Skip to content

Commit 78ac3f8

Browse files
committed
Improve consistency of mul! with LinearAlgebra
1 parent 8752dcb commit 78ac3f8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/matmul.jl

+18-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function Base.inv(A::Matrix{<:RealOrComplexI})
5454
F = A * approx_A⁻¹ - interval(LinearAlgebra.I)
5555
Y = LinearAlgebra.opnorm(approx_A⁻¹ * F, Inf)
5656
Z₁ = LinearAlgebra.opnorm(F, Inf)
57-
if isbounded(Y) & strictprecedes(Z₁, one(one(Z₁)))
57+
if isbounded(Y) & strictprecedes(Z₁, one(Z₁))
5858
A⁻¹ = interval.(approx_A⁻¹, inf(interval(mag(Y)) / (one(Z₁) - interval(mag(Z₁)))); format = :midpoint)
5959
else
6060
A⁻¹ = fill(nai(eltype(approx_A⁻¹)), size(A))
@@ -195,9 +195,23 @@ for T ∈ (:AbstractVector, :AbstractMatrix) # needed to resolve method ambiguit
195195
end
196196

197197
function _mul!(::MatMulMode{:slow}, C, A::AbstractMatrix, B::AbstractVecOrMat, α, β)
198-
AB = Matrix{eltype(C)}(undef, size(A, 1), size(B, 2))
199-
_matmul_rec!(AB, A, B)
200-
C .= AB .* α .+ C .* β
198+
if iszero(α)
199+
if iszero(β)
200+
C .= zero(eltype(C))
201+
elseif !isone(β)
202+
C .*= β
203+
end
204+
else
205+
if iszero(β)
206+
_matmul_rec!(C, A, B)
207+
C .*= α
208+
else
209+
AB = Matrix{eltype(C)}(undef, size(A, 1), size(B, 2))
210+
C .= AB .* α .+ C .* β
211+
end
212+
end
213+
t = all(isguaranteed, A) & all(isguaranteed, B) & isguaranteed(α) & isguaranteed(β)
214+
_ensure_ng_flag!(C, t)
201215
return C
202216
end
203217

0 commit comments

Comments
 (0)