StructArrays.jl icon indicating copy to clipboard operation
StructArrays.jl copied to clipboard

don't force eager conversions when not necessary, fix #228

Open aplavin opened this issue 3 years ago • 2 comments

aplavin avatar Jun 01 '22 08:06 aplavin

Seems reasonable to me. For tuples and named tuples the conversion would happen field by field regardless when calling setindex! and company on the component arrays. It may be best to add some comments explain the rationale in the code, as this seems like a somewhat delicate choice.

EDIT: thinking more about it, this has issues for nested structures. For example, the following errors here but works on master

julia> using StructArrays

julia> s = StructArray(x=StructArray(rand(ComplexF64, 1)))
1-element StructArray(StructArray(::Vector{Float64}, ::Vector{Float64})) with eltype NamedTuple{(:x,), Tuple{ComplexF64}}:
 (x = 0.1722611417806078 + 0.4879486345600308im,)

julia> push!(s, (x=1,))
ERROR: type Int64 has no field re

The reason is that push! does not recurrently call push! if some columns are StructArrays, but the whole thing is unrolled, for performance reasons. I suspect the correct implementation should take into account the "nesting structure" of the StructArray, though I'm not 100% sure what that would look like.

piever avatar Jun 08 '22 18:06 piever

Personally, I would close this unless #228 gets a better example of a real problem.

timholy avatar Jun 26 '22 12:06 timholy