Skip to content

Commit 7e0685a

Browse files
Merge pull request #358 from SciML/ap/direct_ldiv
Allow linsolve to be \
2 parents e989b72 + d840c17 commit 7e0685a

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NonlinearSolve"
22
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
33
authors = ["SciML"]
4-
version = "3.5.0"
4+
version = "3.5.1"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/internal/helpers.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ use this functionality unless it can't be avoided (like in [`LevenbergMarquardt`
123123

124124
# Extension Algorithm Helpers
125125
function __test_termination_condition(termination_condition, alg)
126-
termination_condition !== AbsNormTerminationMode && termination_condition !== nothing &&
126+
!(termination_condition isa AbsNormTerminationMode) &&
127+
termination_condition !== nothing &&
127128
error("`$(alg)` does not support termination conditions!")
128129
end
129130

src/internal/linear_solve.jl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,11 @@ function reinit_cache!(cache::LinearSolverCache, args...; kwargs...)
4949
cache.nfactors = 0
5050
end
5151

52-
@inline function LinearSolverCache(alg, linsolve, A::Number, b::Number, u; kwargs...)
53-
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
54-
end
55-
@inline function LinearSolverCache(alg, ::Nothing, A::SMatrix, b, u; kwargs...)
56-
# Default handling for SArrays caching in LinearSolve is not the best. Override it here
57-
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
58-
end
59-
@inline function LinearSolverCache(alg, linsolve, A::Diagonal, b, u; kwargs...)
60-
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
61-
end
6252
function LinearSolverCache(alg, linsolve, A, b, u; kwargs...)
53+
if (A isa Number && b isa Number) || (linsolve === nothing && A isa SMatrix) ||
54+
(A isa Diagonal) || (linsolve isa typeof(\))
55+
return LinearSolverCache(nothing, nothing, A, b, nothing, 0, 0)
56+
end
6357
@bb b_ = copy(b)
6458
@bb u_ = copy(u)
6559
linprob = LinearProblem(A, b_; u0 = u_, kwargs...)
@@ -193,3 +187,5 @@ end
193187
@inline __needs_square_A(::Nothing, ::Number) = false
194188
@inline __needs_square_A(::Nothing, _) = false
195189
@inline __needs_square_A(linsolve, _) = LinearSolve.needs_square_A(linsolve)
190+
@inline __needs_square_A(::typeof(\), _) = false
191+
@inline __needs_square_A(::typeof(\), ::Number) = false # Ambiguity Fix

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ end
1818
end
1919

2020
@inline __needs_concrete_A(::Nothing) = false
21+
@inline __needs_concrete_A(::typeof(\)) = true
2122
@inline __needs_concrete_A(linsolve) = needs_concrete_A(linsolve)
2223

2324
@inline __maybe_mutable(x, ::AutoSparseEnzyme) = __mutable(x)

test/core/rootfind.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const TERMINATION_CONDITIONS = [
7272
]
7373

7474
@testset "[IIP] u0: $(typeof(u0)) precs: $(_nameof(prec)) linsolve: $(_nameof(linsolve))" for u0 in ([
75-
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES())
75+
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES(), \)
7676
ad isa AutoZygote && continue
7777
if prec === :Random
7878
prec = (args...) -> (Diagonal(randn!(similar(u0))), nothing)
@@ -139,7 +139,7 @@ end
139139
RadiusUpdateSchemes.NLsolve, RadiusUpdateSchemes.Hei, RadiusUpdateSchemes.Yuan,
140140
RadiusUpdateSchemes.Fan, RadiusUpdateSchemes.Bastin]
141141
u0s = ([1.0, 1.0], @SVector[1.0, 1.0], 1.0)
142-
linear_solvers = [nothing, LUFactorization(), KrylovJL_GMRES()]
142+
linear_solvers = [nothing, LUFactorization(), KrylovJL_GMRES(), \]
143143

144144
@testset "[OOP] u0: $(typeof(u0)) radius_update_scheme: $(radius_update_scheme) linear_solver: $(linsolve)" for u0 in u0s,
145145
radius_update_scheme in radius_update_schemes, linsolve in linear_solvers
@@ -471,7 +471,7 @@ end
471471
precs = [NonlinearSolve.DEFAULT_PRECS, :Random]
472472

473473
@testset "[IIP] u0: $(typeof(u0)) precs: $(_nameof(prec)) linsolve: $(_nameof(linsolve))" for u0 in ([
474-
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES())
474+
1.0, 1.0],), prec in precs, linsolve in (nothing, KrylovJL_GMRES(), \)
475475
ad isa AutoZygote && continue
476476
if prec === :Random
477477
prec = (args...) -> (Diagonal(randn!(similar(u0))), nothing)

0 commit comments

Comments
 (0)