-
Notifications
You must be signed in to change notification settings - Fork 37
Closed
Description
getindex
for CartesianIndices
whose indices are not start from 1
seems incorrect.
julia> A = reshape(1:6, 2, 3)
2×3 reshape(::UnitRange{Int64}, 2, 3) with eltype Int64:
1 3 5
2 4 6
julia> ArrayInterface.getindex(A, CartesianIndices((1:2, 2:3)))
2×2 Matrix{Int64}:
1 3
2 4
julia> ArrayInterface.getindex(A, 1:2, 2:3)
2×2 Matrix{Int64}:
3 5
4 6
julia> getindex(A, CartesianIndices((1:2, 2:3)))
2×2 Matrix{Int64}:
3 5
4 6
IMO, ArrayInterface.getindex(A, CartesianIndices((1:2, 2:3)))
should be the same as ArrayInterface.getindex(A, 1:2, 2:3)
which is the behavior of Base.getindex
,
but it was treated as getindex(A, 1:2, 1:2)
.
It seems that to_index
don't handle CartesianIndices
properly:
ArrayInterface.jl/src/indexing.jl
Line 190 in e74a7aa
@inline to_index(x, i::CartesianIndices) = axes(i) |
Returning i.indices
should fix it:
julia> ArrayInterface.to_index(x, i::CartesianIndices) = i.indices
julia> ArrayInterface.getindex(A, CartesianIndices((1:2, 2:3)))
2×2 Matrix{Int64}:
3 5
4 6
Metadata
Metadata
Assignees
Labels
No labels