Skip to content

Cannot both broadcast and access components with StructArrays of StaticArrays  #179

@jlchan

Description

@jlchan

One nice feature is that StructArrays built from StaticArrays are compatible with broadcasting, e.g.,

x = StructArray([SVector{2}(1.,2.) for i = 1:5])
x .+ x  # works
2 .* x  # works

However, it's harder to access the components - StructArrays.components(x) just returns the underlying storage for SVector

julia> StructArrays.components(x)
(data = [(1.0, 2.0), (1.0, 2.0), (1.0, 2.0), (1.0, 2.0), (1.0, 2.0)],).

It's possible to extract the components using unwrap and accessing the underlying SVector storage directly

x = StructArray([SVector(1., 2,) for i in 1:5], unwrap = t -> t <: Tuple)
StructArrays.components(x.data) # returns a tuple containing a vector of 1's and a vector of 2's

but this creates a nested StructArray with type

StructArray(StructArray(::Vector{Float64}, ::Vector{Float64}))  with eltype SVector{2, Float64}

Because of the nested StructArray types, both operation and function broadcasting break again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions