Skip to content

Commit c0046f8

Browse files
authored
Fix to_index for CartesianIndices and (#310)
first for LazyAxis
1 parent de94815 commit c0046f8

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

lib/ArrayInterfaceOffsetArrays/test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Op = PermutedDimsArray(O,(3,1,2));
1111
@test @inferred(ArrayInterface.offsets(O)) === (4, 8, 11)
1212
@test @inferred(ArrayInterface.offsets(Op)) === (11, 4, 8)
1313

14+
@test @inferred(ArrayInterface.to_indices(O, (:, :, :))) == (4:6, 8:11, 11:15)
15+
@test @inferred(ArrayInterface.to_indices(Op, (:, :, :))) == (11:15, 4:6, 8:11)
16+
1417
@test @inferred(ArrayInterface.offsets((1,2,3))) === (StaticInt(1),)
1518
o = OffsetArray(vec(A), 8);
1619
@test @inferred(ArrayInterface.offset1(o)) === 9

src/axes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ ArrayInterfaceCore.known_first(::Type{<:LazyAxis{N,P}}) where {N,P} = known_offs
220220
ArrayInterfaceCore.known_first(::Type{<:LazyAxis{:,P}}) where {P} = 1
221221
@inline function Base.first(x::LazyAxis{N})::Int where {N}
222222
if ArrayInterfaceCore.known_first(x) === nothing
223-
return Int(offsets(parent(x), StaticInt(N)))
223+
return Int(offsets(getfield(x, :parent), StaticInt(N)))
224224
else
225225
return Int(known_first(x))
226226
end

src/indexing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ to_index(x, i::AbstractArray{Bool}) = LogicalIndex(i)
188188
to_index(x::LinearIndices, i::AbstractArray{Bool}) = LogicalIndex{Int}(i)
189189
# cartesian indexing
190190
@inline to_index(x, i::CartesianIndices{0}) = i
191-
@inline to_index(x, i::CartesianIndices) = axes(i)
191+
@inline to_index(x, i::CartesianIndices) = getfield(i, :indices)
192192
@inline to_index(x, i::CartesianIndex) = Tuple(i)
193193
@inline to_index(x, i::NDIndex) = Tuple(i)
194194
@inline to_index(x, i::AbstractArray{<:AbstractCartesianIndex}) = i

test/indexing.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@test @inferred(ArrayInterface.to_index(axis, CartesianIndex(1))) === (1,)
77
@test @inferred(ArrayInterface.to_index(axis, 1:2)) === 1:2
88
@test @inferred(ArrayInterface.to_index(axis, CartesianIndices((1:2,)))) == (1:2,)
9+
@test @inferred(ArrayInterface.to_index(axis, CartesianIndices((2:3,)))) == (2:3,)
910
@test @inferred(ArrayInterface.to_index(axis, [1, 2])) == [1, 2]
1011
@test @inferred(ArrayInterface.to_index(axis, [true, false, false])) == [1]
1112
index = @inferred(ArrayInterface.to_index(axis, :))

0 commit comments

Comments
 (0)