I cannot change the type of the input parameter of the unpack function, because this is a callback function from an ODE solver.
But you inspired me to find the following solution:’
function unpack(y)
part = reshape(SVector{6*(SEGMENTS+1)}(y), Size(3, SEGMENTS+1, 2))
pos1 = part[:,:,1]
SVector{SEGMENTS+1}(SVector(pos1[:,i]) for i in 1:SEGMENTS+1)
end
Output:
julia> include("src/test.jl")
7-element SVector{7, SVector{3, Float64}} with indices SOneTo(7):
[1.0, 2.0, 3.0]
[0.0, 0.0, 0.0]
[0.0, 0.0, 0.0]
[0.0, 0.0, 0.0]
[0.0, 0.0, 0.0]
[0.0, 0.0, 0.0]
[0.0, 0.0, 0.0]
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 6.581 ns (0.00% GC)
median time: 6.699 ns (0.00% GC)
mean time: 7.011 ns (0.00% GC)
maximum time: 38.815 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 1000