Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StructArrays #86

Open
cscherrer opened this issue Aug 14, 2020 · 0 comments
Open

StructArrays #86

cscherrer opened this issue Aug 14, 2020 · 0 comments

Comments

@cscherrer
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant