MonteCarloMeasurements.jl
MonteCarloMeasurements.jl copied to clipboard
StructArrays
Hi @baggepinnen , we've talked before about StructArrays...
I haven't used this package much before, but I did get this going and it seems to work well:
julia> using StructArrays, MonteCarloMeasurements, NamedTupleTools, BenchmarkTools
julia> function structarray(nt::NamedTuple)
return StructArray(prototype(nt)(getproperty.(values(nt), :particles)))
end
structarray (generic function with 1 method)
julia> nt = (x=Particles(5), y=Particles(5))
(x = -4.44e-17 ± 0.98, y = -4.44e-17 ± 0.98)
julia> @btime structarray($nt)
2.063 ns (0 allocations: 0 bytes)
5-element StructArray(::Array{Float64,1}, ::Array{Float64,1}) with eltype NamedTuple{(:x, :y),Tuple{Float64,Float64}}:
(x = -1.2815515655446004, y = -1.2815515655446004)
(x = -0.5244005127080408, y = -0.5244005127080408)
(x = 0.5244005127080407, y = 0.5244005127080407)
(x = 1.2815515655446004, y = 0.0)
(x = 0.0, y = 1.2815515655446004)
Not sure how this might fit in with your manipulations in the package, just passing it along in case it's helpful :)