Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ StructVector(args...; kwargs...) = StructArray(args...; kwargs...)
"""
StructArray{T}(A::AbstractArray; dims, unwrap=FT->FT!=eltype(A))

Construct a `StructArray` from slices of `A` along `dims`.
Construct a `StructArray` from slices of `A` along `dims`.

The `unwrap` keyword argument is a function that determines whether to
recursively convert fields of type `FT` to `StructArray`s.
Expand Down Expand Up @@ -441,3 +441,6 @@ BroadcastStyle(::Type{SA}) where SA<:StructArray = StructArrayStyle{typeof(cst(S

Base.similar(bc::Broadcasted{StructArrayStyle{S}}, ::Type{ElType}) where {S<:DefaultArrayStyle,N,ElType} =
isstructtype(ElType) ? similar(StructArray{ElType}, axes(bc)) : similar(Array{ElType}, axes(bc))

# for aliasing analysis during broadcast
Base.dataids(u::StructArray) = mapreduce(Base.dataids, (a, b) -> (a..., b...), values(components(u)), init=())
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -813,14 +813,17 @@ Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{MyArray}}, ::Type{El
@test isa(@inferred(s .+ r), StructArray)
@test s .+ r == StructArray{ComplexF64}((s.re .+ r, s.im))

# used inside of broadcast but we also test it here explicitly
@test isa(@inferred(Base.dataids(s)), NTuple{N, UInt} where {N})

s = StructArray{ComplexF64}((MyArray(rand(2,2)), MyArray(rand(2,2))))
@test_throws MethodError s .+ s
end

@testset "staticarrays" begin

# test that staticschema returns the right things
for StaticVectorType = [SVector, MVector, SizedVector]
for StaticVectorType = [SVector, MVector, SizedVector]
@test StructArrays.staticschema(StaticVectorType{2,Float64}) == Tuple{Float64,Float64}
end

Expand Down