Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rand!(a, Multinomial(100, p)) StackOverflowError bug #1929

Closed
cossio opened this issue Dec 16, 2024 · 3 comments
Closed

rand!(a, Multinomial(100, p)) StackOverflowError bug #1929

cossio opened this issue Dec 16, 2024 · 3 comments

Comments

@cossio
Copy link
Contributor

cossio commented Dec 16, 2024

using Random, Distributions
p = rand(10)
p = p / sum(p)
a = zeros(10)
rand!(a, Multinomial(100, p))

Results in an error,

ERROR: StackOverflowError:
Stacktrace:
 [1] rand!(rng::TaskLocalRNG, A::Vector{Float64}, X::Distributions.MultinomialSampler{Float64}) (repeats 79984 times)
   @ Random ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/Random/src/Random.jl:268
@devmotion
Copy link
Member

The arguments of rand! are incorrectly ordered in your example: https://juliastats.org/Distributions.jl/stable/multivariate/#Random.rand!-Tuple{AbstractRNG,%20MultivariateDistribution,%20AbstractArray}

julia> rand!(Multinomial(100, p), a)
10-element Vector{Float64}:
  3.0
 13.0
 16.0
  5.0
 12.0
 17.0
  7.0
 24.0
  1.0
  2.0

@cossio
Copy link
Contributor Author

cossio commented Dec 17, 2024

I missed that. Isn't this order different from the one at Base?
https://docs.julialang.org/en/v1/stdlib/Random/#Random.rand!

@devmotion
Copy link
Member

Yes: #1316

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants