11
22@testset " dimensions" begin
33
4+ @testset " to_dims" begin
5+ @testset " small case" begin
6+ @test ArrayInterface. to_dims ((:x , :y ), :x ) == 1
7+ @test ArrayInterface. to_dims ((:x , :y ), :y ) == 2
8+ @test_throws ArgumentError ArrayInterface. to_dims ((:x , :y ), :z ) # not found
9+ end
10+
11+ @testset " large case" begin
12+ @test ArrayInterface. to_dims ((:x , :y , :a , :b , :c , :d ), :x ) == 1
13+ @test ArrayInterface. to_dims ((:x , :y , :a , :b , :c , :d ), :a ) == 3
14+ @test ArrayInterface. to_dims ((:x , :y , :a , :b , :c , :d ), :d ) == 6
15+ @test_throws ArgumentError ArrayInterface. to_dims ((:x , :y , :a , :b , :c , :d ), :z ) # not found
16+ end
17+ end
18+
419struct NamedDimsWrapper{L,T,N,P<: AbstractArray{T,N} } <: AbstractArray{T,N}
520 parent:: P
621 NamedDimsWrapper {L} (p) where {L} = new {L,eltype(p),ndims(p),typeof(p)} (p)
@@ -10,8 +25,11 @@ ArrayInterface.has_dimnames(::Type{T}) where {T<:NamedDimsWrapper} = true
1025ArrayInterface. dimnames (:: Type{T} ) where {L,T<: NamedDimsWrapper{L} } = L
1126Base. parent (x:: NamedDimsWrapper ) = x. parent
1227Base. size (x:: NamedDimsWrapper ) = size (parent (x))
28+ Base. size (x:: NamedDimsWrapper , d) = ArrayInterface. size (x, d)
1329Base. axes (x:: NamedDimsWrapper ) = axes (parent (x))
30+ Base. axes (x:: NamedDimsWrapper , d) = ArrayInterface. axes (x, d)
1431Base. strides (x:: NamedDimsWrapper ) = Base. strides (parent (x))
32+ Base. strides (x:: NamedDimsWrapper , d) = ArrayInterface. strides (x, d)
1533
1634Base. getindex (x:: NamedDimsWrapper ; kwargs... ) = ArrayInterface. getindex (x; kwargs... )
1735Base. getindex (x:: NamedDimsWrapper , args... ) = ArrayInterface. getindex (x, args... )
@@ -46,9 +64,9 @@ dnums = ntuple(+, length(d))
4664@test @inferred (ArrayInterface. to_dims (x, reverse (d))) === reverse (dnums)
4765@test_throws ArgumentError ArrayInterface. to_dims (x, :z )
4866
49- @test @inferred (ArrayInterface . size (x, :x )) == size (parent (x), 1 )
50- @test @inferred (ArrayInterface . axes (x, :x )) == axes (parent (x), 1 )
51- @test ArrayInterface . strides (x, :x ) == ArrayInterface. strides (parent (x))[1 ]
67+ @test @inferred (size (x, :x )) == size (parent (x), 1 )
68+ @test @inferred (axes (x, :x )) == axes (parent (x), 1 )
69+ @test strides (x, :x ) == ArrayInterface. strides (parent (x))[1 ]
5270
5371x[x = 1 ] = [2 , 3 ]
5472@test @inferred (getindex (x, x = 1 )) == [2 , 3 ]
0 commit comments