1
1
using OffsetArrays
2
2
using Test
3
3
using DelimitedFiles
4
+ using OffsetArrays: IdentityUnitRange
4
5
5
6
@test isempty (detect_ambiguities (OffsetArrays, Base, Core))
6
7
@@ -42,8 +43,8 @@ y = OffsetArray(r, r)
42
43
y = OffsetArray (r, (r,))
43
44
@test axes (y) == (r,)
44
45
45
- y = OffsetArray {Float32} (undef, (Base . Slice (- 1 : 1 ),))
46
- @test axes (y) === (Base . Slice (- 1 : 1 ),)
46
+ y = OffsetArray {Float32} (undef, (IdentityUnitRange (- 1 : 1 ),))
47
+ @test axes (y) === (IdentityUnitRange (- 1 : 1 ),)
47
48
48
49
A0 = [1 3 ; 2 4 ]
49
50
A = OffsetArray (A0, (- 1 ,2 )) # IndexLinear
@@ -104,21 +105,21 @@ Ac[0,3,1] = 11
104
105
@test_throws BoundsError S[CartesianIndex (1 ,1 ),0 ]
105
106
@test_throws BoundsError S[CartesianIndex (1 ,1 ),2 ]
106
107
@test eachindex (A) == 1 : 4
107
- @test eachindex (S) == CartesianIndices (Base . Slice .((0 : 1 ,3 : 4 )))
108
+ @test eachindex (S) == CartesianIndices (IdentityUnitRange .((0 : 1 ,3 : 4 )))
108
109
109
110
# view
110
111
S = view (A, :, 3 )
111
112
@test S == OffsetArray ([1 ,2 ], (A. offsets[1 ],))
112
113
@test S[0 ] == 1
113
114
@test S[1 ] == 2
114
115
@test_throws BoundsError S[2 ]
115
- @test axes (S) === (Base . Slice (0 : 1 ),)
116
+ @test axes (S) === (IdentityUnitRange (0 : 1 ),)
116
117
S = view (A, 0 , :)
117
118
@test S == OffsetArray ([1 ,3 ], (A. offsets[2 ],))
118
119
@test S[3 ] == 1
119
120
@test S[4 ] == 3
120
121
@test_throws BoundsError S[1 ]
121
- @test axes (S) === (Base . Slice (3 : 4 ),)
122
+ @test axes (S) === (IdentityUnitRange (3 : 4 ),)
122
123
S = view (A, 0 : 0 , 4 )
123
124
@test S == [3 ]
124
125
@test S[1 ] == 3
@@ -137,7 +138,7 @@ S = view(A, :, :)
137
138
@test S[0 ,4 ] == S[3 ] == 3
138
139
@test S[1 ,4 ] == S[4 ] == 4
139
140
@test_throws BoundsError S[1 ,1 ]
140
- @test axes (S) === Base . Slice .((0 : 1 , 3 : 4 ))
141
+ @test axes (S) === IdentityUnitRange .((0 : 1 , 3 : 4 ))
141
142
142
143
# iteration
143
144
let a
@@ -178,10 +179,10 @@ B = similar(A, (3,4))
178
179
@test axes (B) === (Base. OneTo (3 ), Base. OneTo (4 ))
179
180
B = similar (A, (- 3 : 3 ,1 : 4 ))
180
181
@test isa (B, OffsetArray{Int,2 })
181
- @test axes (B) === Base . Slice .((- 3 : 3 , 1 : 4 ))
182
+ @test axes (B) === IdentityUnitRange .((- 3 : 3 , 1 : 4 ))
182
183
B = similar (parent (A), (- 3 : 3 ,1 : 4 ))
183
184
@test isa (B, OffsetArray{Int,2 })
184
- @test axes (B) === Base . Slice .((- 3 : 3 , 1 : 4 ))
185
+ @test axes (B) === IdentityUnitRange .((- 3 : 3 , 1 : 4 ))
185
186
@test isa ([x for x in [1 ,2 ,3 ]], Vector{Int})
186
187
@test similar (Array{Int}, (0 : 0 , 0 : 0 )) isa OffsetArray{Int, 2 }
187
188
@test similar (Array{Int}, (1 , 1 )) isa Matrix{Int}
@@ -191,13 +192,13 @@ B = similar(parent(A), (-3:3,1:4))
191
192
B = reshape (A0, - 10 : - 9 , 9 : 10 )
192
193
@test isa (B, OffsetArray{Int,2 })
193
194
@test parent (B) === A0
194
- @test axes (B) == Base . Slice .((- 10 : - 9 , 9 : 10 ))
195
+ @test axes (B) == IdentityUnitRange .((- 10 : - 9 , 9 : 10 ))
195
196
B = reshape (A, - 10 : - 9 , 9 : 10 )
196
197
@test isa (B, OffsetArray{Int,2 })
197
198
@test pointer (parent (B)) === pointer (A0)
198
- @test axes (B) == Base . Slice .((- 10 : - 9 , 9 : 10 ))
199
+ @test axes (B) == IdentityUnitRange .((- 10 : - 9 , 9 : 10 ))
199
200
b = reshape (A, - 7 : - 4 )
200
- @test axes (b) == (Base . Slice (- 7 : - 4 ),)
201
+ @test axes (b) == (IdentityUnitRange (- 7 : - 4 ),)
201
202
@test isa (parent (b), Vector{Int})
202
203
@test pointer (parent (b)) === pointer (parent (A))
203
204
@test parent (b) == A0[:]
@@ -206,27 +207,27 @@ a = OffsetArray(rand(3,3,3), -1:1, 0:2, 3:5)
206
207
b = reshape (a, Val (2 ))
207
208
@test isa (b, OffsetArray{Float64,2 })
208
209
@test pointer (parent (b)) === pointer (parent (a))
209
- @test axes (b) == Base . Slice .((- 1 : 1 , 1 : 9 ))
210
+ @test axes (b) == IdentityUnitRange .((- 1 : 1 , 1 : 9 ))
210
211
b = reshape (a, Val (4 ))
211
212
@test isa (b, OffsetArray{Float64,4 })
212
213
@test pointer (parent (b)) === pointer (parent (a))
213
- @test axes (b) == (axes (a)... , Base . Slice (1 : 1 ))
214
+ @test axes (b) == (axes (a)... , IdentityUnitRange (1 : 1 ))
214
215
215
216
# Indexing with OffsetArray axes
216
217
i1 = OffsetArray ([2 ,1 ], (- 5 ,))
217
218
i1 = OffsetArray ([2 ,1 ], - 5 )
218
219
b = A0[i1, 1 ]
219
- @test axes (b) === (Base . Slice (- 4 : - 3 ),)
220
+ @test axes (b) === (IdentityUnitRange (- 4 : - 3 ),)
220
221
@test b[- 4 ] == 2
221
222
@test b[- 3 ] == 1
222
223
b = A0[1 ,i1]
223
- @test axes (b) === (Base . Slice (- 4 : - 3 ),)
224
+ @test axes (b) === (IdentityUnitRange (- 4 : - 3 ),)
224
225
@test b[- 4 ] == 3
225
226
@test b[- 3 ] == 1
226
227
v = view (A0, i1, 1 )
227
- @test axes (v) === (Base . Slice (- 4 : - 3 ),)
228
+ @test axes (v) === (IdentityUnitRange (- 4 : - 3 ),)
228
229
v = view (A0, 1 : 1 , i1)
229
- @test axes (v) === (Base. OneTo (1 ), Base . Slice (- 4 : - 3 ))
230
+ @test axes (v) === (Base. OneTo (1 ), IdentityUnitRange (- 4 : - 3 ))
230
231
231
232
# logical indexing
232
233
@test A[A .> 2 ] == [3 ,4 ]
0 commit comments