Skip to content

Commit acc046f

Browse files
committed
Diagonal-sandwiched triple product for SparseMatrixCSC
1 parent 313a04f commit acc046f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/linalg.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ const SparseOrTri{Tv,Ti} = Union{SparseMatrixCSCUnion{Tv,Ti},SparseTriangular{Tv
205205
*(A::AdjOrTrans{<:Any,<:AbstractSparseMatrixCSC}, B::SparseOrTri) = spmatmul(copy(A), B)
206206
*(A::AdjOrTrans{<:Any,<:AbstractSparseMatrixCSC}, B::AdjOrTrans{<:Any,<:AbstractSparseMatrixCSC}) = spmatmul(copy(A), copy(B))
207207

208+
(*)(Da::Diagonal, A::Union{SparseMatrixCSCUnion, AdjOrTrans{<:Any,<:AbstractSparseMatrixCSC}}, Db::Diagonal) =
209+
Da * (A * Db)
210+
208211
# Gustavson's matrix multiplication algorithm revisited.
209212
# The result rowval vector is already sorted by construction.
210213
# The auxiliary Vector{Ti} xb is replaced by a Vector{Bool} of same length.

test/linalg.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,4 +912,20 @@ end
912912
@test sparse(3I, 4, 5) == sparse(1:4, 1:4, 3, 4, 5)
913913
@test sparse(3I, 5, 4) == sparse(1:4, 1:4, 3, 5, 4)
914914
end
915+
916+
@testset "diagonal-sandwiched triple multiplication" begin
917+
D = Diagonal(1:4)
918+
S = sprand(Int, 4, 4, 0.2)
919+
A = Array(S)
920+
C = D * S * D
921+
@test C isa SparseMatrixCSC
922+
@test C D * A * D
923+
C = D * S' * D
924+
@test C isa SparseMatrixCSC
925+
@test C D * A' * D
926+
C = D * view(S, :, :) * D
927+
@test C isa SparseMatrixCSC
928+
@test C D * A * D
929+
end
930+
915931
end

0 commit comments

Comments
 (0)