1
1
using Base. Test
2
2
using OffsetArrays
3
3
4
- @test isempty (detect_ambiguities (OffsetArrays, Base, Core))
4
+ ambs = detect_ambiguities (Base, Core) # in case these have ambiguities of their own
5
+ @test isempty (setdiff (detect_ambiguities (OffsetArrays, Base, Core), ambs))
5
6
6
7
# Basics
7
8
for n = 0 : 5
@@ -39,12 +40,25 @@ S = OffsetArray(view(A0, 1:2, 1:2), (-1,2)) # LinearSlow
39
40
@test_throws DimensionMismatch OffsetArray (A0, 0 : 1 , 2 : 4 )
40
41
41
42
# Scalar indexing
42
- @test A[0 ,3 ] == A[1 ] == S[0 ,3 ] == S[1 ] == 1
43
- @test A[1 ,3 ] == A[2 ] == S[1 ,3 ] == S[2 ] == 2
44
- @test A[0 ,4 ] == A[3 ] == S[0 ,4 ] == S[3 ] == 3
45
- @test A[1 ,4 ] == A[4 ] == S[1 ,4 ] == S[4 ] == 4
43
+ @test A[0 ,3 ] == A[0 ,3 ,1 ] == A[1 ] == S[0 ,3 ] == S[0 ,3 ,1 ] == S[1 ] == 1
44
+ @test A[1 ,3 ] == A[1 ,3 ,1 ] == A[2 ] == S[1 ,3 ] == S[1 ,3 ,1 ] == S[2 ] == 2
45
+ @test A[0 ,4 ] == A[0 ,4 ,1 ] == A[3 ] == S[0 ,4 ] == S[0 ,4 ,1 ] == S[3 ] == 3
46
+ @test A[1 ,4 ] == A[1 ,4 ,1 ] == A[4 ] == S[1 ,4 ] == S[1 ,4 ,1 ] == S[4 ] == 4
47
+ @test @unsafe (A[0 ,3 ]) == @unsafe (A[0 ,3 ,1 ]) == @unsafe (A[1 ]) == @unsafe (S[0 ,3 ]) == @unsafe (S[0 ,3 ,1 ]) == @unsafe (S[1 ]) == 1
48
+ @test @unsafe (A[1 ,3 ]) == @unsafe (A[1 ,3 ,1 ]) == @unsafe (A[2 ]) == @unsafe (S[1 ,3 ]) == @unsafe (S[1 ,3 ,1 ]) == @unsafe (S[2 ]) == 2
49
+ @test @unsafe (A[0 ,4 ]) == @unsafe (A[0 ,4 ,1 ]) == @unsafe (A[3 ]) == @unsafe (S[0 ,4 ]) == @unsafe (S[0 ,4 ,1 ]) == @unsafe (S[3 ]) == 3
50
+ @test @unsafe (A[1 ,4 ]) == @unsafe (A[1 ,4 ,1 ]) == @unsafe (A[4 ]) == @unsafe (S[1 ,4 ]) == @unsafe (S[1 ,4 ,1 ]) == @unsafe (S[4 ]) == 4
46
51
@test_throws BoundsError A[1 ,1 ]
47
52
@test_throws BoundsError S[1 ,1 ]
53
+ @test_throws BoundsError A[0 ,3 ,2 ]
54
+ @test_throws BoundsError A[0 ,3 ,0 ]
55
+ Ac = copy (A)
56
+ Ac[0 ,3 ] = 10
57
+ @test Ac[0 ,3 ] == 10
58
+ Ac[0 ,3 ,1 ] = 11
59
+ @test Ac[0 ,3 ] == 11
60
+ @unsafe Ac[0 ,3 ,1 ] = 12
61
+ @test Ac[0 ,3 ] == 12
48
62
49
63
# Vector indexing
50
64
@test A[:, 3 ] == S[:, 3 ] == OffsetArray ([1 ,2 ], (A. offsets[1 ],))
@@ -63,8 +77,15 @@ S = OffsetArray(view(A0, 1:2, 1:2), (-1,2)) # LinearSlow
63
77
64
78
# CartesianIndexing
65
79
@test A[CartesianIndex ((0 ,3 ))] == S[CartesianIndex ((0 ,3 ))] == 1
80
+ @test A[CartesianIndex ((0 ,3 )),1 ] == S[CartesianIndex ((0 ,3 )),1 ] == 1
81
+ @test @unsafe (A[CartesianIndex ((0 ,3 ))]) == @unsafe (S[CartesianIndex ((0 ,3 ))]) == 1
82
+ @test @unsafe (A[CartesianIndex ((0 ,3 )),1 ]) == @unsafe (S[CartesianIndex ((0 ,3 )),1 ]) == 1
66
83
@test_throws BoundsError A[CartesianIndex (1 ,1 )]
84
+ @test_throws BoundsError A[CartesianIndex (1 ,1 ),0 ]
85
+ @test_throws BoundsError A[CartesianIndex (1 ,1 ),2 ]
67
86
@test_throws BoundsError S[CartesianIndex (1 ,1 )]
87
+ @test_throws BoundsError S[CartesianIndex (1 ,1 ),0 ]
88
+ @test_throws BoundsError S[CartesianIndex (1 ,1 ),2 ]
68
89
@test eachindex (A) == 1 : 4
69
90
@test eachindex (S) == CartesianRange ((0 : 1 ,3 : 4 ))
70
91
0 commit comments