I would like to add, because I just faced this, that for the reinterpretation of a 2D array to a vector of static vectors to actually work in function accepting AbstractVectors, one need to add a vec
to the conversion:
julia> f(x::AbstractVector{<:AbstractVector}) = "this is a vector of vectors"
f (generic function with 1 method)
julia> x = rand(3,5)
3Ă5 Matrix{Float64}:
0.33453 0.209665 0.0140571 0.385981 0.0500048
0.922044 0.549503 0.826726 0.875412 0.200793
0.418103 0.830735 0.913105 0.619941 0.740944
julia> y = vec(reinterpret(SVector{3,Float64},x)) # works in f
5-element reshape(reinterpret(SVector{3, Float64}, ::Matrix{Float64}), 5) with eltype SVector{3, Float64}:
[0.3345302406715238, 0.9220439220026388, 0.4181031420691954]
[0.2096650742720747, 0.5495028980965941, 0.8307349539720923]
[0.014057112572854358, 0.8267260218514032, 0.9131049059956979]
[0.3859812308760291, 0.8754122419901476, 0.6199408169713525]
[0.050004821335951855, 0.2007929870776446, 0.7409443625689442]
julia> f(y)
"this is a vector of vectors"
julia> z = reinterpret(SVector{3,Float64},x) # does not work in f
1Ă5 reinterpret(SVector{3, Float64}, ::Matrix{Float64}):
[0.33453, 0.922044, 0.418103] [0.209665, 0.549503, 0.830735] ⌠[0.385981, 0.875412, 0.619941] [0.0500048, 0.200793, 0.740944]
julia> f(z)
ERROR: MethodError: no method matching f(::Base.ReinterpretArray{SVector{3, Float64}, 2, Float64, Matrix{Float64}, false})
Closest candidates are:
f(::AbstractVector{var"#s2"} where var"#s2"<:(AbstractVector{T} where T)) at REPL[24]:1
Stacktrace:
[1] top-level scope
@ REPL[29]:1
edit: but noticed now that that is not needed for the 1D array which is what the OP asked, because the array was already a vector and the reinterpreted array carries the type hierarchy of the original array (is that correct to say?)