I would like to map a vector of vectors (the latter static) elementwise, so that the static type is preserved.
# setup
using StaticArrays, Test
bs = [SVector{4}(randn(4)...) for _ in 1:9] # 9 is "large" in real life
A = randn(9, 9)
# one solution
function f(A, bs)
X = A \ mapreduce(permutedims, vcat, bs)
SVector{length(first(bs))}(collect(eachcol(X)))
end
xs = @inferred f(A, bs) # OK
typeof(xs) # SArray{Tuple{4},Array{Float64,1},1,4}
I have solved my immediate problem (a hot loop using these arrays experienced a 30x speedup, yay!), but I am curious if there is an idiomatic solution, one that ideally propagates the static shape information to xs
when applicable (and also works when bs
contains plain vanilla Vectors
).