Skip to content

Commit 3d12196

Browse files
committed
Fix mul! for HermOrSym sparse matrices (#689)
1 parent 2376bf8 commit 3d12196

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/SparseArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Base: Matrix, Vector
1919
import LinearAlgebra: mul!, ldiv!, rdiv!, cholesky, adjoint!, diag, eigen, dot,
2020
issymmetric, istril, istriu, lu, tr, transpose!, tril!, triu!, isbanded,
2121
cond, diagm, factorize, ishermitian, norm, opnorm, lmul!, rmul!, tril, triu,
22-
matprod_dest, generic_matvecmul!, generic_matmatmul!, copytrito!
22+
matprod_dest, generic_matvecmul!, generic_matmatmul!, generic_matmatmul_wrapper!, copytrito!
2323

2424
import Base: adjoint, argmin, argmax, Array, broadcast, circshift!, complex, Complex,
2525
conj, conj!, convert, copy, copy!, copyto!, count, diff, findall, findmax, findmin,

src/linalg.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function _At_or_Ac_mul_B!(tfun::Function, C, A, B, α, β)
117117
C
118118
end
119119

120-
Base.@constprop :aggressive function generic_matmatmul!(C::StridedMatrix, tA, tB, A::DenseMatrixUnion, B::SparseMatrixCSCUnion2, alpha::Number, beta::Number)
120+
Base.@constprop :aggressive function generic_matmatmul_wrapper!(C::StridedMatrix, tA, tB, A::DenseMatrixUnion, B::SparseMatrixCSCUnion2, alpha::Number, beta::Number, ::LinearAlgebra.BlasFlag.SyrkHerkGemm)
121121
transA = tA == 'N' ? identity : tA == 'T' ? transpose : adjoint
122122
if tB == 'N'
123123
_spmul!(C, transA(A), B, alpha, beta)
@@ -128,6 +128,9 @@ Base.@constprop :aggressive function generic_matmatmul!(C::StridedMatrix, tA, tB
128128
end
129129
return C
130130
end
131+
Base.@constprop :aggressive generic_matmatmul_wrapper!(C::StridedMatrix, tA, tB, A::DenseMatrixUnion, B::SparseMatrixCSCUnion2, alpha::Number, beta::Number, @nospecialize(val)) =
132+
LinearAlgebra._generic_matmatmul!(C, wrap(A, tA), wrap(B, tB), alpha, beta)
133+
131134
function _spmul!(C::StridedMatrix, X::DenseMatrixUnion, A::SparseMatrixCSCUnion2, α::Number, β::Number)
132135
mX, nX = size(X)
133136
nX == size(A, 1) ||

test/linalg.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ end
236236
end
237237
end
238238

239+
@testset "Dense times symmetric/Hermitian sparse matrix multiplication" begin
240+
A = [1 3; 2 4]
241+
As = sparse(A)
242+
B = [1 1; 1 1]
243+
@test mul!(copy(B), B, Hermitian(A), true, true) == mul!(copy(B), B, Hermitian(As), true, true)
244+
end
245+
239246
@testset "in-place sparse-sparse mul!" begin
240247
for n in (20, 30)
241248
sA = sprandn(ComplexF64, n, n, 0.1); A = Array(sA)

0 commit comments

Comments
 (0)