JuliaArrays / JuliaArrays/StaticArrays.jl
`rand(SMatrix{N,N}, M)` produces array of abstractly typed values
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
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)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two rand(SMatrix{5,5}, 10000) cases from the issue and inspect the shown Random dispatch through rand! and Array{X}(undef, dims). Determine how StaticArrays' abstract types should produce a concrete result array, then verify that the result stores values inline rather than abstractly typed elements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100