Quick way to reinterpret this?

Hello!

When reading from a .h5 file, where I have saved some position value as SVector{3,Float64} I get this:

julia> data["Position"]
3027-element Vector{@NamedTuple{data::@NamedTuple{1::Float64, 2::Float64, 3::Float64}}}:
 (data = (var"1" = -0.04, var"2" = -0.04, var"3" = 0.0),)
 (data = (var"1" = -0.04, var"2" = -0.02, var"3" = 0.0),)
 (data = (var"1" = -0.02, var"2" = -0.04, var"3" = 0.0),)
 (data = (var"1" = -0.02, var"2" = -0.02, var"3" = 0.0),)

Is there a quick and efficient way to reinterpret this back to a SVector{3,Float64} or 3xN matrix?

Kind regards

At the risk of asking the obvious: is reinterpret what you’re looking for?

Array of deserialized data:

julia> d = [(data = (var"1" = -0.04, var"2" = -0.04, var"3" = 0.0),)
            (data = (var"1" = -0.04, var"2" = -0.02, var"3" = 0.0),)
            (data = (var"1" = -0.02, var"2" = -0.04, var"3" = 0.0),)
            (data = (var"1" = -0.02, var"2" = -0.02, var"3" = 0.0),)]
4-element Vector{@NamedTuple{data::@NamedTuple{1::Float64, 2::Float64, 3::Float64}}}:
 (data = (var"1" = -0.04, var"2" = -0.04, var"3" = 0.0),)
 (data = (var"1" = -0.04, var"2" = -0.02, var"3" = 0.0),)
 (data = (var"1" = -0.02, var"2" = -0.04, var"3" = 0.0),)
 (data = (var"1" = -0.02, var"2" = -0.02, var"3" = 0.0),)

Reinterpreted as an array of SVector{3, Float64}:

julia> using StaticArrays
julia> reinterpret(SVector{3, Float64}, d)
4-element reinterpret(SVector{3, Float64}, ::Vector{@NamedTuple{data::@NamedTuple{1::Float64, 2::Float64, 3::Float64}}}):
 [-0.04, -0.04, 0.0]
 [-0.04, -0.02, 0.0]
 [-0.02, -0.04, 0.0]
 [-0.02, -0.02, 0.0]

Reinterpreted as a 3xN array of Float64:

julia> reinterpret(reshape, Float64, d)
3×4 reinterpret(reshape, Float64, ::Vector{@NamedTuple{data::@NamedTuple{1::Float64, 2::Float64, 3::Float64}}}) with eltype Float64:
 -0.04  -0.04  -0.02  -0.02
 -0.04  -0.02  -0.04  -0.02
  0.0    0.0    0.0    0.0
1 Like

That is perfect. It was reshape I was missing, thanks!