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

Commit 8c77efe

Browse files
committed
Add compat entries and change default norm
1 parent 8d9a5d3 commit 8c77efe

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1818
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1919

2020
[compat]
21+
ADTypes = "0.2"
2122
ArrayInterface = "7"
23+
ConcreteStructs = "0.2"
2224
DiffEqBase = "6.126"
2325
FiniteDiff = "2"
2426
ForwardDiff = "0.10.3"
2527
LinearAlgebra = "1.9"
28+
MaybeInplace = "0.1"
2629
PrecompileTools = "1"
2730
Reexport = "1"
2831
SciMLBase = "2.7"

src/nlsolve/halley.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ A low-overhead implementation of Halley's Method.
1414
1515
- `autodiff`: determines the backend used for the Hessian. Defaults to
1616
`AutoForwardDiff()`. Valid choices are `AutoForwardDiff()` or `AutoFiniteDiff()`.
17+
18+
!!! warning
19+
20+
Inplace Problems are currently not supported by this method.
1721
"""
1822
@kwdef @concrete struct SimpleHalley <: AbstractNewtonAlgorithm
1923
autodiff = AutoForwardDiff()

src/nlsolve/trustRegion.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
7171
termination_condition)
7272

7373
# Set default trust region radius if not specified by user.
74-
Δₘₐₓ == 0 && (Δₘₐₓ = max(norm(fx), maximum(x) - minimum(x)))
74+
Δₘₐₓ == 0 && (Δₘₐₓ = max(NONLINEARSOLVE_DEFAULT_NORM(fx), maximum(x) - minimum(x)))
7575
Δ == 0 &&= Δₘₐₓ / 11)
7676

77-
fₖ = 0.5 * norm(fx)^2
77+
fₖ = 0.5 * NONLINEARSOLVE_DEFAULT_NORM(fx)^2
7878
H = ∇f' * ∇f
7979
g = _restructure(x, ∇f' * _vec(fx))
8080
shrink_counter = 0
@@ -93,7 +93,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
9393

9494
fx = __eval_f(prob, fx, x)
9595

96-
fₖ₊₁ = norm(fx)^2 / T(2)
96+
fₖ₊₁ = NONLINEARSOLVE_DEFAULT_NORM(fx)^2 / T(2)
9797

9898
# Compute the ratio of the actual to predicted reduction.
9999
@bb= H × vec(δ)
@@ -120,7 +120,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleTrustRegion, args.
120120
fx, ∇f = value_and_jacobian(alg.autodiff, prob.f, fx, x, prob.p, jac_cache; J)
121121

122122
# Update the trust region radius.
123-
(r > η₃) && (norm(δ) Δ) &&= min(t₂ * Δ, Δₘₐₓ))
123+
(r > η₃) && (NONLINEARSOLVE_DEFAULT_NORM(δ) Δ) &&= min(t₂ * Δ, Δₘₐₓ))
124124
fₖ = fₖ₊₁
125125

126126
@bb H = transpose(∇f) × ∇f
@@ -138,12 +138,12 @@ function dogleg_method!!(cache, J, f, g, Δ)
138138
@bb δN .= _restructure(δN, J \ _vec(f))
139139
@bb δN .*= -1
140140
# Test if the full step is within the trust region.
141-
(norm(δN) Δ) && return δN
141+
(NONLINEARSOLVE_DEFAULT_NORM(δN) Δ) && return δN
142142

143143
# Calcualte Cauchy point, optimum along the steepest descent direction.
144144
@bb δsd .= g
145145
@bb @. δsd *= -1
146-
norm_δsd = norm(δsd)
146+
norm_δsd = NONLINEARSOLVE_DEFAULT_NORM(δsd)
147147
if (norm_δsd Δ)
148148
@bb @. δsd *= Δ / norm_δsd
149149
return δsd

0 commit comments

Comments
 (0)