JuliaArrays / JuliaArrays/StaticArrays.jl
`reinterpret` failure due to missing `axes` specialization
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
julia> reinterpret(Float64, SA[im,1.0im])
Error showing value of type Base.ReinterpretArray{Float64, 1, ComplexF64, SVector{2, ComplexF64}, false}:
ERROR: DimensionMismatch("1:4 is inconsistent with SOneTo{2}")
Stacktrace:
[1] (::StaticArrays.var"#errmsg#1"{2})(r::UnitRange{Int64})
@ StaticArrays ~/.julia/packages/StaticArrays/80e5O/src/SOneTo.jl:14
[2] SOneTo
@ ~/.julia/packages/StaticArrays/80e5O/src/SOneTo.jl:15 [inlined]
[3] convert
@ ./range.jl:148 [inlined]
[4] oftype
@ ./essentials.jl:375 [inlined]
[5] axes
@ ./reinterpretarray.jl:302 [inlined]
[6] summary
@ ./show.jl:2664 [inlined]
[7] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, X::Base.ReinterpretArray{Float64, 1, ComplexF64, SVector{2, ComplexF64}, false})
@ Base ./arrayshow.jl:337
...
As @MasonProtter points out in slack, this is the offending method in Base
function axes(a::NonReshapedReinterpretArray{T,N,S} where {N}) where {T,S}
paxs = axes(a.parent)
f, l = first(paxs[1]), length(paxs[1])
size1 = issingletontype(T) ? l : div(l*sizeof(S), sizeof(T))
tuple(oftype(paxs[1], f:f+size1-1), tail(paxs)...)
end
The error stems from oftype not receiving enough type-domain information to yield the correct SOneTo axis object. Mason also suggests the following kind of fix in StaticArrays.jl
function Base.axes(::Base.NonReshapedReinterpretArray{T, N, S, SA}) where {T, N, S, SA <: StaticArray{Tup}} where {Tup}
paxs = axes(SA)
old_sizes = size(SA)
l = old_sizes[1]
size1 = Base.issingletontype(T) ? l : div(l*sizeof(S), sizeof(T))
(SOneTo(size1), SOneTo.(Base.tail(old_sizes))...)
end
and an analogous method for Base.axes(::ReshapedReinterpretArray{T,N,S} where {N}) where {T,S}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Julia reproducer and the Base axes methods shown in the issue, then inspect StaticArrays' SOneTo implementation and existing axes specializations. The analogous methods for NonReshapedReinterpretArray and ReshapedReinterpretArray should make reinterpret(Float64, SA[im, 1.0im]) display without a DimensionMismatch and report compatible axes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100