Skip to content

Commit 51b3227

Browse files
tkfandreasnoack
authored andcommitted
Dispatch more cases to BLAS.gemm! (#33229)
* Dispatch more cases to BLAS.gemm! * Use α and β instead of alpha′ and beta′
1 parent b439bfb commit 51b3227

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

stdlib/LinearAlgebra/src/matmul.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,23 @@ function (*)(A::AbstractMatrix, B::AbstractMatrix)
152152
TS = promote_op(matprod, eltype(A), eltype(B))
153153
mul!(similar(B, TS, (size(A,1), size(B,2))), A, B)
154154
end
155-
@inline mul!(C::StridedMatrix{T}, A::StridedVecOrMat{T}, B::StridedVecOrMat{T},
156-
alpha::Union{T, Bool}, beta::Union{T, Bool}) where {T<:BlasFloat} =
157-
gemm_wrapper!(C, 'N', 'N', A, B, MulAddMul(alpha, beta))
155+
156+
@inline function mul!(C::StridedMatrix{T}, A::StridedVecOrMat{T}, B::StridedVecOrMat{T},
157+
α::Number, β::Number) where {T<:BlasFloat}
158+
alpha, beta = promote(α, β, zero(T))
159+
if alpha isa T && beta isa T
160+
return gemm_wrapper!(C, 'N', 'N', A, B, MulAddMul(alpha, beta))
161+
else
162+
return generic_matmatmul!(C, 'N', 'N', A, B, MulAddMul(α, β))
163+
end
164+
end
165+
158166
# Complex Matrix times real matrix: We use that it is generally faster to reinterpret the
159167
# first matrix as a real matrix and carry out real matrix matrix multiply
160168
for elty in (Float32,Float64)
161169
@eval begin
162170
@inline function mul!(C::StridedMatrix{Complex{$elty}}, A::StridedVecOrMat{Complex{$elty}}, B::StridedVecOrMat{$elty},
163-
alpha::Union{$elty, Bool}, beta::Union{$elty, Bool})
171+
alpha::Real, beta::Real)
164172
Afl = reinterpret($elty, A)
165173
Cfl = reinterpret($elty, C)
166174
mul!(Cfl, Afl, B, alpha, beta)

stdlib/LinearAlgebra/test/matmul.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ end
586586
A = rand(n, n)
587587
B = rand(n, n)
588588
C = zeros(n, n)
589-
mul!(C, A, B, -1, 0)
589+
mul!(C, A, B, -1 + 0im, 0)
590590
D = -A * B
591591
@test D C
592592

0 commit comments

Comments
 (0)