@@ -137,6 +137,12 @@ using StaticArrays, Test
137
137
@test v[2 ,1 ] == 2
138
138
@test_throws BoundsError v[1 ,2 ]
139
139
@test_throws BoundsError v[3 ,1 ]
140
+
141
+ # SOneTo
142
+ @test (@inferred v[axes (v,1 ), SOneTo (1 )]) === SMatrix {2,1} (v)
143
+ @test v[axes (v,1 ), SOneTo (1 )] == v[Base. OneTo (length (v)), Base. OneTo (1 )]
144
+ @test (@inferred v[axes (v,1 ), 1 , SOneTo (1 )]) === SMatrix {2,1} (v)
145
+ @test v[axes (v,1 ), 1 , SOneTo (1 )] == v[Base. OneTo (length (v)), 1 , Base. OneTo (1 )]
140
146
end
141
147
142
148
@testset " 2D getindex() on SMatrix" begin
@@ -249,6 +255,29 @@ using StaticArrays, Test
249
255
@test (@inferred getindex (a, SVector (1 ,2 ), 1 , 1 , 1 )) == [24 ,48 ]
250
256
end
251
257
258
+ @testset " indexing with reshape for SMatrix/MMatrix" begin
259
+ sm = @SMatrix [1 3 ; 2 4 ]
260
+ mm = @MMatrix [1 3 ; 2 4 ]
261
+ for m in Any[sm, mm, view (sm, :, :), view (mm, :, :)]
262
+ sa = @inferred m[:, SOneTo (1 ), 1 , SOneTo (1 )]
263
+ a = m[:, Base. OneTo (1 ), 1 , Base. OneTo (1 )]
264
+ @test sa == a
265
+ @test sa == SArray {Tuple{2,1,1}} (a)
266
+ if m isa SArray
267
+ @test sa === SArray {Tuple{2,1,1}} (a)
268
+ end
269
+
270
+ if isdefined (Base, :IdentityUnitRange )
271
+ sa = @inferred m[:, Base. IdentityUnitRange (SOneTo (1 )), 1 , SOneTo (1 )]
272
+ @test sa == a
273
+ @test sa == SArray {Tuple{2,1,1}} (a)
274
+ if m isa SArray
275
+ @test sa === SArray {Tuple{2,1,1}} (a)
276
+ end
277
+ end
278
+ end
279
+ end
280
+
252
281
@testset " Indexing with empty vectors" begin
253
282
a = [1.0 2.0 ; 3.0 4.0 ]
254
283
@test a[SVector {0,Int} ()] == SVector {0,Float64} (())
0 commit comments