How to reinterpret existing array in to a StaticArray

Continuing the discussion from Reinterpret 3D array into array of SMatrices:

I asked a similar question before, but the solution doesn’t work any longer. I used to be able to do this but now it throws an error that I don’t understand:

using StaticArrays
A = rand(2,3,5);
reinterpret(SMatrix{2,3,Float64},A,(5,),2*3)
ERROR: MethodError: no method matching reinterpret(::Type{StaticArrays.SArray{Tuple{2,3},Float64,2,L} where L}, ::Array{Float64,3}, ::Tuple{Int64}, ::Int64)
Closest candidates are:
  reinterpret(::Type{T}, ::Array{S,N} where N, ::Tuple{Vararg{Int64,N}}) where {N, S, T} at array.jl:155
  reinterpret(::Type{T}, ::Array{S,N} where N) where {S, T} at array.jl:148
  reinterpret(::Type{T}, ::Base.ReshapedArray, ::Tuple{Vararg{Int64,N}} where N) where T at reshapedarray.jl:171
  ...

any ideas?

thanks!

oh i see. this has to be put inside the type declaration now:

reinterpret(SMatrix{2,3,Float64,6},A,(5,))

5-element Array{StaticArrays.SArray{Tuple{2,3},Float64,2,6},1}:
 [0.00793254 0.304444 0.932803; 0.765576 0.847383 0.391187]
 [0.651666 0.885873 0.648122; 0.146218 0.261972 0.594099]  
 [0.410662 0.523081 0.945088; 0.129933 0.144542 0.227049]  
 [0.975269 0.86898 0.997614; 0.909002 0.329853 0.73141]    
 [0.351473 0.864738 0.769397; 0.79498 0.977108 0.390928]   

sorry there was someone replying just now…

2 Likes