Hi,
I am trying to do in-place random number generation using Distributions.jl. However, for some reason, only the random number generation from the Categorical distribution takes extra computation time due to the extra allocations. Here is the code.
function loop()
w = rand(10^5)
normalize!(w,1)
tmpI = zeros(Int,10^5)
tmpF = zeros(Float64,10^5)
@time for i in 1:10^3
rand!(Categorical(w), tmpI)
end
@time for i in 1:10^3
rand!(Normal(0,1), tmpF)
end
@time for i in 1:10^3
rand!(Gamma(1,1), tmpF)
end
@time for i in 1:10^3
rand!(InverseGamma(1,1), tmpF)
end
@time for i in 1:10^3
rand!(Uniform(0,1), tmpF)
end
end
loop()
And here is the result.
4.153208 seconds (10.00 k allocations: 3.726 GiB, 1.42% gc time)
0.269260 seconds
0.444689 seconds
0.883855 seconds
0.063641 seconds
Is this inevitable?