Skip to content

Commit

Permalink
Merge pull request #246 from SciML/cholmod
Browse files Browse the repository at this point in the history
Add missing specialization for CHOLMOD
  • Loading branch information
ChrisRackauckas authored Dec 31, 2022
2 parents 93762b9 + 22511ca commit 64200a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/factorization.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/factorization_sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ 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)
Expand Down

0 comments on commit 64200a1

Please sign in to comment.