Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check=false with newest KLU #478

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ HYPRE = "1.4.0"
InteractiveUtils = "1.10"
IterativeSolvers = "0.9.3"
JET = "0.8.28"
KLU = "0.5"
KLU = "0.6"
KernelAbstractions = "0.9.16"
Krylov = "0.9"
KrylovKit = "0.6"
Expand Down
33 changes: 16 additions & 17 deletions src/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -855,23 +855,17 @@
A = convert(AbstractMatrix, A)
if cache.isfresh
cacheval = @get_cacheval(cache, :KLUFactorization)
if cacheval !== nothing && alg.reuse_symbolic
if alg.reuse_symbolic
if alg.check_pattern && !(SparseArrays.decrement(SparseArrays.getcolptr(A)) ==
cacheval.colptr &&
SparseArrays.decrement(SparseArrays.getrowval(A)) == cacheval.rowval)
fact = KLU.klu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
nonzeros(A)))
else
# If we have a cacheval already, run umfpack_symbolic to ensure the symbolic factorization exists
# This won't recompute if it does.
KLU.klu_analyze!(cacheval)
copyto!(cacheval.nzval, nonzeros(A))
if cacheval._numeric === C_NULL # We MUST have a numeric factorization for reuse, unlike UMFPACK.
KLU.klu_factor!(cacheval)
end
fact = KLU.klu!(cacheval,
SparseArrays.decrement(SparseArrays.getrowval(A)) ==
cacheval.rowval)
fact = KLU.klu(
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
nonzeros(A)))
nonzeros(A)),
check = false)
else
fact = KLU.klu!(cacheval, nonzeros(A), check = false)
end
else
# New fact each time since the sparsity pattern can change
Expand All @@ -882,9 +876,14 @@
cache.cacheval = fact
cache.isfresh = false
end

y = ldiv!(cache.u, @get_cacheval(cache, :KLUFactorization), cache.b)
SciMLBase.build_linear_solution(alg, y, nothing, cache)
F = @get_cacheval(cache, :KLUFactorization)

Check warning on line 879 in src/factorization.jl

View check run for this annotation

Codecov / codecov/patch

src/factorization.jl#L879

Added line #L879 was not covered by tests
if F.common.status == KLU.KLU_OK
y = ldiv!(cache.u, F, cache.b)
SciMLBase.build_linear_solution(alg, y, nothing, cache)
else
SciMLBase.build_linear_solution(
alg, cache.u, nothing, cache; retcode = ReturnCode.Infeasible)
end
end

## CHOLMODFactorization
Expand Down
2 changes: 1 addition & 1 deletion test/default_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ A = spzeros(2, 2)
# test that solving a singular problem doesn't error
prob = LinearProblem(A, ones(2))
@test solve(prob, UMFPACKFactorization()).retcode == ReturnCode.Infeasible
@test_broken solve(prob, KLUFactorization()).retcode == ReturnCode.Infeasible
@test solve(prob, KLUFactorization()).retcode == ReturnCode.Infeasible

@test LinearSolve.defaultalg(sprand(10^4, 10^4, 1e-5) + I, zeros(1000)).alg ===
LinearSolve.DefaultAlgorithmChoice.KLUFactorization
Expand Down
Loading