Skip to content

Commit bd5d988

Browse files
committed
Format
1 parent c7409c8 commit bd5d988

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-28
lines changed

ext/NonlinearSolveNLSolversExt.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ using ADTypes, FastClosures, NonlinearSolve, NLSolvers, SciMLBase, LinearAlgebra
44
using FiniteDiff, ForwardDiff
55

66
function SciMLBase.__solve(prob::NonlinearProblem, alg::NLSolversJL, args...;
7-
abstol = nothing, reltol = nothing, maxiters = 1000, alias_u0::Bool = false,
8-
termination_condition = nothing, kwargs...)
7+
abstol = nothing, reltol = nothing, maxiters = 1000,
8+
alias_u0::Bool = false, termination_condition = nothing, kwargs...)
99
NonlinearSolve.__test_termination_condition(termination_condition, :NLSolversJL)
1010

1111
abstol = NonlinearSolve.DEFAULT_TOLERANCE(abstol, eltype(prob.u0))
@@ -50,12 +50,13 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::NLSolversJL, args...;
5050
prob_nlsolver = NEqProblem(prob_obj; inplace = false)
5151
res = NLSolvers.solve(prob_nlsolver, prob.u0, alg.method, options)
5252

53-
retcode = ifelse(norm(res.info.best_residual, Inf) abstol, ReturnCode.Success,
54-
ReturnCode.MaxIters)
53+
retcode = ifelse(norm(res.info.best_residual, Inf) abstol,
54+
ReturnCode.Success, ReturnCode.MaxIters)
5555
stats = SciMLBase.NLStats(-1, -1, -1, -1, res.info.iter)
5656

57-
return SciMLBase.build_solution(prob, alg, res.info.solution,
58-
res.info.best_residual; retcode, original = res, stats)
57+
return SciMLBase.build_solution(
58+
prob, alg, res.info.solution, res.info.best_residual;
59+
retcode, original = res, stats)
5960
end
6061

6162
f!, u0, resid = NonlinearSolve.__construct_extension_f(prob; alias_u0)
@@ -73,12 +74,12 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::NLSolversJL, args...;
7374

7475
res = NLSolvers.solve(prob_nlsolver, u0, alg.method, options)
7576

76-
retcode = ifelse(norm(res.info.best_residual, Inf) abstol, ReturnCode.Success,
77-
ReturnCode.MaxIters)
77+
retcode = ifelse(
78+
norm(res.info.best_residual, Inf) abstol, ReturnCode.Success, ReturnCode.MaxIters)
7879
stats = SciMLBase.NLStats(-1, -1, -1, -1, res.info.iter)
7980

80-
return SciMLBase.build_solution(prob, alg, res.info.solution,
81-
res.info.best_residual; retcode, original = res, stats)
81+
return SciMLBase.build_solution(prob, alg, res.info.solution, res.info.best_residual;
82+
retcode, original = res, stats)
8283
end
8384

8485
end

src/abstract_types.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ end
214214
function __show_cache(io::IO, cache::AbstractNonlinearSolveCache, indent = 0)
215215
println(io, "$(nameof(typeof(cache)))(")
216216
__show_algorithm(io, cache.alg,
217-
(" "^(indent + 4)) * "alg = " * string(get_name(cache.alg)), indent +
218-
4)
217+
(" "^(indent + 4)) * "alg = " * string(get_name(cache.alg)), indent + 4)
219218
println(io, ",")
220219
println(io, (" "^(indent + 4)) * "u = ", get_u(cache), ",")
221220
println(io, (" "^(indent + 4)) * "residual = ", get_fu(cache), ",")

src/core/generic.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Performs one step of the nonlinear solver.
4545
respectively. For algorithms that don't use jacobian information, this keyword is
4646
ignored with a one-time warning.
4747
"""
48-
function SciMLBase.step!(cache::AbstractNonlinearSolveCache{iip, timeit}, args...;
49-
kwargs...) where {iip, timeit}
48+
function SciMLBase.step!(cache::AbstractNonlinearSolveCache{iip, timeit},
49+
args...; kwargs...) where {iip, timeit}
5050
not_terminated(cache) || return
5151
timeit && (time_start = time())
5252
res = @static_timeit cache.timer "solve" begin

src/default.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ end
5858
maxiters::Int
5959
end
6060

61-
function Base.show(io::IO,
62-
cache::NonlinearSolvePolyAlgorithmCache{pType, N}) where {pType, N}
61+
function Base.show(
62+
io::IO, cache::NonlinearSolvePolyAlgorithmCache{pType, N}) where {pType, N}
6363
problem_kind = ifelse(pType == :NLS, "NonlinearProblem", "NonlinearLeastSquaresProblem")
6464
println(io, "NonlinearSolvePolyAlgorithmCache for $(problem_kind) with $(N) algorithms")
6565
best_alg = ifelse(cache.best == -1, "nothing", cache.best)
@@ -84,8 +84,16 @@ for (probType, pType) in ((:NonlinearProblem, :NLS), (:NonlinearLeastSquaresProb
8484
maxtime = nothing, maxiters = 1000, kwargs...) where {N}
8585
return NonlinearSolvePolyAlgorithmCache{isinplace(prob), N, maxtime !== nothing}(
8686
map(solver -> SciMLBase.__init(prob, solver, args...; maxtime, kwargs...),
87-
alg.algs), alg, -1, 1, 0, 0.0, maxtime,
88-
ReturnCode.Default, false, maxiters)
87+
alg.algs),
88+
alg,
89+
-1,
90+
1,
91+
0,
92+
0.0,
93+
maxtime,
94+
ReturnCode.Default,
95+
false,
96+
maxiters)
8997
end
9098
end
9199
end
@@ -109,8 +117,9 @@ end
109117
stats = $(sol_syms[i]).stats
110118
u = $(sol_syms[i]).u
111119
fu = get_fu($(cache_syms[i]))
112-
return SciMLBase.build_solution($(sol_syms[i]).prob, cache.alg, u,
113-
fu; retcode = $(sol_syms[i]).retcode, stats,
120+
return SciMLBase.build_solution(
121+
$(sol_syms[i]).prob, cache.alg, u, fu;
122+
retcode = $(sol_syms[i]).retcode, stats,
114123
original = $(sol_syms[i]), trace = $(sol_syms[i]).trace)
115124
end
116125
cache.current = $(i + 1)
@@ -137,8 +146,8 @@ end
137146
return Expr(:block, calls...)
138147
end
139148

140-
@generated function __step!(cache::NonlinearSolvePolyAlgorithmCache{iip, N}, args...;
141-
kwargs...) where {iip, N}
149+
@generated function __step!(
150+
cache::NonlinearSolvePolyAlgorithmCache{iip, N}, args...; kwargs...) where {iip, N}
142151
calls = []
143152
cache_syms = [gensym("cache") for i in 1:N]
144153
for i in 1:N

test/wrappers/rootfind_tests.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ end
1616
prob_iip = SteadyStateProblem(f_iip, u0)
1717

1818
for alg in [
19-
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())), NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
19+
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())),
20+
NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
2021
sol = solve(prob_iip, alg)
2122
@test SciMLBase.successful_retcode(sol.retcode)
2223
@test maximum(abs, sol.resid) < 1e-6
@@ -28,7 +29,8 @@ end
2829
prob_oop = SteadyStateProblem(f_oop, u0)
2930

3031
for alg in [
31-
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())), NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
32+
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())),
33+
NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
3234
sol = solve(prob_oop, alg)
3335
@test SciMLBase.successful_retcode(sol.retcode)
3436
@test maximum(abs, sol.resid) < 1e-6
@@ -45,7 +47,8 @@ end
4547
prob_iip = NonlinearProblem{true}(f_iip, u0)
4648

4749
for alg in [
48-
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())), NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
50+
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())),
51+
NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
4952
local sol
5053
sol = solve(prob_iip, alg)
5154
@test SciMLBase.successful_retcode(sol.retcode)
@@ -57,7 +60,8 @@ end
5760
u0 = zeros(2)
5861
prob_oop = NonlinearProblem{false}(f_oop, u0)
5962
for alg in [
60-
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())), NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
63+
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())),
64+
NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL()]
6165
local sol
6266
sol = solve(prob_oop, alg)
6367
@test SciMLBase.successful_retcode(sol.retcode)
@@ -70,8 +74,7 @@ end
7074
for tol in [1e-1, 1e-3, 1e-6, 1e-10, 1e-15],
7175
alg in [
7276
NLSolversJL(NLSolvers.LineSearch(NLSolvers.Newton(), NLSolvers.Backtracking())),
73-
NLsolveJL(),
74-
CMINPACK(), SIAMFANLEquationsJL(; method = :newton),
77+
NLsolveJL(), CMINPACK(), SIAMFANLEquationsJL(; method = :newton),
7578
SIAMFANLEquationsJL(; method = :pseudotransient),
7679
SIAMFANLEquationsJL(; method = :secant)]
7780

0 commit comments

Comments
 (0)