From 5cec4138706a25945387ce7addad7758f387c060 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Sun, 15 Oct 2023 13:16:08 -0400 Subject: [PATCH] Add test for sparse cholesky --- src/factorization.jl | 2 -- test/sparse_vector.jl | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/factorization.jl b/src/factorization.jl index 7e3b6d63c..038ad11ee 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -242,8 +242,6 @@ end function do_factorization(alg::CholeskyFactorization, A, b, u) A = convert(AbstractMatrix, A) if A isa SparseMatrixCSC - # fact = cholesky!(A; shift = alg.shift, check = false, perm = alg.perm) - # fact = @time cholesky!(A; check = false) fact = cholesky(A; shift = alg.shift, check = false, perm = alg.perm) elseif alg.pivot === Val(false) || alg.pivot === NoPivot() fact = cholesky!(A, alg.pivot; check = false) diff --git a/test/sparse_vector.jl b/test/sparse_vector.jl index d5c9bbda9..145745528 100644 --- a/test/sparse_vector.jl +++ b/test/sparse_vector.jl @@ -2,7 +2,7 @@ using SparseArrays using LinearSolve using LinearAlgebra -# Constructing sparse array +# Constructing sparse array function hess_sparse(x::Vector{T}) where {T} return [ -sin(x[1] + x[2]) + 1, @@ -37,7 +37,12 @@ n = length(x0) hess_mat = sparse(rowval, colval, hess_sparse(x0), n, n) grad_vec = sparsevec(gradinds, grad_sparse(x0), n) -# # Converting grad_vec to dense succeeds in solving +# Converting grad_vec to dense succeeds in solving prob = LinearProblem(hess_mat, grad_vec) -linsolve = init(prob) +linsolve = init(prob); @test solve!(linsolve).u ≈ hess_mat \ Array(grad_vec) + +H = hess_mat' * hess_mat +prob = LinearProblem(H, hess_mat' * grad_vec) +linsolve = init(prob, CholeskyFactorization()) +@test solve!(linsolve).u ≈ H \ Array(hess_mat' * grad_vec)