Open
Description
Originally spotted in the wild on discourse https://discourse.julialang.org/t/grassmann-jl-a-b-3x-faster-than-julias-staticarrays-jl/41451/1
The former of these two cases you'd naturally expect to work, but it allocates an array of pointers rather than allocating values inline:
julia> typeof(rand(SMatrix{5,5},10000))
Array{SArray{Tuple{5,5},T,2,L} where L where T,1}
julia> typeof(rand(SMatrix{5,5,Float64,25},10000))
Array{SArray{Tuple{5,5},Float64,2,25},1}
I guess we can try to overload rand
for a set of our abstract types in an attempt to patch this up. The Random
stdlib doesn't provide a way to make the output array concrete, it appears we dispatch to the following
rand(r::AbstractRNG, ::Type{X}, dims::Dims) where {X} = rand!(r, Array{X}(undef, dims), X)