@@ -917,6 +917,7 @@ Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{MyArray1}}, ::Type{E
917
917
Base. similar (bc:: Broadcast.Broadcasted{Broadcast.ArrayStyle{MyArray2}} , :: Type{ElType} ) where ElType =
918
918
MyArray2 {ElType} (undef, size (bc))
919
919
Base. BroadcastStyle (:: Broadcast.ArrayStyle{MyArray1} , :: Broadcast.ArrayStyle{MyArray3} ) = Broadcast. ArrayStyle {MyArray1} ()
920
+ Base. BroadcastStyle (:: Broadcast.ArrayStyle{MyArray2} , S:: Broadcast.DefaultArrayStyle ) = S
920
921
921
922
@testset " broadcast" begin
922
923
s = StructArray {ComplexF64} ((rand (2 ,2 ), rand (2 ,2 )))
@@ -935,27 +936,24 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray1}, ::Broadcast.ArrayStyle{MyA
935
936
@test isa (@inferred (Base. dataids (s)), NTuple{N, UInt} where {N})
936
937
937
938
# Make sure we can handle style with similar defined
939
+ # And we can handle most conflict
938
940
# s1 and s2 has similar defined, but s3 not
939
- # s2 are conflict with s1 and s3.
941
+ # s2 are conflict with s1 and s3. (And it's weaker than DefaultArrayStyle)
940
942
s1 = StructArray {ComplexF64} ((MyArray1 (rand (2 )), MyArray1 (rand (2 ))))
941
943
s2 = StructArray {ComplexF64} ((MyArray2 (rand (2 )), MyArray2 (rand (2 ))))
942
944
s3 = StructArray {ComplexF64} ((MyArray3 (rand (2 )), MyArray3 (rand (2 ))))
945
+ s4 = StructArray {ComplexF64} ((rand (2 ), rand (2 )))
943
946
944
- function _test_similar (a, b)
945
- flag = false
947
+ function _test_similar (a, b, c)
946
948
try
947
- c = StructArray {ComplexF64} ((a. re .+ b. re, a. im .+ b. im))
948
- flag = true
949
+ d = StructArray {ComplexF64} ((a. re .+ b. re .- c . re , a. im .+ b. im .- c . im))
950
+ @test typeof (a .+ b .- c) == typeof (d)
949
951
catch
950
- end
951
- if flag
952
- @test typeof (@inferred (a .+ b)) == typeof (c)
953
- else
954
- @test_throws MethodError a .+ b
952
+ @test_throws MethodError a .+ b .- c
955
953
end
956
954
end
957
- for s in (s1,s2,s3), s′ in (s1,s2,s3)
958
- _test_similar (s, s′)
955
+ for s in (s1,s2,s3,s4 ), s′ in (s1,s2,s3,s4), s″ in (s1,s2,s3,s4 )
956
+ _test_similar (s, s′, s″ )
959
957
end
960
958
961
959
# test for dimensionality track
@@ -973,20 +971,26 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray1}, ::Broadcast.ArrayStyle{MyA
973
971
@test (A .= B .* c) === A
974
972
975
973
# ambiguity check (can we do this better?)
976
- function _test (a, b)
977
- if a isa StructArray || b isa StructArray
978
- d = @inferred a .+ b
979
- @test d == collect (a) .+ collect (b)
974
+ function _test (a, b, c )
975
+ if a isa StructArray || b isa StructArray || c isa StructArray
976
+ d = @inferred a .+ b .- c
977
+ @test d == collect (a) .+ collect (b) .- collect (c)
980
978
@test d isa StructArray
981
979
end
982
980
end
983
- testset = StructArray ([1 ;2 + im]), StructArray ([1 2 + im]), 1 : 2 , (1 ,2 ), (@SArray [1 2 ])
984
- for aa in testset, bb in testset
985
- _test (aa, bb)
981
+ testset = (StructArray ([1 ;2 + im]),
982
+ StructArray ([1 2 + im]),
983
+ 1 : 2 ,
984
+ (1 ,2 ),
985
+ (@SArray [1 2 ]),
986
+ StructArray (@SArray [1 1 + 2im ]))
987
+ for aa in testset, bb in testset, cc in testset
988
+ _test (aa, bb, cc)
986
989
end
987
- a = StructArray ([1 ;2 + im])
988
- b = StructArray ([1 2 + im])
989
- @test @inferred (a .+ b .+ a .* a' .+ (1 ,2 ) .+ (1 : 2 ) .- b' ) isa StructArray
990
+
991
+ a = @SArray randn (3 ,3 );
992
+ b = StructArray {ComplexF64} ((a,a))
993
+ @test a[:,1 ] .+ b isa StructArray && (a[:,1 ] .+ b). re isa SizedMatrix
990
994
end
991
995
992
996
@testset " staticarrays" begin
0 commit comments