From 54dd82a04c93e4c6aadcdc346c8093e33c6e48a7 Mon Sep 17 00:00:00 2001 From: Chi Po Choi Date: Tue, 7 Aug 2018 02:05:00 -0700 Subject: [PATCH 1/2] fix \ SparseVector --- stdlib/SuiteSparse/src/cholmod.jl | 2 +- stdlib/SuiteSparse/test/cholmod.jl | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/stdlib/SuiteSparse/src/cholmod.jl b/stdlib/SuiteSparse/src/cholmod.jl index b0a82eaca18d6..5c8f6b40c8649 100644 --- a/stdlib/SuiteSparse/src/cholmod.jl +++ b/stdlib/SuiteSparse/src/cholmod.jl @@ -1714,7 +1714,7 @@ end (\)(L::Factor{T}, B::StridedMatrix) where {T<:VTypes} = Matrix(L\Dense{T}(B)) (\)(L::Factor, B::Sparse) = spsolve(CHOLMOD_A, L, B) # When right hand side is sparse, we have to ensure that the rhs is not marked as symmetric. -(\)(L::Factor, B::SparseVecOrMat) = sparse(spsolve(CHOLMOD_A, L, Sparse(B, 0))) +(\)(L::Factor, B::SparseVecOrMat) = sparse(spsolve(CHOLMOD_A, L, Sparse(B))) \(adjL::Adjoint{<:Any,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B)) \(adjL::Adjoint{<:Any,<:Factor}, B::VecOrMat) = (L = adjL.parent; Matrix(solve(CHOLMOD_A, L, Dense(B)))) diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index aaa9e49266ca5..c34268c5d0ba7 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -686,6 +686,15 @@ end @test A\view(Matrix(1.0I, 5, 5), :, :) ≈ Matrix(Diagonal(x)) end +@testset "Test \\ for Factor and SparseVecOrMat" begin + sparseI = sparse(1.0I, 100, 100) + sparseb = sprandn(100, 0.5) + sparseB = sprandn(100, 100, 0.5) + chI = cholesky(sparseI) + @test chI \ sparseb ≈ sparseb + @test chI \ sparseB ≈ sparseB +end + @testset "Real factorization and complex rhs" begin A = sprandn(5, 5, 0.4) |> t -> t't + I B = complex.(randn(5, 2), randn(5, 2)) From 3015097d56d97d3a3b23cd21da095713c72def1f Mon Sep 17 00:00:00 2001 From: Chi Po Choi Date: Wed, 8 Aug 2018 06:47:35 -0700 Subject: [PATCH 2/2] split (\) for sparsevector; test for Factor and Symmetric Sparse Matrix --- stdlib/SuiteSparse/src/cholmod.jl | 3 ++- stdlib/SuiteSparse/test/cholmod.jl | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/SuiteSparse/src/cholmod.jl b/stdlib/SuiteSparse/src/cholmod.jl index 5c8f6b40c8649..96e0d57a3c568 100644 --- a/stdlib/SuiteSparse/src/cholmod.jl +++ b/stdlib/SuiteSparse/src/cholmod.jl @@ -1714,7 +1714,8 @@ end (\)(L::Factor{T}, B::StridedMatrix) where {T<:VTypes} = Matrix(L\Dense{T}(B)) (\)(L::Factor, B::Sparse) = spsolve(CHOLMOD_A, L, B) # When right hand side is sparse, we have to ensure that the rhs is not marked as symmetric. -(\)(L::Factor, B::SparseVecOrMat) = sparse(spsolve(CHOLMOD_A, L, Sparse(B))) +(\)(L::Factor, B::SparseMatrixCSC) = sparse(spsolve(CHOLMOD_A, L, Sparse(B, 0))) +(\)(L::Factor, B::SparseVector) = sparse(spsolve(CHOLMOD_A, L, Sparse(B))) \(adjL::Adjoint{<:Any,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B)) \(adjL::Adjoint{<:Any,<:Factor}, B::VecOrMat) = (L = adjL.parent; Matrix(solve(CHOLMOD_A, L, Dense(B)))) diff --git a/stdlib/SuiteSparse/test/cholmod.jl b/stdlib/SuiteSparse/test/cholmod.jl index c34268c5d0ba7..0735214711a60 100644 --- a/stdlib/SuiteSparse/test/cholmod.jl +++ b/stdlib/SuiteSparse/test/cholmod.jl @@ -693,6 +693,7 @@ end chI = cholesky(sparseI) @test chI \ sparseb ≈ sparseb @test chI \ sparseB ≈ sparseB + @test chI \ sparseI ≈ sparseI end @testset "Real factorization and complex rhs" begin