|
8 | 8 | end
|
9 | 9 |
|
10 | 10 | @testset "UnsafeIndex" begin
|
11 |
| - @test @inferred(ArrayInterface.UnsafeIndex(ones(2,2,2), typeof((1,[1,2],1)))) == ArrayInterface.UnsafeGetCollection() |
| 11 | + @test @inferred(ArrayInterface.UnsafeIndex(ones(2,2,2), typeof((1,[1,2],1)))) == ArrayInterface.UnsafeGetCollection() |
12 | 12 | @test @inferred(ArrayInterface.UnsafeIndex(ones(2,2,2), typeof((1,1,1)))) == ArrayInterface.UnsafeGetElement()
|
13 | 13 | end
|
14 | 14 |
|
|
19 | 19 | @test @inferred(ArrayInterface.to_index(axis, [1, 2])) == [1, 2]
|
20 | 20 | @test @inferred(ArrayInterface.to_index(axis, [true, false, false])) == [1]
|
21 | 21 |
|
22 |
| - @test_throws BoundsError ArrayInterface.to_index(axis, 4) |
23 |
| - @test_throws BoundsError ArrayInterface.to_index(axis, 1:4) |
| 22 | + @test_throws BoundsError ArrayInterface.to_index(axis, 4) |
| 23 | + @test_throws BoundsError ArrayInterface.to_index(axis, 1:4) |
24 | 24 | @test_throws BoundsError ArrayInterface.to_index(axis, [1, 2, 5])
|
25 |
| - @test_throws BoundsError ArrayInterface.to_index(axis, [true, false, false, true]) |
| 25 | + @test_throws BoundsError ArrayInterface.to_index(axis, [true, false, false, true]) |
| 26 | +end |
| 27 | + |
| 28 | +@testset "unsafe_reconstruct" begin |
| 29 | + one_to = Base.OneTo(10) |
| 30 | + opt_ur = StaticInt(1):10 |
| 31 | + ur = 1:10 |
| 32 | + @test @inferred(ArrayInterface.unsafe_reconstruct(one_to, opt_ur)) === one_to |
| 33 | + @test @inferred(ArrayInterface.unsafe_reconstruct(one_to, one_to)) === one_to |
| 34 | + |
| 35 | + @test @inferred(ArrayInterface.unsafe_reconstruct(opt_ur, opt_ur)) === opt_ur |
| 36 | + @test @inferred(ArrayInterface.unsafe_reconstruct(opt_ur, one_to)) === opt_ur |
| 37 | + |
| 38 | + @test @inferred(ArrayInterface.unsafe_reconstruct(ur, ur)) === ur |
| 39 | + @test @inferred(ArrayInterface.unsafe_reconstruct(ur, one_to)) === ur |
26 | 40 | end
|
27 | 41 |
|
28 | 42 | @testset "to_indices" begin
|
|
69 | 83 | @test @inferred(ArrayInterface.to_axes(A, (axis, axis), (inds,))) === (inds,)
|
70 | 84 | # multidim arg
|
71 | 85 | @test @inferred(ArrayInterface.to_axes(A, (axis, axis), (multi_inds,))) === (Base.OneTo(2),)
|
| 86 | + |
| 87 | + @test ArrayInterface.to_axis(axis, axis) === axis |
| 88 | + @test ArrayInterface.to_axis(axis, ArrayInterface.indices(axis)) === axis |
72 | 89 | end
|
73 | 90 |
|
74 | 91 | @testset "0-dimensional" begin
|
|
96 | 113 | # TODO should this be implemented in ArrayInterface with vectorization?
|
97 | 114 | #@test_throws ArgumentError Base._sub2ind((1:3,), 2)
|
98 | 115 | #@test_throws ArgumentError Base._ind2sub((1:3,), 2)
|
| 116 | + x = Array{Int,2}(undef, (2, 2)) |
| 117 | + ArrayInterface.unsafe_set_element!(x, 1, (2, 2)) |
| 118 | + @test ArrayInterface.unsafe_get_element(x, (2, 2)) === 1 |
| 119 | + |
| 120 | + @test_throws MethodError ArrayInterface.unsafe_set_element!(x, 1, (:x, :x)) |
| 121 | + @test_throws MethodError ArrayInterface.unsafe_get_element(x, (:x, :x)) |
99 | 122 | end
|
100 | 123 |
|
101 | 124 | @testset "2-dimensional" begin
|
|
154 | 177 | @test @inferred(ArrayInterface.getindex(LinearIndices(A),ArrayInterface.getindex(CartesianIndices(A),i))) == i
|
155 | 178 | end
|
156 | 179 | end
|
| 180 | + |
0 commit comments