Skip to content

Commit

Permalink
fix nested structarrays broadcasting (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin authored Oct 10, 2022
1 parent 5c88775 commit efda46e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ Base.@pure cst(::Type{SA}) where {SA} = combine_style_types(array_types(SA).para

BroadcastStyle(::Type{SA}) where {SA<:StructArray} = StructArrayStyle{typeof(cst(SA)), ndims(SA)}()

function Base.similar(bc::Broadcasted{StructArrayStyle{S, N}}, ::Type{ElType}) where {S<:DefaultArrayStyle, N, ElType}
function Base.similar(bc::Broadcasted{StructArrayStyle{S, N}}, ::Type{ElType}) where {S<:Union{DefaultArrayStyle,StructArrayStyle}, N, ElType}
ContainerType = isnonemptystructtype(ElType) ? StructArray{ElType} : Array{ElType}
return similar(ContainerType, axes(bc))
end
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,9 @@ Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{MyArray}}, ::Type{El
# issue #189
v = StructArray([(a="s1",), (a="s2",)])
@test @inferred(broadcast(el -> el.a, v)) == ["s1", "s2"]

@test identity.(StructArray(x=StructArray(a=1:3)))::StructArray == [(x=(a=1,),), (x=(a=2,),), (x=(a=3,),)]
@test (x -> x.x.a).(StructArray(x=StructArray(a=1:3))) == [1, 2, 3]
end

@testset "map" begin
Expand Down

0 comments on commit efda46e

Please sign in to comment.