Hey everyone,
I have a function that in theory should be fully parallelizable as it is independent of the previous input. In the example below i just fill a vector with categorically distributed random variables:
using Distributions
#Sampling Categorical data
output = zeros(Int64, 3)
prob = [ .4 .6 ; .5 .5 ; .9 .1]
for i in 1:size(prob,1)
output[i] = wsample(prob[i,:]) #works - and seems to be faster than the method below
#output[i] = rand(Categorical(prob[1,:])) #works
end
Now I would like to vectorize either of the 2 methods above, but the common syntax does not seem to work in this case here:
#vectorize via wsample
wsample.( prob )#NOT WORKING
map(x -> wsample(x), prob ) #NOT WORKING
#Vectorize via Distributions
map(x -> rand(Categorical(x)), prob ) #NOT WORKING
rand.( Categorical.( prob ) ) # NOT WORKING
Question 1: Does anyone know a way to use said methods in a vectorized way? I did not see any thread regarding this, so I guess I must do something wrong as this case comes up in lots of algorithms. I know that this is not necessarily faster than a for-loop in a compiled language but I would at least like to benchmark it for my problems.
As a step further, I would also like to use the pmap
function, but that obviously also does not work with the code I provided.