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

StackOverflowError with rand! #1822

Closed
3f6a opened this issue Jan 11, 2024 · 3 comments
Closed

StackOverflowError with rand! #1822

3f6a opened this issue Jan 11, 2024 · 3 comments

Comments

@3f6a
Copy link

3f6a commented Jan 11, 2024

julia> X = zeros(2, 10)
2×10 Matrix{Float64}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

julia> rand!(X, MultivariateNormal([1.0, 2.0], [1.0 0.0; 0.0 1.0]))
ERROR: StackOverflowError:
Stacktrace:
 [1] rand!(rng::TaskLocalRNG, A::Matrix{Float64}, X::FullNormal) (repeats 2 times)
   @ Random ~/.julia/juliaup/julia-1.10.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Random/src/Random.jl:268
@devmotion
Copy link
Member

The arguments have to be provided in different order:

julia> using Distributions, Random

julia> X = zeros(2, 10)
2×10 Matrix{Float64}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

julia> rand!(MultivariateNormal([1.0, 2.0], [1.0 0.0; 0.0 1.0]), X)
2×10 Matrix{Float64}:
 0.337452  0.144253  2.32285  -1.27711    -0.530822  0.0721648  -0.624228
 1.39392   2.19907   3.2094    3.96336     -1.20843   1.82541     0.828073

julia> X
2×10 Matrix{Float64}:
 0.337452  0.144253  2.32285  -1.27711    -0.530822  0.0721648  -0.624228
 1.39392   2.19907   3.2094    3.96336     -1.20843   1.82541     0.828073

@devmotion
Copy link
Member

Ref #1316

@3f6a
Copy link
Author

3f6a commented Jan 11, 2024

Thanks for the response.

I think it's a bit confusing, but please feel free to close this.

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