From 52fa28801ff1ed48977ff14b0364dca22a9e2e2f Mon Sep 17 00:00:00 2001 From: Patrick Belliveau Date: Tue, 4 Sep 2018 12:48:37 -0700 Subject: [PATCH 1/4] Fix type signature of mul! methods for multiplying SparseMatrixCSCs with Diagonal matrices. Type signature for diagonal matrices was wrong, causing fallback to generic Matmul. --- stdlib/SparseArrays/src/linalg.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/SparseArrays/src/linalg.jl b/stdlib/SparseArrays/src/linalg.jl index 6e9a751dd4306..fbff4ee4a272e 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()) From 61af5c15c95273c9fb0d233a44efe89c749fb7b8 Mon Sep 17 00:00:00 2001 From: Patrick Belliveau Date: Tue, 4 Sep 2018 15:27:59 -0700 Subject: [PATCH 2/4] Add SparseMatrixCSC*Diagonal dispatch test --- stdlib/SparseArrays/test/sparse.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index 0c17946d7a5d8..0123ab226b0e9 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 = deepcopy(A) + m1 = @which mul!(C,A,D) + m2 = @which mul!(C,D,A) + @test m1.module == SparseArrays + @test m2.module == SparseArrays +end + end # module From 13105cd65aefc3de491aa44d70ecb80cf161b107 Mon Sep 17 00:00:00 2001 From: Patrick Belliveau Date: Tue, 4 Sep 2018 16:30:23 -0700 Subject: [PATCH 3/4] Fix trailing whitespace --- stdlib/SparseArrays/src/linalg.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/SparseArrays/src/linalg.jl b/stdlib/SparseArrays/src/linalg.jl index fbff4ee4a272e..ad8ffb2b14f63 100644 --- a/stdlib/SparseArrays/src/linalg.jl +++ b/stdlib/SparseArrays/src/linalg.jl @@ -982,7 +982,7 @@ function mul!(C::SparseMatrixCSC, A::SparseMatrixCSC, D::Diagonal{T, <:Vector}) C end -function mul!(C::SparseMatrixCSC, D::Diagonal{T, <:Vector}, A::SparseMatrixCSC) where T +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()) From 1fe0e11d1c79a1e72055b230f63d8d17e26f0c9a Mon Sep 17 00:00:00 2001 From: Andreas Noack Date: Wed, 5 Sep 2018 09:44:49 +0200 Subject: [PATCH 4/4] Don't copy with deepcopy --- stdlib/SparseArrays/test/sparse.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index 0123ab226b0e9..416cbffac27cf 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -2300,7 +2300,7 @@ end @testset "Issue #28934" begin A = sprand(5,5,0.5) D = Diagonal(rand(5)) - C = deepcopy(A) + C = copy(A) m1 = @which mul!(C,A,D) m2 = @which mul!(C,D,A) @test m1.module == SparseArrays