StaticArrays.jl icon indicating copy to clipboard operation
StaticArrays.jl copied to clipboard

matmul fails with empty inner dimension

Open mikmoore opened this issue 2 years ago • 0 comments

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

mikmoore avatar Sep 25 '23 17:09 mikmoore