-
Notifications
You must be signed in to change notification settings - Fork 149
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
similar(::StaticArray, T) when !isbitstype(T) should give a SizedArray #799
Comments
It’s possible that |
Well I don't think More immediately, we could dispatch on |
Gentle bump, this leads to failure such as julia> S = Diagonal(SVector{2,Real}(1,2))
2×2 Diagonal{Real, SVector{2, Real}} with indices SOneTo(2)×SOneTo(2):
1 ⋅
⋅ 2
julia> S[:, 1]
ERROR: setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] setindex!
@ ~/.julia/packages/StaticArrays/B0HhH/src/MArray.jl:39 [inlined]
[3] macro expansion
@ ./multidimensional.jl:903 [inlined]
[4] macro expansion
@ ./cartesian.jl:64 [inlined]
[5] _unsafe_getindex!
@ ./multidimensional.jl:898 [inlined]
[6] _unsafe_getindex(::IndexCartesian, ::Diagonal{Real, SVector{2, Real}}, ::Base.Slice{SOneTo{2}}, ::Int64)
@ Base ./multidimensional.jl:889
[7] _getindex
@ ./multidimensional.jl:875 [inlined]
[8] getindex(::Diagonal{Real, SVector{2, Real}}, ::Function, ::Int64)
@ Base ./abstractarray.jl:1241
[9] top-level scope
@ REPL[20]:1 It would be good to have a |
The
similar(::StaticArray, T)
method returns anMArray
even if called on anSArray
, rightfully so since there would be no reason to callsimilar
if you couldn't mutate the array later.However, if
!isbitstype(T)
, then the returnedMArray
is still un-mutable later because ofStaticArrays.jl/src/MArray.jl
Lines 94 to 99 in 64c64b2
So I think the natural thing would be for
similar(::StaticArray, T)
to return aSizedArray
when!isbitstype(T)
, as basically suggested by that error message.If people here agree, I can take a stab at a PR, but also I'm happy if someone else that's more familiar with the code-base does it (probably much faster than I can).
FWIW, this would fix FluxML/Zygote.jl#686 where this came up for me.
The text was updated successfully, but these errors were encountered: