From fe3a212b64fb137bdfb28ec246760e77be6e716b Mon Sep 17 00:00:00 2001 From: Patrick Belliveau Date: Wed, 5 Sep 2018 03:09:00 -0700 Subject: [PATCH] Fix dispatch of SparseMatrixCSC*Diagonal multiplication (#29045) * Fix type signature of mul! methods for multiplying SparseMatrixCSCs with Diagonal matrices. Type signature for diagonal matrices was wrong, causing fallback to generic Matmul. * Add SparseMatrixCSC*Diagonal dispatch test * Fix trailing whitespace * Don't copy with deepcopy (cherry picked from commit 8d993569b86608f9588458930a203fa4bc29ad50) --- stdlib/SparseArrays/src/linalg.jl | 4 ++-- stdlib/SparseArrays/test/sparse.jl | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/stdlib/SparseArrays/src/linalg.jl b/stdlib/SparseArrays/src/linalg.jl index 6e9a751dd4306..ad8ffb2b14f63 100644 --- a/stdlib/SparseArrays/src/linalg.jl +++ b/stdlib/SparseArrays/src/linalg.jl @@ -968,7 +968,7 @@ function copyinds!(C::SparseMatrixCSC, A::SparseMatrixCSC) end # multiply by diagonal matrix as vector -function mul!(C::SparseMatrixCSC, A::SparseMatrixCSC, D::Diagonal{<:Vector}) +function mul!(C::SparseMatrixCSC, A::SparseMatrixCSC, D::Diagonal{T, <:Vector}) where T m, n = size(A) b = D.diag (n==length(b) && size(A)==size(C)) || throw(DimensionMismatch()) @@ -982,7 +982,7 @@ function mul!(C::SparseMatrixCSC, A::SparseMatrixCSC, D::Diagonal{<:Vector}) C end -function mul!(C::SparseMatrixCSC, D::Diagonal{<:Vector}, A::SparseMatrixCSC) +function mul!(C::SparseMatrixCSC, D::Diagonal{T, <:Vector}, A::SparseMatrixCSC) where T m, n = size(A) b = D.diag (m==length(b) && size(A)==size(C)) || throw(DimensionMismatch()) diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index 0c17946d7a5d8..416cbffac27cf 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -8,6 +8,7 @@ using LinearAlgebra using Base.Printf: @printf using Random using Test: guardseed +using InteractiveUtils: @which @testset "issparse" begin @test issparse(sparse(fill(1,5,5))) @@ -2295,4 +2296,15 @@ end @test typeof(a) === typeof(na) end +#PR #29045 +@testset "Issue #28934" begin + A = sprand(5,5,0.5) + D = Diagonal(rand(5)) + C = copy(A) + m1 = @which mul!(C,A,D) + m2 = @which mul!(C,D,A) + @test m1.module == SparseArrays + @test m2.module == SparseArrays +end + end # module