From 793d035a630fc053307e2cf672277c41da843c5e Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Thu, 10 Feb 2022 13:46:50 +0800 Subject: [PATCH] Fix regression on `StaticArray` --- src/staticarrays_support.jl | 9 +++++++-- test/runtests.jl | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/staticarrays_support.jl b/src/staticarrays_support.jl index ce1875b0..bf1eeb2d 100644 --- a/src/staticarrays_support.jl +++ b/src/staticarrays_support.jl @@ -1,4 +1,4 @@ -import StaticArrays: StaticArray, FieldArray, tuple_prod +import StaticArrays: StaticArray, FieldArray, tuple_prod, StaticArrayStyle """ StructArrays.staticschema(::Type{<:StaticArray{S, T}}) where {S, T} @@ -26,4 +26,9 @@ StructArrays.component(s::StaticArray, i) = getindex(s, i) invoke(StructArrays.staticschema, Tuple{Type{<:Any}}, T) end StructArrays.component(s::FieldArray, i) = invoke(StructArrays.component, Tuple{Any, Any}, s, i) -StructArrays.createinstance(T::Type{<:FieldArray}, args...) = invoke(createinstance, Tuple{Type{<:Any}, Vararg}, T, args...) \ No newline at end of file +StructArrays.createinstance(T::Type{<:FieldArray}, args...) = invoke(createinstance, Tuple{Type{<:Any}, Vararg}, T, args...) + +function Base.copy(bc::Broadcasted{<:StructArrayStyle{StaticArrayStyle{N}}}) where {N} + B = convert(Broadcasted{Broadcast.DefaultArrayStyle{N}}, bc) + copy(B) +end diff --git a/test/runtests.jl b/test/runtests.jl index a4f19ce4..802ca059 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -987,6 +987,10 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray1}, ::Broadcast.ArrayStyle{MyA a = StructArray([1;2+im]) b = StructArray([1 2+im]) @test @inferred(a .+ b .+ a .* a' .+ (1,2) .+ (1:2) .- b') isa StructArray + + a = @SArray randn(3,3); + b = StructArray{ComplexF64}((a,a)) + @test a[:,1] .+ b isa SizedMatrix end @testset "staticarrays" begin