JuliaArrays / JuliaArrays/StaticArrays.jl
Performance of mixed-type (matrix-) multiplication
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
Hi,
I noticed that mixed-type multiplication (e.g. *(::SMatrix, ::Matrix)) is slow. I searched the issues but didn't find one that mentions this.
For example:
julia> SA = @SMatrix randn(3,3);
julia> A = Matrix(SA);
julia> B = randn(3, 1_000);
julia> @btime $SA * $B;
14.455 μs (5 allocations: 54.23 KiB)
julia> @btime $A * $B;
2.121 μs (2 allocations: 23.48 KiB)
This is, because *(::SMatrix, ::Matrix) doesn't hit BLAS and goes via LinearAlgebra.generic_matmul!().
This case doesn't seem to be covered by the benchmarks (unless I missed it), so I'm wondering whether it would it be in scope (of this package) to address this.
If not, I think it should be mentioned somewhere though.
Note that converting to standard Array followed by Matrix-Matrix multiplication is much faster than the SMatrix-Matrix multiplication (because it hits BLAS), and allocates less:
julia> @btime Matrix($SA) * $B;
2.062 μs (3 allocations: 23.61 KiB)
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 reported benchmarks for SMatrix–Matrix multiplication and compare them with Matrix–Matrix multiplication. Read LinearAlgebra.generic_matmul! and the package's existing multiplication benchmarks, then determine whether the intended result is faster mixed-type multiplication or documentation of the limitation. Done means the chosen direction is covered by a benchmark and its performance or documentation is verified.
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
- Needs clarification
- Newbie friendliness
- 35/100