Skip to content

Commit

Permalink
Fix UMFPACK to use check=false
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed Feb 23, 2024
1 parent e23f5c7 commit 0f63778
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -780,21 +780,26 @@ function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs.
SparseArrays.decrement(SparseArrays.getrowval(A)) ==
cacheval.rowval)
fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
nonzeros(A)))
nonzeros(A)), check=false)
else
fact = lu!(cacheval,
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
nonzeros(A)))
nonzeros(A)), check=false)
end
else
fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)))
fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)), check=false)

Check warning on line 790 in src/factorization.jl

View check run for this annotation

Codecov / codecov/patch

src/factorization.jl#L790

Added line #L790 was not covered by tests
end
cache.cacheval = fact
cache.isfresh = false
end

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

Check warning on line 796 in src/factorization.jl

View check run for this annotation

Codecov / codecov/patch

src/factorization.jl#L796

Added line #L796 was not covered by tests
if F.status == SparseArrays.UMFPACK.UMFPACK_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)

Check warning on line 801 in src/factorization.jl

View check run for this annotation

Codecov / codecov/patch

src/factorization.jl#L801

Added line #L801 was not covered by tests
end
end

"""
Expand Down Expand Up @@ -840,10 +845,10 @@ function init_cacheval(alg::KLUFactorization, A::AbstractSparseArray, b, u, Pl,
nonzeros(A)))
end

# TODO: guard this against errors
function SciMLBase.solve!(cache::LinearCache, alg::KLUFactorization; kwargs...)
A = cache.A
A = convert(AbstractMatrix, A)

if cache.isfresh
cacheval = @get_cacheval(cache, :KLUFactorization)
if cacheval !== nothing && alg.reuse_symbolic
Expand Down
7 changes: 7 additions & 0 deletions test/default_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ solve(prob)
LinearSolve.OperatorAssumptions(false)).alg ===
LinearSolve.DefaultAlgorithmChoice.QRFactorization


A = spzeros(100, 100)
A[1,1]=1
# test that solving a singluar problem doesn't error

Check warning on line 41 in test/default_algs.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"singluar" should be "singular".
prob = LinearProblem(A, ones(100))
solve(prob)

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

0 comments on commit 0f63778

Please sign in to comment.