@@ -1136,6 +1136,7 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray1}, ::Broadcast.ArrayStyle{MyA
1136
1136
Base. BroadcastStyle (:: Broadcast.ArrayStyle{MyArray2} , S:: Broadcast.DefaultArrayStyle ) = S
1137
1137
1138
1138
@testset " broadcast" begin
1139
+ dotaddsub ((a, b, c),) = a .+ b .- c
1139
1140
s = StructArray {ComplexF64} ((rand (2 ,2 ), rand (2 ,2 )))
1140
1141
@test isa (@inferred (s .+ s), StructArray)
1141
1142
@test (s .+ s). re == 2 * s. re
@@ -1159,18 +1160,21 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
1159
1160
s2 = StructArray {ComplexF64} ((MyArray2 (rand (2 )), MyArray2 (rand (2 ))))
1160
1161
s3 = StructArray {ComplexF64} ((MyArray3 (rand (2 )), MyArray3 (rand (2 ))))
1161
1162
s4 = StructArray {ComplexF64} ((rand (2 ), rand (2 )))
1162
-
1163
- function _test_similar (a, b, c)
1164
- try
1165
- d = StructArray {ComplexF64} ((a. re .+ b. re .- c. re, a. im .+ b. im .- c. im))
1166
- @test typeof (a .+ b .- c) == typeof (d)
1167
- catch
1168
- @test_throws MethodError a .+ b .- c
1163
+ test_set = Any[s1, s2, s3, s4]
1164
+ for ia in 1 : 4 , ib in 1 : 4 , ic in 1 : 4
1165
+ as = test_set[ia], test_set[ib], test_set[ic]
1166
+ is = ia, ib, ic
1167
+ ns = count (== (3 ), is), count (== (4 ), is)
1168
+ if count (== (2 ), is) == 0 && ! (ia<= ib<= ic)
1169
+ # Skip some order independent test (MyArray1 > MyArray3 > Array)
1170
+ continue
1171
+ elseif ns in ((1 ,2 ), (2 ,1 )) || (ic == 3 && ia + ib == 6 )
1172
+ @test_throws MethodError dotaddsub (as)
1173
+ else
1174
+ d = StructArray {ComplexF64} ((dotaddsub (map (a-> a. re, as)), dotaddsub (map (a-> a. im, as))))
1175
+ @test @inferred (dotaddsub (as)):: typeof (d) == d
1169
1176
end
1170
1177
end
1171
- for s in (s1,s2,s3,s4), s′ in (s1,s2,s3,s4), s″ in (s1,s2,s3,s4)
1172
- _test_similar (s, s′, s″)
1173
- end
1174
1178
1175
1179
# test for dimensionality track
1176
1180
s = s1
@@ -1197,21 +1201,20 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
1197
1201
@test (x -> x. x. x. a). (StructArray (x= StructArray (x= StructArray (a= 1 : 3 )))) == [1 , 2 , 3 ]
1198
1202
1199
1203
@testset " ambiguity check" begin
1200
- function _test (a, b, c)
1201
- if a isa StructArray || b isa StructArray || c isa StructArray
1202
- d = @inferred a .+ b .- c
1203
- @test d == collect (a) .+ collect (b) .- collect (c)
1204
- @test d isa StructArray
1205
- end
1206
- end
1207
1204
testset = Any[StructArray ([1 ;2 + im]),
1208
1205
1 : 2 ,
1209
1206
(1 ,2 ),
1210
1207
StructArray (@SArray [1 1 + 2im ]),
1211
1208
(@SArray [1 2 ])
1212
1209
]
1213
- for aa in testset, bb in testset, cc in testset
1214
- _test (aa, bb, cc)
1210
+ # The 3 styles in testset has clear priorities:
1211
+ # Style{Tuple} < StaticArrayStyle < DefaultArrayStyle
1212
+ # Thus is OK to skip some test as the result is order independent
1213
+ for ia in 1 : 5 , ib in ia: 5 , ic in ib: 5
1214
+ as = a, b, c = testset[ia], testset[ib], testset[ic]
1215
+ if a isa StructArray || b isa StructArray || c isa StructArray
1216
+ @test @inferred (dotaddsub (as)):: StructArray == dotaddsub (map (collect, as))
1217
+ end
1215
1218
end
1216
1219
end
1217
1220
0 commit comments