Skip to content

Commit fa137df

Browse files
committed
Fix :slow matrix multiplication for previous Julia versions prior to 1.11
1 parent d9dcd1e commit fa137df

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/matmul.jl

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,33 @@ function Base.:*(A::AbstractMatrix, B::AbstractVector{<:RealOrComplexI})
121121
return LinearAlgebra.mul!(C, A, B, one(T), zero(T))
122122
end
123123

124-
LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat{<:RealOrComplexI}, α::Number, β::Number) =
125-
_mul!(matmul_mode(), C, A, B, α, β)
124+
function LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat{<:RealOrComplexI}, α::Number, β::Number)
125+
size(A, 2) == size(B, 1) || return throw(DimensionMismatch("The number of columns of A must match the number of rows of B."))
126+
return _mul!(matmul_mode(), C, A, B, α, β)
127+
end
126128

127-
LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix, B::AbstractVecOrMat{<:RealOrComplexI}, α::Number, β::Number) =
128-
_mul!(matmul_mode(), C, A, B, α, β)
129+
function LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix, B::AbstractVecOrMat{<:RealOrComplexI}, α::Number, β::Number)
130+
size(A, 2) == size(B, 1) || return throw(DimensionMismatch("The number of columns of A must match the number of rows of B."))
131+
return _mul!(matmul_mode(), C, A, B, α, β)
132+
end
129133

130-
LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat, α::Number, β::Number) =
131-
_mul!(matmul_mode(), C, A, B, α, β)
134+
function LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat, α::Number, β::Number)
135+
size(A, 2) == size(B, 1) || return throw(DimensionMismatch("The number of columns of A must match the number of rows of B."))
136+
return _mul!(matmul_mode(), C, A, B, α, β)
137+
end
132138

133-
_mul!(::MatMulMode{:slow}, C, A, B, α, β) = LinearAlgebra._mul!(C, A, B, α, β)
139+
function _mul!(::MatMulMode{:slow}, C, A::AbstractMatrix, B::AbstractVecOrMat, α, β)
140+
for j axes(B, 2)
141+
for i axes(A, 1)
142+
x = zero(eltype(C))
143+
for l axes(A, 2)
144+
@inbounds x += A[i,l] * B[l,j]
145+
end
146+
@inbounds C[i,j] = x * α + C[i,j] * β
147+
end
148+
end
149+
return C
150+
end
134151

135152
# fast matrix multiplication
136153
# Note: Rump's algorithm

0 commit comments

Comments
 (0)