Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit d8f141b

Browse files
committed
Disambiguate conditionals with Bool
1 parent 80f1bcc commit d8f141b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/nlsolve/trustRegion.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
8585
@bb= copy(x)
8686
dogleg_cache = (; δsd, δN_δsd, δN)
8787

88-
F = fx
8988
for k in 1:maxiters
9089
# Solve the trust region subproblem.
9190
δ = dogleg_method!!(dogleg_cache, ∇f, fx, g, Δ)
@@ -100,16 +99,16 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
10099
r = (fₖ₊₁ - fₖ) / (dot(δ, g) + dot(δ, Hδ) / T(2))
101100

102101
# Update the trust region radius.
103-
if r < η₂
102+
if Bool(r η₂)
103+
shrink_counter = 0
104+
else
104105
Δ = t₁ * Δ
105106
shrink_counter += 1
106107
shrink_counter > max_shrink_times && return build_solution(prob, alg, x, fx;
107108
retcode = ReturnCode.ConvergenceFailure)
108-
else
109-
shrink_counter = 0
110109
end
111110

112-
if r > η₁
111+
if Bool(r η₁)
113112
# Termination Checks
114113
tc_sol = check_termination(tc_cache, fx, x, xo, prob, alg)
115114
tc_sol !== nothing && return tc_sol
@@ -138,13 +137,14 @@ function dogleg_method!!(cache, J, f, g, Δ)
138137
@bb δN .= _restructure(δN, J \ _vec(f))
139138
@bb δN .*= -1
140139
# Test if the full step is within the trust region.
141-
(norm(δN) Δ) && return δN
140+
Bool(norm(δN) Δ) && return δN
142141

143142
# Calcualte Cauchy point, optimum along the steepest descent direction.
144143
@bb δsd .= g
145144
@bb @. δsd *= -1
146145
norm_δsd = norm(δsd)
147-
if (norm_δsd Δ)
146+
147+
if Bool(norm_δsd Δ)
148148
@bb @. δsd *= Δ / norm_δsd
149149
return δsd
150150
end

src/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ function check_termination(tc_cache, fx, x, xo, prob, alg)
286286
end
287287
function check_termination(tc_cache, fx, x, xo, prob, alg,
288288
::AbstractNonlinearTerminationMode)
289-
if tc_cache(fx, x, xo)
289+
if Bool(tc_cache(fx, x, xo))
290290
return build_solution(prob, alg, x, fx; retcode = ReturnCode.Success)
291291
end
292292
return nothing
293293
end
294294
function check_termination(tc_cache, fx, x, xo, prob, alg,
295295
::AbstractSafeNonlinearTerminationMode)
296-
if tc_cache(fx, x, xo)
296+
if Bool(tc_cache(fx, x, xo))
297297
if tc_cache.retcode == NonlinearSafeTerminationReturnCode.Success
298298
retcode = ReturnCode.Success
299299
elseif tc_cache.retcode == NonlinearSafeTerminationReturnCode.PatienceTermination
@@ -309,7 +309,7 @@ function check_termination(tc_cache, fx, x, xo, prob, alg,
309309
end
310310
function check_termination(tc_cache, fx, x, xo, prob, alg,
311311
::AbstractSafeBestNonlinearTerminationMode)
312-
if tc_cache(fx, x, xo)
312+
if Bool(tc_cache(fx, x, xo))
313313
if tc_cache.retcode == NonlinearSafeTerminationReturnCode.Success
314314
retcode = ReturnCode.Success
315315
elseif tc_cache.retcode == NonlinearSafeTerminationReturnCode.PatienceTermination

0 commit comments

Comments
 (0)