Open
Description
I've tried it with OffsetArrays
, but I guess the behavior would persist with other wrappers. I'm not totally sure what causes this, as I've not looked into it.
julia> A = reinterpret(reshape, Float64, ones(ComplexF64, 3, 3))
2×3×3 reinterpret(reshape, Float64, ::Matrix{ComplexF64}) with eltype Float64:
[:, :, 1] =
1.0 1.0 1.0
0.0 0.0 0.0
[:, :, 2] =
1.0 1.0 1.0
0.0 0.0 0.0
[:, :, 3] =
1.0 1.0 1.0
0.0 0.0 0.0
julia> B = OffsetArray(A)
2×3×3 OffsetArray(reinterpret(reshape, Float64, ::Matrix{ComplexF64}), 1:2, 1:3, 1:3) with eltype Float64 with indices 1:2×1:3×1:3:
[:, :, 1] =
1.0 1.0 1.0
0.0 0.0 0.0
[:, :, 2] =
1.0 1.0 1.0
0.0 0.0 0.0
[:, :, 3] =
1.0 1.0 1.0
0.0 0.0 0.0
julia> B[:, 1, 1]
ERROR: MethodError: no method matching _maybe_reshape(::Base.IndexSCartesian2{2}, ::OffsetArray{Float64, 3, Base.ReinterpretArray{Float64, 3, ComplexF64, Matrix{ComplexF64}, true}}, ::Base.Slice{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}}, ::Int64, ::Int64)
Closest candidates are:
_maybe_reshape(::Base.IndexSCartesian2, ::Base.ReinterpretArray{T, N, S, A, true} where {T, N, S, A<:(AbstractArray{S})}, ::Any...) at ~/Downloads/julia/julia-1.7/share/julia/base/reinterpretarray.jl:255
_maybe_reshape(::IndexLinear, ::AbstractArray, ::Any...) at ~/Downloads/julia/julia-1.7/share/julia/base/multidimensional.jl:842
_maybe_reshape(::IndexCartesian, ::AbstractArray, ::Any...) at ~/Downloads/julia/julia-1.7/share/julia/base/multidimensional.jl:844
...
Stacktrace:
[1] _getindex
@ ./multidimensional.jl:839 [inlined]
[2] getindex(::OffsetArray{Float64, 3, Base.ReinterpretArray{Float64, 3, ComplexF64, Matrix{ComplexF64}, true}}, ::Function, ::Int64, ::Int64)
@ Base ./abstractarray.jl:1218
[3] top-level scope
@ REPL[17]:1
julia> A[:, 1, 1]
2-element Vector{Float64}:
1.0
0.0
This works on the other hand:
julia> C = @view A[:, :, :]
2×3×3 view(reinterpret(reshape, Float64, ::Matrix{ComplexF64}), :, :, :) with eltype Float64:
[:, :, 1] =
1.0 1.0 1.0
0.0 0.0 0.0
[:, :, 2] =
1.0 1.0 1.0
0.0 0.0 0.0
[:, :, 3] =
1.0 1.0 1.0
0.0 0.0 0.0
julia> C[:, 1, 1]
2-element Vector{Float64}:
1.0
0.0
julia> IndexStyle(C)
IndexCartesian()