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

reinterpret failure due to missing axes specialization #1269

Open
pablosanjose opened this issue Jun 30, 2024 · 0 comments
Open

reinterpret failure due to missing axes specialization #1269

pablosanjose opened this issue Jun 30, 2024 · 0 comments

Comments

@pablosanjose
Copy link
Contributor

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}

@pablosanjose pablosanjose changed the title reinterpret failure due to missing axis specialization reinterpret failure due to missing axes specialization Jun 30, 2024
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

1 participant