Skip to content

Commit 730afb0

Browse files
committed
Add more axes tests
1 parent a4bbe75 commit 730afb0

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

src/axes.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ function axes_types(::Type{T}) where {T}
3737
end
3838
axes_types(::Type{LinearIndices{N,R}}) where {N,R} = R
3939
axes_types(::Type{CartesianIndices{N,R}}) where {N,R} = R
40-
function axes_types(::Type{T}) where {T<:VecAdjTrans}
41-
return Tuple{OptionallyStaticUnitRange{One,One},axes_types(parent_type(T), One())}
42-
end
43-
function axes_types(::Type{T}) where {T<:MatAdjTrans}
44-
return eachop_tuple(_get_tuple, to_parent_dims(T), axes_types(parent_type(T)))
40+
function axes_types(::Type{T}) where {T<:Union{Adjoint,Transpose}}
41+
P = parent_type(T)
42+
return Tuple{axes_types(P, static(2)), axes_types(P, static(1))}
4543
end
4644
function axes_types(::Type{T}) where {T<:PermutedDimsArray}
4745
return eachop_tuple(_get_tuple, to_parent_dims(T), axes_types(parent_type(T)))

src/indexing.jl

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -216,31 +216,8 @@ end
216216
end
217217
@propagate_inbounds function _to_indices(::StaticInt{N}, A, axs::Tuple, args::Tuple) where {N}
218218
axes_front, axes_tail = Base.IteratorsMD.split(axs, Val(N))
219-
return _to_multi_indices(A, axes_front, axes_tail, first(args), _maybe_tail(args))
219+
return (to_index(_layout(IndexStyle(A), axes_front), first(args)), to_indices(A, axes_tail, _maybe_tail(args))...)
220220
end
221-
@propagate_inbounds function _to_multi_indices(
222-
A,
223-
axes_front::Tuple,
224-
axes_tail::Tuple,
225-
arg::Union{LinearIndices,CartesianIndices},
226-
args::Tuple
227-
)
228-
return (to_indices(A, axes_front, axes(arg))..., to_indices(A, axes_tail, args)...,)
229-
end
230-
@propagate_inbounds function _to_multi_indices(
231-
A,
232-
axes_front::Tuple,
233-
axes_tail::Tuple,
234-
arg::AbstractCartesianIndex,
235-
args::Tuple
236-
)
237-
return (map(to_index, axes_front, Tuple(arg))..., to_indices(A, axes_tail, args)...)
238-
end
239-
240-
@propagate_inbounds function _to_multi_indices(A, f::Tuple, l::Tuple, arg, args::Tuple)
241-
return (to_index(_layout(IndexStyle(A), f), arg), to_indices(A, l, args)...)
242-
end
243-
244221
@propagate_inbounds function to_indices(A, axs::Tuple, args::Tuple{})
245222
@boundscheck if length(first(axs)) != 1
246223
error("Cannot drop dimension of size $(length(first(axs))).")
@@ -254,7 +231,6 @@ to_indices(A, axs::Tuple{}, args::Tuple{}) = ()
254231
_maybe_tail(::Tuple{}) = ()
255232
_maybe_tail(x::Tuple) = tail(x)
256233

257-
258234
"""
259235
to_index([::IndexStyle, ]axis, arg) -> index
260236

test/runtests.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,23 @@ end
759759
end
760760
end
761761

762+
763+
@testset "axes" begin
764+
A = zeros(3,4,5);
765+
Ap = @view(PermutedDimsArray(A, (3,1,2))[:,1:2,1])';
766+
767+
axs = @inferred(ArrayInterface.axes(Ap))
768+
lzaxs = @inferred(ArrayInterface.lazy_axes(Ap))
769+
axis = axs[2]
770+
lzaxis = lzaxs[2]
771+
772+
@test map(parent, lzaxs) === axs
773+
@test @inferred(first(lzaxis)) === first(axis)
774+
@test @inferred(lzaxis[2]) === axis[2]
775+
@test @inferred(lzaxis[1:2:5]) === axis[1:2:5]
776+
@test @inferred(lzaxis[1:2]) === axis[1:2]
777+
end
778+
762779
include("ndindex.jl")
763780
include("indexing.jl")
764781
include("dimensions.jl")

0 commit comments

Comments
 (0)