Skip to content

Commit

Permalink
Merge pull request #468 from SciML/krylov
Browse files Browse the repository at this point in the history
Avoid constructing any Krylov cache with default dense
  • Loading branch information
ChrisRackauckas authored Feb 12, 2024
2 parents fa5278e + 91fe4d4 commit 31784ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LinearSolve"
uuid = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
authors = ["SciML"]
version = "2.23.0"
version = "2.23.1"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
6 changes: 3 additions & 3 deletions src/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function defaultalg(A::Nothing, b::GPUArraysCore.AnyGPUArray, assump::OperatorAs
end

# Ambiguity handling
function defaultalg(A::GPUArraysCore.AnyGPUArray, b::GPUArraysCore.AbstractGPUArray,
function defaultalg(A::GPUArraysCore.AnyGPUArray, b::GPUArraysCore.AnyGPUArray,
assump::OperatorAssumptions{Bool})
if assump.condition === OperatorCondition.IllConditioned || !assump.issq
DefaultLinearSolver(DefaultAlgorithmChoice.QRFactorization)
Expand Down Expand Up @@ -152,7 +152,7 @@ function defaultalg(A, b, assump::OperatorAssumptions{Bool})
# Special case on Arrays: avoid BLAS for RecursiveFactorization.jl when
# it makes sense according to the benchmarks, which is dependent on
# whether MKL or OpenBLAS is being used
if (A === nothing && !(b isa GPUArraysCore.AbstractGPUArray)) || A isa Matrix
if (A === nothing && !(b isa GPUArraysCore.AnyGPUArray)) || A isa Matrix
if (A === nothing ||
eltype(A) <: BLASELTYPES) &&
ArrayInterface.can_setindex(b) &&
Expand Down Expand Up @@ -296,7 +296,7 @@ cache.cacheval = NamedTuple(LUFactorization = cache of LUFactorization, ...)
abstol, reltol,
verbose::Bool, assump::OperatorAssumptions)
caches = map(first.(EnumX.symbol_map(DefaultAlgorithmChoice.T))) do alg
if alg === :KrylovJL_GMRES
if alg === :KrylovJL_GMRES || alg === :KrylovJL_CRAIGMR || alg === :KrylovJL_LSMR
quote
if A isa Matrix || A isa SparseMatrixCSC
nothing
Expand Down
12 changes: 6 additions & 6 deletions test/default_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ b = rand(m)
x = rand(n)
f = (du, u, p, t) -> mul!(du, A, u)
fadj = (du, u, p, t) -> mul!(du, A', u)
fo = FunctionOperator(f, x, b; op_adjoint = fadj)
prob = LinearProblem(fo, b)
funcop = FunctionOperator(f, x, b; op_adjoint = fadj)
prob = LinearProblem(funcop, b)
sol1 = solve(prob)
sol2 = solve(prob, LinearSolve.KrylovJL_GMRES())
@test sol1.u == sol2.u
Expand All @@ -89,8 +89,8 @@ b = rand(m)
x = rand(n)
f = (du, u, p, t) -> mul!(du, A, u)
fadj = (du, u, p, t) -> mul!(du, A', u)
fo = FunctionOperator(f, x, b; op_adjoint = fadj)
prob = LinearProblem(fo, b)
funcop = FunctionOperator(f, x, b; op_adjoint = fadj)
prob = LinearProblem(funcop, b)
sol1 = solve(prob)
sol2 = solve(prob, LinearSolve.KrylovJL_LSMR())
@test sol1.u == sol2.u
Expand All @@ -101,8 +101,8 @@ b = rand(m)
x = rand(n)
f = (du, u, p, t) -> mul!(du, A, u)
fadj = (du, u, p, t) -> mul!(du, A', u)
fo = FunctionOperator(f, x, b; op_adjoint = fadj)
prob = LinearProblem(fo, b)
funcop = FunctionOperator(f, x, b; op_adjoint = fadj)
prob = LinearProblem(funcop, b)
sol1 = solve(prob)
sol2 = solve(prob, LinearSolve.KrylovJL_CRAIGMR())
@test sol1.u == sol2.u

0 comments on commit 31784ff

Please sign in to comment.