vendredi 28 octobre 2022

Julia: random multinomial numbers allocation

I have to generate a vector of random number drawn from a Multinomial distribution. Since I need to do it inside a loop I would like to reduce the number of allocations. This is my code:

pop = zeros(100)
p = rand(100)
p /= sum(p)

#imagine the next line inside a for loop
@time pop = rand(Multinomial(100, p)) #test1
@time pop .= rand(Multinomial(100, p)) #test2

Why test1 is 2 allocations and test2 is 4? Is there a way of doing it with 0 allocations?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire