119119 @test LinearIndices ()[1 ] == 1
120120 @test_throws BoundsError LinearIndices ()[2 ]
121121 @test LinearIndices ()[1 ,1 ] == 1
122+ @test LinearIndices ()[] == 1
123+ @test size (LinearIndices ()) == ()
122124 @test CartesianIndices ()[1 ] == CartesianIndex ()
123125 @test_throws BoundsError CartesianIndices ()[2 ]
124126 end
129131 @test CartesianIndices ((3 ,))[i] == CartesianIndex (i,)
130132 end
131133 @test LinearIndices ((3 ,))[2 ,1 ] == 2
134+ @test LinearIndices ((3 ,))[[1 ]] == [1 ]
135+ @test size (LinearIndices ((3 ,))) == (3 ,)
132136 @test_throws BoundsError CartesianIndices ((3 ,))[2 ,2 ]
133137 # ambiguity btw cartesian indexing and linear indexing in 1d when
134138 # indices may be nontraditional
@@ -140,22 +144,39 @@ end
140144 k = 0
141145 cartesian = CartesianIndices ((4 ,3 ))
142146 linear = LinearIndices (cartesian)
147+ @test size (cartesian) == size (linear) == (4 , 3 )
143148 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
145151 @test cartesian[k] == CartesianIndex (i,j)
146152 @test LinearIndices (0 : 3 ,3 : 5 )[i- 1 ,j+ 2 ] == k
147153 @test CartesianIndices (0 : 3 ,3 : 5 )[k] == CartesianIndex (i- 1 ,j+ 2 )
148154 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)
149163 end
150164
151165 @testset " 3-dimensional" begin
152166 l = 0
153167 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)
155172 @test CartesianIndices ((4 ,3 ,2 ))[l] == CartesianIndex (i,j,k)
156173 @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)
157176 @test CartesianIndices (1 : 4 ,1 : 3 ,1 : 2 )[l] == CartesianIndex (i,j,k)
158177 @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 )
159180 @test CartesianIndices (0 : 3 ,3 : 5 ,- 101 : - 100 )[l] == CartesianIndex (i- 1 , j+ 2 , k- 102 )
160181 end
161182
0 commit comments