-
Notifications
You must be signed in to change notification settings - Fork 148
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
Generating random StaticArrays works with SamplerTypes but not other Samplers #804
Comments
I'm not sure whether this is a feature request or a bug, but it seems like a problem we should address :-) |
An even simpler example of this bug is using Distributions
@MVector rand(Uniform(-1.,1.), 2) |
Ran into this today! Any chance this might be addressed? |
The most simple case is julia> using StaticArrays
julia> rand(Float32, 3)
3-element Vector{Float32}:
0.36981475
0.018245816
0.6316833
julia> @SVector rand(Float32, 3)
3-element SVector{3, Float32} with indices SOneTo(3):
0.54274094
0.22791529
0.9776533
julia> rand(1:5, 3)
3-element Vector{Int64}:
5
3
4
julia> @SVector rand(1:5, 3)
ERROR: ArgumentError: Static Array parameter T must be a type, got 1:5
Stacktrace: The problem is that macros such as julia> @macroexpand @SVector rand(Float32, 3)
:(StaticArrays.rand((SVector){3, Float32}))
julia> @macroexpand @SVector rand(1:5, 3)
:(StaticArrays.rand((SVector){3, 1:5})) I think adding a new function named julia> @macroexpand @SVector rand(Float32, 3) # How macro expands
:(StaticArrays.strand((SVector){3, Float32}))
julia> @macroexpand @SVector rand(1:5, 3) # How macro expands
:(StaticArrays.strand((SVector){3, Int}, 1:5))
julia> strand(SVector{3}, 1:5) # Use cases
julia> strand(SVector{3, Int}, 1:5)
julia> strand(SVector{3}, Float64)
julia> strand(SVector{3, Float64}, Float64)
julia> strand(SVector{3, Float64})
julia> strand(SMatrix{3, Float64}, 1:8) |
I've looked into this issue yesterday and I think we can modify the macro without introducing a new function. I'll let you know when I make sure it works fine. |
My solution seems to work as long as the array has at least one element, so I'd say it's good enough. There are also no regressions for 0-element arrays. |
Similarly, it would be good to handle julia> using Random
julia> rng = Xoshiro(3);
julia> @SVector rand(rng, 3)
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type Xoshiro What I would suggest is that |
Here's an example taken from the Julia docs on random number generation here
This lets us conveniently generate arrays of random dice,
or arrays of random dice rolls
With StaticArrays we can generate random dice
but not random dice rolls
The same error occurs when using the samplers from Distributions.jl, for example.
The text was updated successfully, but these errors were encountered: