@@ -67,29 +67,29 @@ for (_A, Ar, _B) in ((A, Ars, B), (As, Arss, Bs))
67
67
reinterpret (NTuple{3 , Int64}, Bc)[2 ] = (4 ,5 ,6 )
68
68
@test Bc == Complex{Int64}[5 + 6im , 7 + 4im , 5 + 6im ]
69
69
B2 = reinterpret (NTuple{3 , Int64}, Bc)
70
- @test setindex! (B2, (1 ,2 ,3 ), 1 ) == B2
70
+ @test setindex! (B2, (1 ,2 ,3 ), 1 ) === B2
71
71
@test Bc == Complex{Int64}[1 + 2im , 3 + 4im , 5 + 6im ]
72
72
Bc = copy (_B)
73
73
Brrs = reinterpret (reshape, Int64, Bc)
74
- @test setindex! (Brrs, - 5 , 2 , 3 ) == Brrs
74
+ @test setindex! (Brrs, - 5 , 2 , 3 ) === Brrs
75
75
@test Bc == Complex{Int64}[5 + 6im , 7 + 8im , 9 - 5im ]
76
76
Brrs[last (eachindex (Brrs))] = 22
77
77
@test Bc == Complex{Int64}[5 + 6im , 7 + 8im , 9 + 22im ]
78
78
79
79
A1 = reinterpret (Float64, _A)
80
80
A2 = reinterpret (ComplexF64, _A)
81
- @test setindex! (A1, 1.0 , 1 ) == A1
81
+ @test setindex! (A1, 1.0 , 1 ) === A1
82
82
@test real (A2[1 ]) == 1.0
83
83
A1 = reinterpret (reshape, Float64, _A)
84
- A1[ 1 ] = 2.5
84
+ @test setindex! (A1, 2.5 , 1 ) === A1
85
85
@test reinterpret (Float64, _A[1 ]) == 2.5
86
86
A1rs = reinterpret (Float64, Ar)
87
87
A2rs = reinterpret (ComplexF64, Ar)
88
- A1rs[ 1 , 1 ] = 1.0
88
+ @test setindex! ( A1rs, 1.0 , 1 , 1 ) === A1rs
89
89
@test real (A2rs[1 ]) == 1.0
90
90
A1rs = reinterpret (reshape, Float64, Ar)
91
91
A2rs = reinterpret (reshape, ComplexF64, Ar)
92
- @test setindex! (A1rs, 2.5 , 1 , 1 ) == A1rs
92
+ @test setindex! (A1rs, 2.5 , 1 , 1 ) === A1rs
93
93
@test real (A2rs[1 ]) == 2.5
94
94
end
95
95
end
@@ -107,14 +107,14 @@ A3r[CartesianIndex(1,2)] = 300+400im
107
107
@test A3[2 ,1 ,2 ] == 400
108
108
109
109
# same-size reinterpret where one of the types is non-primitive
110
- let a = NTuple{4 ,UInt8}[(0x01 ,0x02 ,0x03 ,0x04 )]
111
- @test reinterpret (Float32, a) [1 ] == reinterpret (Float32, 0x04030201 )
112
- reinterpret (Float32, a)[ 1 ] = 2.0
110
+ let a = NTuple{4 ,UInt8}[(0x01 ,0x02 ,0x03 ,0x04 )], ra = reinterpret (Float32, a)
111
+ @test ra [1 ] == reinterpret (Float32, 0x04030201 )
112
+ @test setindex! (ra, 2.0 ) === ra
113
113
@test reinterpret (Float32, a)[1 ] == 2.0
114
114
end
115
- let a = NTuple{4 ,UInt8}[(0x01 ,0x02 ,0x03 ,0x04 )]
116
- @test reinterpret (reshape, Float32, a) [1 ] == reinterpret (Float32, 0x04030201 )
117
- reinterpret (reshape, Float32, a)[ 1 ] = 2.0
115
+ let a = NTuple{4 ,UInt8}[(0x01 ,0x02 ,0x03 ,0x04 )], ra = reinterpret (reshape, Float32, a)
116
+ @test ra [1 ] == reinterpret (Float32, 0x04030201 )
117
+ @test setindex! (ra, 2.0 ) === ra
118
118
@test reinterpret (reshape, Float32, a)[1 ] == 2.0
119
119
end
120
120
@@ -198,7 +198,7 @@ let a = fill(1.0, 5, 3)
198
198
@test_throws BoundsError r[badinds... ] = - 2
199
199
end
200
200
for goodinds in (1 , 15 , (1 ,1 ), (5 ,3 ))
201
- r[ goodinds... ] = - 2
201
+ @test setindex! (r, - 2 , goodinds... ) === r
202
202
@test r[goodinds... ] == - 2
203
203
end
204
204
r = reinterpret (Int32, a)
@@ -211,7 +211,7 @@ let a = fill(1.0, 5, 3)
211
211
@test_throws BoundsError r[badinds... ] = - 3
212
212
end
213
213
for goodinds in (1 , 30 , (1 ,1 ), (10 ,3 ))
214
- r[ goodinds... ] = - 3
214
+ @test setindex! (r, - 3 , goodinds... ) === r
215
215
@test r[goodinds... ] == - 3
216
216
end
217
217
r = reinterpret (Int64, view (a, 1 : 2 : 5 , :))
@@ -224,7 +224,7 @@ let a = fill(1.0, 5, 3)
224
224
@test_throws BoundsError r[badinds... ] = - 4
225
225
end
226
226
for goodinds in (1 , 9 , (1 ,1 ), (3 ,3 ))
227
- r[ goodinds... ] = - 4
227
+ @test setindex! (r, - 4 , goodinds... ) === r
228
228
@test r[goodinds... ] == - 4
229
229
end
230
230
r = reinterpret (Int32, view (a, 1 : 2 : 5 , :))
@@ -237,7 +237,7 @@ let a = fill(1.0, 5, 3)
237
237
@test_throws BoundsError r[badinds... ] = - 5
238
238
end
239
239
for goodinds in (1 , 18 , (1 ,1 ), (6 ,3 ))
240
- r[ goodinds... ] = - 5
240
+ @test setindex! (r, - 5 , goodinds... ) === r
241
241
@test r[goodinds... ] == - 5
242
242
end
243
243
@@ -318,14 +318,25 @@ end
318
318
319
319
# Test 0-dimensional Arrays
320
320
A = zeros (UInt32)
321
- B = reinterpret (Int32,A)
322
- Brs = reinterpret (reshape,Int32,A)
323
- @test size (B) == size (Brs) == ()
324
- @test axes (B) == axes (Brs) == ()
325
- B[] = Int32 (5 )
321
+ B = reinterpret (Int32, A)
322
+ Brs = reinterpret (reshape,Int32, A)
323
+ C = reinterpret (Tuple{UInt32}, A) # non-primitive type
324
+ Crs = reinterpret (reshape, Tuple{UInt32}, A) # non-primitive type
325
+ @test size (B) == size (Brs) == size (C) == size (Crs) == ()
326
+ @test axes (B) == axes (Brs) == axes (C) == axes (Crs) == ()
327
+ @test setindex! (B, Int32 (5 )) === B
326
328
@test B[] === Int32 (5 )
327
329
@test Brs[] === Int32 (5 )
330
+ @test C[] === (UInt32 (5 ),)
331
+ @test Crs[] === (UInt32 (5 ),)
328
332
@test A[] === UInt32 (5 )
333
+ @test setindex! (Brs, Int32 (12 )) === Brs
334
+ @test A[] === UInt32 (12 )
335
+ @test setindex! (C, (UInt32 (7 ),)) === C
336
+ @test A[] === UInt32 (7 )
337
+ @test setindex! (Crs, (UInt32 (3 ),)) === Crs
338
+ @test A[] === UInt32 (3 )
339
+
329
340
330
341
a = [(1.0 ,2.0 )]
331
342
af = @inferred (reinterpret (reshape, Float64, a))
@@ -413,13 +424,15 @@ end
413
424
z = reinterpret (Tuple{}, fill (missing , ()))
414
425
@test z == fill ((), ())
415
426
@test z == reinterpret (reshape, Tuple{}, fill (nothing , ()))
427
+ @test z[] == ()
428
+ @test setindex! (z, ()) === z
416
429
@test_throws BoundsError z[2 ]
417
430
@test_throws BoundsError z[3 ] = ()
418
431
@test_throws ArgumentError reinterpret (UInt8, fill (nothing , ()))
419
432
@test_throws ArgumentError reinterpret (Missing, fill (1f0 , ()))
420
433
@test_throws ArgumentError reinterpret (reshape, Float64, fill (nothing , ()))
421
434
@test_throws ArgumentError reinterpret (reshape, Nothing, fill (17 , ()))
422
-
435
+ @test_throws MethodError z[] = nothing
423
436
424
437
@test @inferred (ndims (reinterpret (reshape, SomeSingleton, t))) == 2
425
438
@test @inferred (axes (reinterpret (reshape, Tuple{}, t))) == (Base. OneTo (3 ),Base. OneTo (5 ))
0 commit comments