Skip to content

Commit

Permalink
Add test for sparse cholesky
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 15, 2023
1 parent a538b3a commit f28b102
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 245 in src/factorization.jl

View check run for this annotation

Codecov / codecov/patch

src/factorization.jl#L245

Added line #L245 was not covered by tests
elseif alg.pivot === Val(false) || alg.pivot === NoPivot()
fact = cholesky!(A, alg.pivot; check = false)
Expand All @@ -270,7 +268,6 @@ function init_cacheval(alg::CholeskyFactorization, A, b, u, Pl, Pr,
maxiters::Int, abstol, reltol, verbose::Bool,
assumptions::OperatorAssumptions)
ArrayInterface.cholesky_instance(convert(AbstractMatrix, A), alg.pivot)
# cholesky!(similar(A, 1, 1); check=false)
end

@static if VERSION < v"1.8beta"
Expand Down
11 changes: 8 additions & 3 deletions test/sparse_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit f28b102

Please sign in to comment.