-
Notifications
You must be signed in to change notification settings - Fork 152
Error during SArray initialization with array comprehension containing two SVector iterates #76
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
Comments
Thanks @wsshin for the report. Comprehensions (and generators) certainly are only partially supported at the moment, and we want to support them better in the future, but it is rather odd that one works and the other doesn't. |
This seems to be due to a bizarre interaction between type inference with julia> using StaticArrays
julia> vec2 = @SVector([1,2]); vec3 = @SVector([1,2,3])
3-element StaticArrays.SVector{3,Int64}:
1
2
3
julia> [eval(ex) for ex in [:vec2, :vec3]]
ERROR: The size of type `StaticArrays.SVector{S,Int64}` is not known. Type inference has inferred julia> typealias SVecInt{S} SVector{S,Int}
StaticArrays.SVector{S,Int64}
julia> sv = SVecInt[SVector(1,2)];
ERROR: The size of type `StaticArrays.SVector{S,Int64}` is not known. |
This is super easy to workaround in the macro, but the root cause is confusing. Typed comprehension lowers to a weird getindex call - getindex(SVecInt, SVector(1,2)) Which in turn does this: julia> a = Array{SVecInt,1}(1)
1-element Array{StaticArrays.SVector{S,Int64},1}:
#undef
julia> a[1] = SVector(1,2)
ERROR: The size of type `StaticArrays.SVector{S,Int64}` is not known.
|
Ultimately, this boils down to convert(SVecInt, SVector(1,2)) As it turns out, running with
|
This doesn't address the root cause, but works around the issue reported in #76.
By the way, @wsshin the comprehension syntax I've implemented is only meant for literals like We definitely want to support this behaviour (the output dimension is inferrable from the static vector inputs) but it's just not implemeted yet. |
See #26 |
Use normal functions for getindex
Uh oh!
There was an error while loading. Please reload this page.
Consider two SVector objects with 2 and 3 entries:
I can use one of these two SVector objects as iterates in array comprehension to initialize SArray. For example,
However, as soon as I mix two SVector objects, an error is generated:
Is this an expected behavior?
Here is the
versioninfo()
output:The text was updated successfully, but these errors were encountered: