# Elementwise mapping preserving static type

**URL:** <https://discourse.julialang.org/t/elementwise-mapping-preserving-static-type/30953>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 11, 2019, 1:59pm UTC](https://discourse.julialang.org/t/elementwise-mapping-preserving-static-type/30953 "2019-11-11T13:59:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 11, 2019, 1:59pm UTC](https://discourse.julialang.org/t/elementwise-mapping-preserving-static-type/30953/1 "2019-11-11T13:59:05Z")

</div>

I would like to map a vector of vectors (the latter static) elementwise, so that the static type is preserved.

```julia
# 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`).
