JuliaArrays / JuliaArrays/StaticArrays.jl
cat SMatrices returns Arrays
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
Hi!
I was trying to compute a static block matrix using static sub matrices and saw that the result is not a StaticArray.
julia> m1 = @SMatrix rand(2,3);
julia> m2 = @SMatrix rand(2,3);
julia> cat(m1, m2, dims = (1, 2))
4×6 Array{Float64,2}:
0.611586 0.396562 0.30208 0.0 0.0 0.0
0.574913 0.909981 0.0731041 0.0 0.0 0.0
0.0 0.0 0.0 0.495477 0.512808 0.232148
0.0 0.0 0.0 0.880756 0.449617 0.305318
Also, trying simpler examples yield to Arrays as well:
julia> cat(m1, m2, dims = 1)
4×3 Array{Float64,2}:
0.611586 0.396562 0.30208
0.574913 0.909981 0.0731041
0.495477 0.512808 0.232148
0.880756 0.449617 0.305318
julia> cat(m1, m2, dims = 2)
2×6 Array{Float64,2}:
0.611586 0.396562 0.30208 0.495477 0.512808 0.232148
0.574913 0.909981 0.0731041 0.880756 0.449617 0.305318
The result is different if we just use hcat or vcat.
julia> hcat(m1, m2)
2×6 SArray{Tuple{2,6},Float64,2,12} with indices SOneTo(2)×SOneTo(6):
0.611586 0.396562 0.30208 0.495477 0.512808 0.232148
0.574913 0.909981 0.0731041 0.880756 0.449617 0.305318
julia> vcat(m1, m2)
4×3 SArray{Tuple{4,3},Float64,2,12} with indices SOneTo(4)×SOneTo(3):
0.611586 0.396562 0.30208
0.574913 0.909981 0.0731041
0.495477 0.512808 0.232148
0.880756 0.449617 0.305318
However, I still need to find a method that computes a block matrix using submatrices.
I have a function that computes several static matrices in the body that need to be concatenated as a block static matrix (which is then returned). Should I create static sub-matrices filled with zeros and use hcat and vcat then?
Also, in the slack channel, @mcabbott suggested using generated functions:
I guess this might end up more efficient. I think it ought to be possible to re-use cat by making arrays of expressions like :(args[n][i,j]) and cat-ing those… The one thing I contributed to StaticArrays is like that: https://github.com/JuliaArrays/StaticArrays.jl/blob/0a7f3f7eae1fab11a50699fe33332d5099534be9/src/abstractarray.jl#L218
Please, notice that the sub matrices might have different sizes as well.
Any ideas?
Thanks!
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
Reproduce the cat, hcat, and vcat examples with static matrices, then inspect src/abstractarray.jl at the referenced concatenation implementation. Determine how concatenation should preserve static results, including inputs with different sizes, and add tests showing the expected StaticArray output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100