Best practices for handling arrays of points


#1

I’m working with arrays of d-dimensional StaticArrays (representing trajectories in d-space, for d a small integer). It seems that standard library functions are not set-up well to deal with this: as a simple example, I can’t find an efficient standard library function to convert this to an N x 3 array (given that zip(arr…) is very slow if arr is long). Is this a sign that in Julia this type of data should be represented in a different way?


#2

This is explained in the StaticArrays docs:

julia> X = [@SArray randn(3) for i = 1:5]
5-element Array{SVector{3,Float64},1}:
 [1.7243, 1.74027, 0.152618]    
 [0.312562, -0.487502, 0.221353]
 [1.10307, -1.032, 0.898139]    
 [-0.158312, -0.230623, 1.10006]
 [-1.39961, 1.11121, -1.54268]  

julia> reinterpret(Float64, X, (3,5))
3×5 Array{Float64,2}:
 1.7243     0.312562   1.10307   -0.158312  -1.39961
 1.74027   -0.487502  -1.032     -0.230623   1.11121
 0.152618   0.221353   0.898139   1.10006   -1.54268

Note that Julia is column-major, so you will get a 3xN array.


#3

Aha, this is exactly what I needed. Thanks!


#4

Note that the typeof the output in v0.7 is:

julia> reinterpret(Float64, X, (3,5))
3×5 reshape(reinterpret(Float64, ::Array{SVector{3,Float64},1}), 3, 5) with eltype Float64:

I know it can be dealt with the same as 3×5 Array{Float64,2} but is a bit weird.