julia> using StructArrays #, BenchmarkTools
julia> mutable struct M{T}
x::T
end
julia> ms = [M((;a=rand(), b=rand(1:2))) for _ ∈ 1:10]
10-element Vector{M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}}:
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.28755525874520704, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.48459762010752394, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.8595309903519835, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.9999199980992112, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.07601872388828879, b = 1))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.9043072853815545, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.7170560150210613, b = 1))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.36632931891866216, b = 1))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.005976654462236608, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.9097792660807252, b = 1))
julia> StructArrays.staticschema(::Type{M{NamedTuple{names, types}}}) where {names, types} = NamedTuple{names, types}
julia> StructArrays.component(m::M, key::Symbol) = getfield(getfield(m, 1), key)
julia> StructArrays.createinstance(::Type{M{T}}, args...) where T = M(T(args))
julia> sa=StructArray(ms)
10-element StructArray(::Vector{Float64}, ::Vector{Int64}) with eltype M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}:
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.28755525874520704, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.48459762010752394, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.8595309903519835, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.9999199980992112, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.07601872388828879, b = 1))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.9043072853815545, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.7170560150210613, b = 1))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.36632931891866216, b = 1))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.005976654462236608, b = 2))
M{NamedTuple{(:a, :b), Tuple{Float64, Int64}}}((a = 0.9097792660807252, b = 1))
Thank you.
It seems plausible to me that it is in this function that the “initialization” of the “components” of the structarray occurs.
I tried using the instructions in the package documentation in the “advanced examples” paragraph.
I tried navigating with the debugger and various breakpoints, but I couldn’t get to those functions… the debugger fails on this function at the if @generated statement
function map_params_as_tuple(f::F, ::Type{T}) where {F, T<:Tup}
if @generated
types = fieldtypes(T)
args = map(t -> :(f($t)), types)
Expr(:tuple, args...)
else
map_params_as_tuple_fallback(f, T)
end
end