Reinterpret SVector

Hello everyone,

I’ve got a question regarding the usage of reinterpret in combination with StaticArrays.SVector:
As described in the readme something like
“”“julia
x = rand(3,3)
reinterpret(SVector{3,Float64}, x, (3,))
“””
works, but the other way round it won’t work:

“”“julia
x = [SVector{3,Float64}(rand(3)) for i = 1:3]
reinterpret(Matrix{Float64}, x, (3,3))
“””

Is it possible to reinterpret a Vector of SVectors as a Matrix{Float64}?

Thank you in advance
Best, Max

x = [SVector{3, Float64}(rand(3)) for i = 1:3]
y = reinterpret(Float64, x, (3, 3))

The first argument to reinterpret should be the type of the element of the resulting array (i.e., the result of eltype(y).

3 Likes

That makes sense!
Thank you!