From b02562b8f3e1f12b68febc5c44e2212d25ede032 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Sat, 31 Dec 2022 09:09:13 -0500 Subject: [PATCH] Add missing specialization for CHOLMOD --- src/factorization.jl | 1 + src/factorization_sparse.jl | 3 ++- test/basictests.jl | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/factorization.jl b/src/factorization.jl index b1dd74570..bcbd276b0 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -1,4 +1,5 @@ _ldiv!(x, A, b) = ldiv!(x, A, b) + function _ldiv!(x::Vector, A::Factorization, b::Vector) # workaround https://github.com/JuliaLang/julia/issues/43507 copyto!(x, b) diff --git a/src/factorization_sparse.jl b/src/factorization_sparse.jl index e56b80f17..aea1b8862 100644 --- a/src/factorization_sparse.jl +++ b/src/factorization_sparse.jl @@ -2,7 +2,8 @@ # Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242 function _ldiv!(x::Vector, A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY, - SuiteSparse.SPQR.QRSparse}, b::Vector) + SuiteSparse.SPQR.QRSparse, + SuiteSparse.CHOLMOD.Factor}, b::Vector) x .= A \ b end diff --git a/test/basictests.jl b/test/basictests.jl index ca053e46d..f82606476 100644 --- a/test/basictests.jl +++ b/test/basictests.jl @@ -210,6 +210,23 @@ end end end + @testset "CHOLMOD" begin + # Create a posdef symmetric matrix + A = sprand(100,100,0.01); A = A + A' + 100*I; + + # rhs + b=rand(100); + + # Set the problem + prob = LinearProblem(A,b) + sol = solve(prob) + + # Enforce symmetry to use Cholesky, since A is symmetric and posdef + prob2 = LinearProblem(Symmetric(A),b) + sol2 = solve(prob2) + @test abs(norm(A * sol2.u .- b) - norm(A * sol.u .- b)) < 1e-12 + end + @testset "Preconditioners" begin @testset "Vector Diagonal Preconditioner" begin s = rand(n)