Skip to content

Commit 1d7d202

Browse files
committed
Fix formatting
1 parent 80c8ced commit 1d7d202

File tree

10 files changed

+27
-68
lines changed

10 files changed

+27
-68
lines changed

src/algorithms/levenberg_marquardt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
LevenbergMarquardt(; linsolve = nothing,
33
precs = DEFAULT_PRECS, damping_initial::Real = 1.0, α_geodesic::Real = 0.75,
44
damping_increase_factor::Real = 2.0, damping_decrease_factor::Real = 3.0,
5-
finite_diff_step_geodesic::Real = 0.1, b_uphill::Real = 1.0, autodiff = nothing,
5+
finite_diff_step_geodesic = 0.1, b_uphill::Real = 1.0, autodiff = nothing,
66
min_damping_D::Real = 1e-8, disable_geodesic = Val(false))
77
88
An advanced Levenberg-Marquardt implementation with the improvements suggested in
@@ -33,7 +33,7 @@ For the remaining arguments, see [`GeodesicAcceleration`](@ref) and
3333
function LevenbergMarquardt(; concrete_jac = missing, linsolve = nothing,
3434
precs = DEFAULT_PRECS, damping_initial::Real = 1.0, α_geodesic::Real = 0.75,
3535
damping_increase_factor::Real = 2.0, damping_decrease_factor::Real = 3.0,
36-
finite_diff_step_geodesic::Real = 0.1, b_uphill::Real = 1.0, autodiff = nothing,
36+
finite_diff_step_geodesic = 0.1, b_uphill::Real = 1.0, autodiff = nothing,
3737
min_damping_D::Real = 1e-8, disable_geodesic = False)
3838
if concrete_jac !== missing
3939
Base.depwarn("The `concrete_jac` keyword argument is deprecated and will be \

src/core/approximate_jacobian.jl

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ function SciMLBase.__init(prob::AbstractNonlinearProblem{uType, iip},
173173
J = initialization_cache(nothing)
174174
inv_workspace, J = INV ? __safe_inv_workspace(J) : (nothing, J)
175175
descent_cache = __internal_init(prob, alg.descent, J, fu, u; abstol, reltol,
176-
internalnorm,
177-
linsolve_kwargs, pre_inverted = Val(INV), timer)
176+
internalnorm, linsolve_kwargs, pre_inverted = Val(INV), timer)
178177
du = get_du(descent_cache)
179178

180179
reinit_rule_cache = __internal_init(alg.reinit_rule, J, fu, u, du)
@@ -191,8 +190,7 @@ function SciMLBase.__init(prob::AbstractNonlinearProblem{uType, iip},
191190
supports_trust_region(alg.descent) || error("Trust Region not supported by \
192191
$(alg.descent).")
193192
trustregion_cache = __internal_init(prob, alg.trustregion, f, fu, u, p;
194-
internalnorm,
195-
kwargs...)
193+
internalnorm, kwargs...)
196194
GB = :TrustRegion
197195
end
198196

@@ -205,12 +203,7 @@ function SciMLBase.__init(prob::AbstractNonlinearProblem{uType, iip},
205203
GB = :LineSearch
206204
end
207205

208-
update_rule_cache = __internal_init(prob,
209-
alg.update_rule,
210-
J,
211-
fu,
212-
u,
213-
du;
206+
update_rule_cache = __internal_init(prob, alg.update_rule, J, fu, u, du;
214207
internalnorm)
215208

216209
trace = init_nonlinearsolve_trace(alg, u, fu, ApplyArray(__zero, J), du;
@@ -256,8 +249,7 @@ function __step!(cache::ApproximateJacobianSolveCache{INV, GB, iip};
256249
elseif recompute_jacobian === nothing
257250
# Standard Step
258251
reinit = __internal_solve!(cache.reinit_rule_cache, cache.J, cache.fu,
259-
cache.u,
260-
cache.du)
252+
cache.u, cache.du)
261253
reinit && (countable_reinit = true)
262254
elseif recompute_jacobian
263255
reinit = true # Force ReInitialization: Don't count towards resetting
@@ -276,9 +268,7 @@ function __step!(cache::ApproximateJacobianSolveCache{INV, GB, iip};
276268
end
277269

278270
if reinit
279-
J_init = __internal_solve!(cache.initialization_cache,
280-
cache.fu,
281-
cache.u,
271+
J_init = __internal_solve!(cache.initialization_cache, cache.fu, cache.u,
282272
Val(true))
283273
cache.J = INV ? __safe_inv!!(cache.inv_workspace, J_init) : J_init
284274
J = cache.J
@@ -318,8 +308,7 @@ function __step!(cache::ApproximateJacobianSolveCache{INV, GB, iip};
318308
elseif GB === :TrustRegion
319309
@static_timeit cache.timer "trustregion" begin
320310
tr_accepted, u_new, fu_new = __internal_solve!(cache.trustregion_cache, J,
321-
cache.fu,
322-
cache.u, δu, descent_intermediates)
311+
cache.fu, cache.u, δu, descent_intermediates)
323312
if tr_accepted
324313
@bb copyto!(cache.u, u_new)
325314
@bb copyto!(cache.fu, fu_new)

src/core/generalized_first_order.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ function __step!(cache::GeneralizedFirstOrderAlgorithmCache{iip, GB};
229229
if GB === :LineSearch
230230
@static_timeit cache.timer "linesearch" begin
231231
linesearch_failed, α = __internal_solve!(cache.linesearch_cache,
232-
cache.u,
233-
δu)
232+
cache.u, δu)
234233
end
235234
if linesearch_failed
236235
cache.retcode = ReturnCode.InternalLineSearchFailed
@@ -243,8 +242,7 @@ function __step!(cache::GeneralizedFirstOrderAlgorithmCache{iip, GB};
243242
elseif GB === :TrustRegion
244243
@static_timeit cache.timer "trustregion" begin
245244
tr_accepted, u_new, fu_new = __internal_solve!(cache.trustregion_cache, J,
246-
cache.fu,
247-
cache.u, δu, descent_intermediates)
245+
cache.fu, cache.u, δu, descent_intermediates)
248246
if tr_accepted
249247
@bb copyto!(cache.u, u_new)
250248
@bb copyto!(cache.fu, fu_new)

src/core/spectral_methods.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ function SciMLBase.__init(prob::AbstractNonlinearProblem, alg::GeneralizedDFSane
130130
@bb fu_cache = copy(fu)
131131

132132
linesearch_cache = __internal_init(prob, alg.linesearch, prob.f, fu, u, prob.p;
133-
maxiters,
134-
internalnorm, kwargs...)
133+
maxiters, internalnorm, kwargs...)
135134

136135
abstol, reltol, tc_cache = init_termination_cache(abstol, reltol, fu, u_cache,
137136
termination_condition)

src/descent/damped_newton.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,15 @@ function __internal_init(prob::AbstractNonlinearProblem, alg::DampedNewtonDescen
9494
rhs_damp = fu
9595
end
9696
damping_fn_cache = __internal_init(prob, alg.damping_fn, alg.initial_damping,
97-
jac_damp,
98-
rhs_damp, u, False; kwargs...)
97+
jac_damp, rhs_damp, u, False; kwargs...)
9998
D = damping_fn_cache(nothing)
10099
D isa Number && (D = D * I)
101100
rhs_cache = vcat(_vec(fu), _vec(u))
102101
J_cache = _vcat(J, D)
103102
A, b = J_cache, rhs_cache
104103
elseif mode === :simple
105104
damping_fn_cache = __internal_init(prob, alg.damping_fn, alg.initial_damping, J, fu,
106-
u, False;
107-
kwargs...)
105+
u, False; kwargs...)
108106
J_cache = __maybe_unaliased(J, alias_J)
109107
D = damping_fn_cache(nothing)
110108
J_damped = __dampen_jacobian!!(J_cache, J, D)
@@ -186,10 +184,8 @@ function __internal_solve!(cache::DampedNewtonDescentCache{INV, mode}, J, fu, u,
186184
INV && (J = inv(J))
187185
@bb cache.JᵀJ_cache = transpose(J) × J
188186
@bb cache.Jᵀfu_cache = transpose(J) × vec(fu)
189-
D = __internal_solve!(cache.damping_fn_cache,
190-
cache.JᵀJ_cache,
191-
cache.Jᵀfu_cache,
192-
True)
187+
D = __internal_solve!(cache.damping_fn_cache, cache.JᵀJ_cache,
188+
cache.Jᵀfu_cache, True)
193189
cache.J = __dampen_jacobian!!(cache.J, cache.JᵀJ_cache, D)
194190
A = __maybe_symmetric(cache.J)
195191
elseif !recompute_A

src/descent/dogleg.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,7 @@ function __internal_solve!(cache::DoglegCache{INV, NF}, J, fu, u, idx::Val{N} =
8282
want to use a Trust Region."
8383
δu = get_du(cache, idx)
8484
T = promote_type(eltype(u), eltype(fu))
85-
δu_newton, _, _ = __internal_solve!(cache.newton_cache,
86-
J,
87-
fu,
88-
u,
89-
idx;
90-
skip_solve,
85+
δu_newton, _, _ = __internal_solve!(cache.newton_cache, J, fu, u, idx; skip_solve,
9186
kwargs...)
9287

9388
# Newton's Step within the trust region
@@ -108,12 +103,7 @@ function __internal_solve!(cache::DoglegCache{INV, NF}, J, fu, u, idx::Val{N} =
108103
@bb cache.δu_cache_mul = JᵀJ × vec(δu_cauchy)
109104
δuJᵀJδu = __dot(δu_cauchy, cache.δu_cache_mul)
110105
else
111-
δu_cauchy, _, _ = __internal_solve!(cache.cauchy_cache,
112-
J,
113-
fu,
114-
u,
115-
idx;
116-
skip_solve,
106+
δu_cauchy, _, _ = __internal_solve!(cache.cauchy_cache, J, fu, u, idx; skip_solve,
117107
kwargs...)
118108
J_ = INV ? inv(J) : J
119109
l_grad = cache.internalnorm(δu_cauchy)

src/descent/geodesic_acceleration.jl

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ function set_acceleration!(cache::GeodesicAccelerationCache, δa, ::Val{N}) wher
8484
end
8585

8686
function __internal_init(prob::AbstractNonlinearProblem, alg::GeodesicAcceleration, J, fu,
87-
u;
88-
shared::Val{N} = Val(1), pre_inverted::Val{INV} = False, linsolve_kwargs = (;),
87+
u; shared::Val{N} = Val(1), pre_inverted::Val{INV} = False, linsolve_kwargs = (;),
8988
abstol = nothing, reltol = nothing, internalnorm::F = DEFAULT_NORM,
9089
kwargs...) where {INV, N, F}
9190
T = promote_type(eltype(u), eltype(fu))
@@ -94,8 +93,7 @@ function __internal_init(prob::AbstractNonlinearProblem, alg::GeodesicAccelerati
9493
@bb δu_ = similar(u)
9594
end
9695
descent_cache = __internal_init(prob, alg.descent, J, fu, u; shared = Val(N * 2),
97-
pre_inverted,
98-
linsolve_kwargs, abstol, reltol, kwargs...)
96+
pre_inverted, linsolve_kwargs, abstol, reltol, kwargs...)
9997
@bb Jv = similar(fu)
10098
@bb fu_cache = copy(fu)
10199
@bb u_cache = similar(u)
@@ -107,12 +105,7 @@ function __internal_solve!(cache::GeodesicAccelerationCache, J, fu, u, idx::Val{
107105
skip_solve::Bool = false, kwargs...) where {N}
108106
a, v, δu = get_acceleration(cache, idx), get_velocity(cache, idx), get_du(cache, idx)
109107
skip_solve && return δu, true, (; a, v)
110-
v, _, _ = __internal_solve!(cache.descent_cache,
111-
J,
112-
fu,
113-
u,
114-
Val(2N - 1);
115-
skip_solve,
108+
v, _, _ = __internal_solve!(cache.descent_cache, J, fu, u, Val(2N - 1); skip_solve,
116109
kwargs...)
117110

118111
@bb @. cache.u_cache = u + cache.h * v
@@ -121,9 +114,9 @@ function __internal_solve!(cache::GeodesicAccelerationCache, J, fu, u, idx::Val{
121114
J !== nothing && @bb(cache.Jv=J × vec(v))
122115
Jv = _restructure(cache.fu_cache, cache.Jv)
123116
@bb @. cache.fu_cache = (2 / cache.h) * ((cache.fu_cache - fu) / cache.h - Jv)
117+
124118
a, _, _ = __internal_solve!(cache.descent_cache, J, cache.fu_cache, u, Val(2N);
125-
skip_solve,
126-
kwargs..., reuse_A_if_factorization = true)
119+
skip_solve, kwargs..., reuse_A_if_factorization = true)
127120

128121
norm_v = cache.internalnorm(v)
129122
norm_a = cache.internalnorm(a)

src/descent/steepest.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ end
3030
@internal_caches SteepestDescentCache :lincache
3131

3232
@inline function __internal_init(prob::AbstractNonlinearProblem, alg::SteepestDescent, J,
33-
fu,
34-
u; shared::Val{N} = Val(1), pre_inverted::Val{INV} = False, linsolve_kwargs = (;),
35-
abstol = nothing, reltol = nothing, timer = get_timer_output(),
36-
kwargs...) where {INV, N}
33+
fu, u; shared::Val{N} = Val(1), pre_inverted::Val{INV} = False,
34+
linsolve_kwargs = (;), abstol = nothing, reltol = nothing,
35+
timer = get_timer_output(), kwargs...) where {INV, N}
3736
INV && @assert length(fu)==length(u) "Non-Square Jacobian Inverse doesn't make sense."
3837
@bb δu = similar(u)
3938
δus = N 1 ? nothing : map(2:N) do i

src/globalization/trust_region.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,7 @@ function __internal_init(prob::AbstractNonlinearProblem, alg::GenericTrustRegion
418418
u_cache, fu_cache, false, 0, 0, alg)
419419
end
420420

421-
function __internal_solve!(cache::GenericTrustRegionSchemeCache,
422-
J,
423-
fu,
424-
u,
425-
δu,
421+
function __internal_solve!(cache::GenericTrustRegionSchemeCache, J, fu, u, δu,
426422
descent_stats)
427423
T = promote_type(eltype(u), eltype(fu))
428424
@bb @. cache.u_cache = u + δu

src/internal/approximate_initialization.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ function __internal_init(prob::AbstractNonlinearProblem, alg::IdentityInitializa
9191
internalnorm)
9292
end
9393
function __internal_init(prob::AbstractNonlinearProblem, alg::IdentityInitialization,
94-
solver,
95-
f::F, fu, u, p; internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN}
94+
solver, f::F, fu, u, p; internalnorm::IN = DEFAULT_NORM, kwargs...) where {F, IN}
9695
α = __initial_alpha(alg.alpha, u, fu, internalnorm)
9796
if alg.structure isa DiagonalStructure
9897
@assert length(u)==length(fu) "Diagonal Jacobian Structure must be square!"

0 commit comments

Comments
 (0)