Skip to content

Commit 64200a1

Browse files
Merge pull request #246 from SciML/cholmod
Add missing specialization for CHOLMOD
2 parents 93762b9 + 22511ca commit 64200a1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/factorization.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_ldiv!(x, A, b) = ldiv!(x, A, b)
2+
23
function _ldiv!(x::Vector, A::Factorization, b::Vector)
34
# workaround https://github.com/JuliaLang/julia/issues/43507
45
copyto!(x, b)

src/factorization_sparse.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Missing ldiv! definitions: https://github.com/JuliaSparse/SparseArrays.jl/issues/242
33
function _ldiv!(x::Vector,
44
A::Union{SparseArrays.QR, LinearAlgebra.QRCompactWY,
5-
SuiteSparse.SPQR.QRSparse}, b::Vector)
5+
SuiteSparse.SPQR.QRSparse,
6+
SuiteSparse.CHOLMOD.Factor}, b::Vector)
67
x .= A \ b
78
end
89

test/basictests.jl

+18
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ end
210210
end
211211
end
212212

213+
@testset "CHOLMOD" begin
214+
# Create a posdef symmetric matrix
215+
A = sprand(100, 100, 0.01)
216+
A = A + A' + 100 * I
217+
218+
# rhs
219+
b = rand(100)
220+
221+
# Set the problem
222+
prob = LinearProblem(A, b)
223+
sol = solve(prob)
224+
225+
# Enforce symmetry to use Cholesky, since A is symmetric and posdef
226+
prob2 = LinearProblem(Symmetric(A), b)
227+
sol2 = solve(prob2)
228+
@test abs(norm(A * sol2.u .- b) - norm(A * sol.u .- b)) < 1e-12
229+
end
230+
213231
@testset "Preconditioners" begin
214232
@testset "Vector Diagonal Preconditioner" begin
215233
s = rand(n)

0 commit comments

Comments
 (0)