From 0257ec37030bffba7fb58ceb1f42ef53afcde9ea Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Tue, 23 Apr 2024 16:03:01 -0400 Subject: [PATCH 1/2] Handle LU failure and Symmetric QR --- Project.toml | 2 +- src/factorization.jl | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 33cabb12a..d0d91d5ab 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LinearSolve" uuid = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" authors = ["SciML"] -version = "2.29.0" +version = "2.29.1" [deps] ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" diff --git a/src/factorization.jl b/src/factorization.jl index 6e7284887..f4e0d4d78 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -93,6 +93,12 @@ function SciMLBase.solve!(cache::LinearCache, alg::LUFactorization; kwargs...) fact = lu(A, check = false) end cache.cacheval = fact + + if !LinearAlgebra.issuccess(fact) + return SciMLBase.build_linear_solution( + alg, cache.u, nothing, cache; retcode = ReturnCode.Failure) + end + cache.isfresh = false end @@ -187,7 +193,11 @@ function do_factorization(alg::QRFactorization, A, b, u) A = convert(AbstractMatrix, A) if ArrayInterface.can_setindex(typeof(A)) if alg.inplace && !(A isa SparseMatrixCSC) && !(A isa GPUArraysCore.AnyGPUArray) - fact = qr!(A, alg.pivot) + if A isa Symmetric + fact = qr(A, alg.pivot) + else + fact = qr!(A, alg.pivot) + end else fact = qr(A) # CUDA.jl does not allow other args! end @@ -203,6 +213,12 @@ function init_cacheval(alg::QRFactorization, A, b, u, Pl, Pr, ArrayInterface.qr_instance(convert(AbstractMatrix, A), alg.pivot) end +function init_cacheval(alg::QRFactorization, A::Symmetric, b, u, Pl, Pr, + maxiters::Int, abstol, reltol, verbose::Bool, + assumptions::OperatorAssumptions) + return qr(convert(AbstractMatrix, A), alg.pivot) +end + const PREALLOCATED_QR_ColumnNorm = ArrayInterface.qr_instance(rand(1, 1), ColumnNorm()) function init_cacheval(alg::QRFactorization{ColumnNorm}, A::Matrix{Float64}, b, u, Pl, Pr, From de292579bc5c09ed9bcde07f50f14b1c49bb249e Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Thu, 25 Apr 2024 17:22:24 -0400 Subject: [PATCH 2/2] Add to RFLU --- src/factorization.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/factorization.jl b/src/factorization.jl index f4e0d4d78..a32f3ede3 100644 --- a/src/factorization.jl +++ b/src/factorization.jl @@ -1039,6 +1039,12 @@ function SciMLBase.solve!(cache::LinearCache, alg::RFLUFactorization{P, T}; end fact = RecursiveFactorization.lu!(A, ipiv, Val(P), Val(T), check = false) cache.cacheval = (fact, ipiv) + + if !LinearAlgebra.issuccess(fact) + return SciMLBase.build_linear_solution( + alg, cache.u, nothing, cache; retcode = ReturnCode.Failure) + end + cache.isfresh = false end y = ldiv!(cache.u, @get_cacheval(cache, :RFLUFactorization)[1], cache.b)