JuliaArrays / JuliaArrays/StaticArrays.jl
matmul fails with empty inner dimension
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
StaticArrays at v1.6.2 on Julia v1.9.1.
StaticArrays attempts to index empty arrays, resulting in an error, when the inner dimension of a SMatrix-SMatrix multiply is empty. I.e., for M x 0 times 0 x N multiply.
julia> using StaticArrays
julia> Z = zero(SMatrix{1,0,Float64,0})
1×0 SMatrix{1, 0, Float64, 0} with indices SOneTo(1)×SOneTo(0)
julia> Z'*Z
0×0 SMatrix{0, 0, Float64, 0} with indices SOneTo(0)×SOneTo(0)
julia> Z*Z'
ERROR: BoundsError: attempt to access Tuple{} at index [1]
Stacktrace:
[1] getindex(t::Tuple, i::Int64)
@ Base ./tuple.jl:29
[2] getindex
@ ~/.julia/packages/StaticArrays/9KYrc/src/SArray.jl:62 [inlined]
[3] macro expansion
@ ~/.julia/packages/StaticArrays/9KYrc/src/matrix_multiply.jl:217 [inlined]
[4] mul_loop(#unused#::Size{(1, 0)}, #unused#::Size{(0, 1)}, a::SMatrix{1, 0, Float64, 0}, b::SMatrix{0, 1, Float64, 0})
@ StaticArrays ~/.julia/packages/StaticArrays/9KYrc/src/matrix_multiply.jl:188
[5] macro expansion
@ ~/.julia/packages/StaticArrays/9KYrc/src/matrix_multiply.jl:139 [inlined]
[6] _mul(Sa::Size{(1, 0)}, Sb::Size{(0, 1)}, a::SMatrix{1, 0, Float64, 0}, b::SMatrix{0, 1, Float64, 0})
@ StaticArrays ~/.julia/packages/StaticArrays/9KYrc/src/matrix_multiply.jl:130
[7] *(A::SMatrix{1, 0, Float64, 0}, B::SMatrix{0, 1, Float64, 0})
@ StaticArrays ~/.julia/packages/StaticArrays/9KYrc/src/matrix_multiply.jl:11
[8] top-level scope
@ REPL[401]:1
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 in src/matrix_multiply.jl, especially the mul_loop and related code shown in the stack trace. Reproduce the M×0 times 0×N case from the issue, then verify that multiplication no longer indexes an empty tuple and returns the correctly shaped result without a BoundsError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100