119
119
@test LinearIndices ()[1 ] == 1
120
120
@test_throws BoundsError LinearIndices ()[2 ]
121
121
@test LinearIndices ()[1 ,1 ] == 1
122
+ @test LinearIndices ()[] == 1
123
+ @test size (LinearIndices ()) == ()
122
124
@test CartesianIndices ()[1 ] == CartesianIndex ()
123
125
@test_throws BoundsError CartesianIndices ()[2 ]
124
126
end
129
131
@test CartesianIndices ((3 ,))[i] == CartesianIndex (i,)
130
132
end
131
133
@test LinearIndices ((3 ,))[2 ,1 ] == 2
134
+ @test LinearIndices ((3 ,))[[1 ]] == [1 ]
135
+ @test size (LinearIndices ((3 ,))) == (3 ,)
132
136
@test_throws BoundsError CartesianIndices ((3 ,))[2 ,2 ]
133
137
# ambiguity btw cartesian indexing and linear indexing in 1d when
134
138
# indices may be nontraditional
@@ -140,22 +144,39 @@ end
140
144
k = 0
141
145
cartesian = CartesianIndices ((4 ,3 ))
142
146
linear = LinearIndices (cartesian)
147
+ @test size (cartesian) == size (linear) == (4 , 3 )
143
148
for j = 1 : 3 , i = 1 : 4
144
- @test linear[i,j] == (k+= 1 )
149
+ k += 1
150
+ @test linear[i,j] == linear[k] == k
145
151
@test cartesian[k] == CartesianIndex (i,j)
146
152
@test LinearIndices (0 : 3 ,3 : 5 )[i- 1 ,j+ 2 ] == k
147
153
@test CartesianIndices (0 : 3 ,3 : 5 )[k] == CartesianIndex (i- 1 ,j+ 2 )
148
154
end
155
+ @test linear[linear] == linear
156
+ @test linear[vec (linear)] == vec (linear)
157
+ @test linear[cartesian] == linear
158
+ @test linear[vec (cartesian)] == vec (linear)
159
+ @test cartesian[linear] == cartesian
160
+ @test cartesian[vec (linear)] == vec (cartesian)
161
+ @test cartesian[cartesian] == cartesian
162
+ @test cartesian[vec (cartesian)] == vec (cartesian)
149
163
end
150
164
151
165
@testset " 3-dimensional" begin
152
166
l = 0
153
167
for k = 1 : 2 , j = 1 : 3 , i = 1 : 4
154
- @test LinearIndices ((4 ,3 ,2 ))[i,j,k] == (l+= 1 )
168
+ l += 1
169
+ @test LinearIndices ((4 ,3 ,2 ))[i,j,k] == l
170
+ @test LinearIndices ((4 ,3 ,2 ))[l] == l
171
+ @test CartesianIndices ((4 ,3 ,2 ))[i,j,k] == CartesianIndex (i,j,k)
155
172
@test CartesianIndices ((4 ,3 ,2 ))[l] == CartesianIndex (i,j,k)
156
173
@test LinearIndices (1 : 4 ,1 : 3 ,1 : 2 )[i,j,k] == l
174
+ @test LinearIndices (1 : 4 ,1 : 3 ,1 : 2 )[l] == l
175
+ @test CartesianIndices (1 : 4 ,1 : 3 ,1 : 2 )[i,j,k] == CartesianIndex (i,j,k)
157
176
@test CartesianIndices (1 : 4 ,1 : 3 ,1 : 2 )[l] == CartesianIndex (i,j,k)
158
177
@test LinearIndices (0 : 3 ,3 : 5 ,- 101 : - 100 )[i- 1 ,j+ 2 ,k- 102 ] == l
178
+ @test LinearIndices (0 : 3 ,3 : 5 ,- 101 : - 100 )[l] == l
179
+ @test CartesianIndices (0 : 3 ,3 : 5 ,- 101 : - 100 )[i,j,k] == CartesianIndex (i- 1 , j+ 2 , k- 102 )
159
180
@test CartesianIndices (0 : 3 ,3 : 5 ,- 101 : - 100 )[l] == CartesianIndex (i- 1 , j+ 2 , k- 102 )
160
181
end
161
182
0 commit comments