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

Commit 464f417

Browse files
Merge pull request #174 from SciML/auto-juliaformatter-pr
Automatic JuliaFormatter.jl run
2 parents c86f900 + 734ebaf commit 464f417

24 files changed

+108
-84
lines changed

ext/SimpleNonlinearSolveChainRulesCoreExt.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ using SimpleNonlinearSolve: SimpleNonlinearSolve, ImmutableNonlinearProblem
1010
function ChainRulesCore.rrule(::typeof(SimpleNonlinearSolve.__internal_solve_up),
1111
prob::Union{ImmutableNonlinearProblem, NonlinearLeastSquaresProblem},
1212
sensealg, u0, u0_changed, p, p_changed, alg, args...; kwargs...)
13-
out, ∇internal = DiffEqBase._solve_adjoint(
13+
out,
14+
∇internal = DiffEqBase._solve_adjoint(
1415
prob, sensealg, u0, p, ChainRulesOriginator(), alg, args...; kwargs...)
1516
function ∇__internal_solve_up(Δ)
1617
∂f, ∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(Δ)

ext/SimpleNonlinearSolveReverseDiffExt.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ for pType in (ImmutableNonlinearProblem, NonlinearLeastSquaresProblem)
5252
ReverseDiff.@grad function __internal_solve_up(
5353
prob::$(pType), sensealg, u0, u0_changed,
5454
p, p_changed, alg, args...; kwargs...)
55-
out, ∇internal = DiffEqBase._solve_adjoint(
55+
out,
56+
∇internal = DiffEqBase._solve_adjoint(
5657
prob, sensealg, ReverseDiff.value(u0), ReverseDiff.value(p),
5758
ReverseDiffOriginator(), alg, args...; kwargs...)
5859
function ∇__internal_solve_up(_args...)

ext/SimpleNonlinearSolveTaylorDiffExt.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ function SciMLBase.__solve(prob::ImmutableNonlinearProblem, alg::SimpleHousehold
3838
@bb xo = copy(x)
3939
f = __fixed_parameter_function(prob)
4040

41-
abstol, reltol, tc_cache = init_termination_cache(
42-
prob, abstol, reltol, fx, x, termination_condition)
41+
abstol, reltol,
42+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
4343

4444
for i in 1:maxiters
4545
num, den, fx = __get_higher_order_derivatives(alg, prob, f, x, fx)

ext/SimpleNonlinearSolveTrackerExt.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ for pType in (ImmutableNonlinearProblem, NonlinearLeastSquaresProblem)
3333
p_, p_changed, alg, args...; kwargs...)
3434
u0, p = Tracker.data(u0_), Tracker.data(p_)
3535
prob = remake(_prob; u0, p)
36-
out, ∇internal = DiffEqBase._solve_adjoint(
36+
out,
37+
∇internal = DiffEqBase._solve_adjoint(
3738
prob, sensealg, u0, p, TrackerOriginator(), alg, args...; kwargs...)
3839

3940
function ∇__internal_solve_up(Δ)
40-
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(Tracker.data(Δ))
41+
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator,
42+
∂args... = ∇internal(Tracker.data(Δ))
4143
return (∂prob, ∂sensealg, ∂u0, nothing, ∂p, nothing, nothing, ∂args...)
4244
end
4345

src/ad.jl

+10-5
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,16 @@ function __nlsolve_ad(prob::NonlinearLeastSquaresProblem, alg, args...; kwargs..
9090
return nothing
9191
end
9292
else
93-
_F = @closure (u, p) -> begin
93+
_F = @closure (
94+
u, p) -> begin
9495
resid = prob.f(u, p)
9596
return reshape(2 .* prob.f.vjp(resid, u, p), size(u))
9697
end
9798
end
9899
elseif SciMLBase.has_jac(prob.f)
99100
if isinplace(prob)
100-
_F = @closure (du, u, p) -> begin
101+
_F = @closure (
102+
du, u, p) -> begin
101103
J = __similar(du, length(sol.resid), length(u))
102104
prob.f.jac(J, u, p)
103105
resid = __similar(du, length(sol.resid))
@@ -106,13 +108,15 @@ function __nlsolve_ad(prob::NonlinearLeastSquaresProblem, alg, args...; kwargs..
106108
return nothing
107109
end
108110
else
109-
_F = @closure (u, p) -> begin
111+
_F = @closure (u,
112+
p) -> begin
110113
return reshape(2 .* vec(prob.f(u, p))' * prob.f.jac(u, p), size(u))
111114
end
112115
end
113116
else
114117
if isinplace(prob)
115-
_F = @closure (du, u, p) -> begin
118+
_F = @closure (du, u,
119+
p) -> begin
116120
_f = @closure (du, u) -> prob.f(du, u, p)
117121
resid = __similar(du, length(sol.resid))
118122
v, J = DI.value_and_jacobian(_f, resid, AutoForwardDiff(), u)
@@ -128,7 +132,8 @@ function __nlsolve_ad(prob::NonlinearLeastSquaresProblem, alg, args...; kwargs..
128132
return __zygote_compute_nlls_vjp(_f, u, p)
129133
end
130134
else
131-
_F = @closure (u, p) -> begin
135+
_F = @closure (
136+
u, p) -> begin
132137
_f = Base.Fix2(prob.f, p)
133138
v, J = DI.value_and_jacobian(_f, AutoForwardDiff(), u)
134139
return reshape(2 .* vec(v)' * J, size(u))

src/bracketing/bisection.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection,
7272
end
7373
end
7474

75-
sol, i, left, right, fl, fr = __bisection(
76-
left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
75+
sol, i,
76+
left,
77+
right,
78+
fl, fr = __bisection(left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
7779

7880
sol !== nothing && return sol
7981

src/bracketing/brent.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Brent, args...;
109109
end
110110
end
111111

112-
sol, i, left, right, fl, fr = __bisection(
113-
left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
112+
sol, i,
113+
left,
114+
right,
115+
fl, fr = __bisection(left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
114116

115117
sol !== nothing && return sol
116118

src/bracketing/falsi.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Falsi, args...;
6767
end
6868
end
6969

70-
sol, i, left, right, fl, fr = __bisection(
71-
left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
70+
sol, i,
71+
left,
72+
right,
73+
fl, fr = __bisection(left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
7274
sol !== nothing && return sol
7375

7476
return SciMLBase.build_solution(

src/bracketing/ridder.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Ridder, args...;
7474
end
7575
end
7676

77-
sol, i, left, right, fl, fr = __bisection(
78-
left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
77+
sol, i,
78+
left,
79+
right,
80+
fl, fr = __bisection(left, right, fl, fr, f; abstol, maxiters = maxiters - i, prob, alg)
7981
sol !== nothing && return sol
8082

8183
return SciMLBase.build_solution(

src/linesearch.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ function __generic_init(alg::LiFukushimaLineSearch, prob, fu, u)
5050
@bb fu_cache = similar(fu)
5151
T = promote_type(eltype(fu), eltype(u))
5252

53-
ϕ = @closure (u, δu, α) -> begin
53+
ϕ = @closure (u, δu,
54+
α) -> begin
5455
@bb @. u_cache = u + α * δu
5556
return NONLINEARSOLVE_DEFAULT_NORM(__eval_f(prob, fu_cache, u_cache))
5657
end

src/nlsolve/broyden.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function SciMLBase.__solve(prob::ImmutableNonlinearProblem, alg::SimpleBroyden,
4848
@bb δJ⁻¹n = copy(x)
4949
@bb δJ⁻¹ = copy(J⁻¹)
5050

51-
abstol, reltol, tc_cache = init_termination_cache(
52-
prob, abstol, reltol, fx, x, termination_condition)
51+
abstol, reltol,
52+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
5353

5454
ls_cache = __get_linesearch(alg) === Val(true) ? LiFukushimaLineSearch()(prob, fx, x) :
5555
nothing

src/nlsolve/dfsane.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ function SciMLBase.__solve(prob::ImmutableNonlinearProblem, alg::SimpleDFSane{M}
7070
τ_min = T(alg.τ_min)
7171
τ_max = T(alg.τ_max)
7272

73-
abstol, reltol, tc_cache = init_termination_cache(
74-
prob, abstol, reltol, fx, x, termination_condition)
73+
abstol, reltol,
74+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
7575

7676
fx_norm = NONLINEARSOLVE_DEFAULT_NORM(fx)^nexp
7777
α_1 = one(T)

src/nlsolve/halley.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ function SciMLBase.__solve(prob::ImmutableNonlinearProblem, alg::SimpleHalley, a
3333

3434
f = __fixed_parameter_function(prob)
3535
autodiff = __get_concrete_autodiff(prob, alg.autodiff)
36-
abstol, reltol, tc_cache = init_termination_cache(
37-
prob, abstol, reltol, fx, x, termination_condition)
36+
abstol, reltol,
37+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
3838

3939
@bb xo = copy(x)
4040

src/nlsolve/klement.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function SciMLBase.__solve(prob::ImmutableNonlinearProblem, alg::SimpleKlement,
1313
T = eltype(x)
1414
fx = _get_fx(prob, x)
1515

16-
abstol, reltol, tc_cache = init_termination_cache(
17-
prob, abstol, reltol, fx, x, termination_condition)
16+
abstol, reltol,
17+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
1818

1919
@bb δx = copy(x)
2020
@bb fprev = copy(fx)

src/nlsolve/lbroyden.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ end
6363

6464
U, Vᵀ = __init_low_rank_jacobian(x, fx, x isa StaticArray ? threshold : Val(η))
6565

66-
abstol, reltol, tc_cache = init_termination_cache(
67-
prob, abstol, reltol, fx, x, termination_condition)
66+
abstol, reltol,
67+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
6868

6969
@bb xo = copy(x)
7070
@bb δx = copy(fx)
@@ -140,7 +140,8 @@ function __static_solve(
140140
init_α = inv(alg.alpha)
141141
end
142142

143-
converged, res = __unrolled_lbroyden_initial_iterations(
143+
converged,
144+
res = __unrolled_lbroyden_initial_iterations(
144145
prob, xo, fo, δx, abstol, U, Vᵀ, threshold, ls_cache, init_α)
145146

146147
converged &&

src/nlsolve/raphson.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ function SciMLBase.__solve(
3434
f = __fixed_parameter_function(prob)
3535
J, jac_cache = jacobian_cache(autodiff, prob, f, fx, x)
3636

37-
abstol, reltol, tc_cache = init_termination_cache(
38-
prob, abstol, reltol, fx, x, termination_condition)
37+
abstol, reltol,
38+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
3939

4040
for i in 1:maxiters
4141
fx, dfx = value_and_jacobian(autodiff, prob, f, fx, x, jac_cache; J)

src/nlsolve/trustRegion.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ function SciMLBase.__solve(prob::ImmutableNonlinearProblem, alg::SimpleTrustRegi
8989
J, jac_cache = jacobian_cache(autodiff, prob, f, fx, x)
9090
fx, ∇f = value_and_jacobian(autodiff, prob, f, fx, x, jac_cache; J)
9191

92-
abstol, reltol, tc_cache = init_termination_cache(
93-
prob, abstol, reltol, fx, x, termination_condition)
92+
abstol, reltol,
93+
tc_cache = init_termination_cache(prob, abstol, reltol, fx, x, termination_condition)
9494

9595
# Set default trust region radius if not specified by user.
9696
Δₘₐₓ == 0 && (Δₘₐₓ = max(norm_fx, maximum(x) - minimum(x)))

src/termination_conditions.jl

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ for name in (:Norm, :RelNorm, :AbsNorm)
112112
end
113113

114114
for norm_type in (:Rel, :Abs), safety in (:Safe, :SafeBest)
115+
115116
struct_name = Symbol(norm_type, safety, :TerminationMode)
116117
supertype_name = Symbol(:Abstract, safety, :NonlinearTerminationMode)
117118

src/termination_conditions_deprecated.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ function (cond::NLSolveTerminationCondition)(storage::Union{
245245
if objective typeof(criteria)(patience_objective_multiplier) * criteria
246246
if nstep cond.safe_termination_options.patience_steps
247247
last_k_values = objective_values[max(1,
248-
length(objective_values) -
249-
cond.safe_termination_options.patience_steps):end]
248+
length(objective_values) - cond.safe_termination_options.patience_steps):end]
250249
if maximum(last_k_values) <
251250
typeof(criteria)(cond.safe_termination_options.min_max_factor) *
252251
minimum(last_k_values)

src/utils.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ end
205205
@inline value(x::Dual) = ForwardDiff.value(x)
206206
@inline value(x::AbstractArray{<:Dual}) = map(ForwardDiff.value, x)
207207

208-
@inline __eval_f(prob, fx, x) = isinplace(prob) ? (prob.f(fx, x, prob.p); fx) :
209-
prob.f(x, prob.p)
208+
@inline __eval_f(
209+
prob, fx, x) = isinplace(prob) ? (prob.f(fx, x, prob.p); fx) : prob.f(x, prob.p)
210210

211211
# Unalias
212212
@inline __maybe_unaliased(x::Union{Number, SArray}, ::Bool) = x

test/core/23_test_problems_tests.jl

+21-21
Original file line numberDiff line numberDiff line change
@@ -43,64 +43,64 @@ export problems, dicts, test_on_library
4343
end
4444

4545
@testitem "23 Test Problems: SimpleNewtonRaphson" setup=[RobustnessTesting] tags=[:core] begin
46-
alg_ops = (SimpleNewtonRaphson(),)
46+
alg_ops=(SimpleNewtonRaphson(),)
4747

48-
broken_tests = Dict(alg => Int[] for alg in alg_ops)
49-
broken_tests[alg_ops[1]] = []
48+
broken_tests=Dict(alg=>Int[] for alg in alg_ops)
49+
broken_tests[alg_ops[1]]=[]
5050

5151
test_on_library(problems, dicts, alg_ops, broken_tests)
5252
end
5353

5454
@testitem "23 Test Problems: SimpleHalley" setup=[RobustnessTesting] tags=[:core] begin
55-
alg_ops = (SimpleHalley(),)
55+
alg_ops=(SimpleHalley(),)
5656

57-
broken_tests = Dict(alg => Int[] for alg in alg_ops)
57+
broken_tests=Dict(alg=>Int[] for alg in alg_ops)
5858
if Sys.isapple()
59-
broken_tests[alg_ops[1]] = [1, 5, 11, 15, 16, 18]
59+
broken_tests[alg_ops[1]]=[1, 5, 11, 15, 16, 18]
6060
else
61-
broken_tests[alg_ops[1]] = [1, 5, 15, 16, 18]
61+
broken_tests[alg_ops[1]]=[1, 5, 15, 16, 18]
6262
end
6363

6464
test_on_library(problems, dicts, alg_ops, broken_tests)
6565
end
6666

6767
@testitem "23 Test Problems: SimpleTrustRegion" setup=[RobustnessTesting] tags=[:core] begin
68-
alg_ops = (SimpleTrustRegion(), SimpleTrustRegion(; nlsolve_update_rule = Val(true)))
68+
alg_ops=(SimpleTrustRegion(), SimpleTrustRegion(; nlsolve_update_rule = Val(true)))
6969

70-
broken_tests = Dict(alg => Int[] for alg in alg_ops)
71-
broken_tests[alg_ops[1]] = [3, 15, 16, 21]
72-
broken_tests[alg_ops[2]] = [15, 16]
70+
broken_tests=Dict(alg=>Int[] for alg in alg_ops)
71+
broken_tests[alg_ops[1]]=[3, 15, 16, 21]
72+
broken_tests[alg_ops[2]]=[15, 16]
7373

7474
test_on_library(problems, dicts, alg_ops, broken_tests)
7575
end
7676

7777
@testitem "23 Test Problems: SimpleDFSane" setup=[RobustnessTesting] tags=[:core] begin
78-
alg_ops = (SimpleDFSane(),)
78+
alg_ops=(SimpleDFSane(),)
7979

80-
broken_tests = Dict(alg => Int[] for alg in alg_ops)
80+
broken_tests=Dict(alg=>Int[] for alg in alg_ops)
8181
if Sys.isapple()
82-
broken_tests[alg_ops[1]] = [1, 2, 3, 5, 6, 21]
82+
broken_tests[alg_ops[1]]=[1, 2, 3, 5, 6, 21]
8383
else
84-
broken_tests[alg_ops[1]] = [1, 2, 3, 4, 5, 6, 11, 21]
84+
broken_tests[alg_ops[1]]=[1, 2, 3, 4, 5, 6, 11, 21]
8585
end
8686

8787
test_on_library(problems, dicts, alg_ops, broken_tests)
8888
end
8989

9090
@testitem "23 Test Problems: SimpleBroyden" setup=[RobustnessTesting] tags=[:core] begin
91-
alg_ops = (SimpleBroyden(),)
91+
alg_ops=(SimpleBroyden(),)
9292

93-
broken_tests = Dict(alg => Int[] for alg in alg_ops)
94-
broken_tests[alg_ops[1]] = [1, 5, 11]
93+
broken_tests=Dict(alg=>Int[] for alg in alg_ops)
94+
broken_tests[alg_ops[1]]=[1, 5, 11]
9595

9696
test_on_library(problems, dicts, alg_ops, broken_tests)
9797
end
9898

9999
@testitem "23 Test Problems: SimpleKlement" setup=[RobustnessTesting] tags=[:core] begin
100-
alg_ops = (SimpleKlement(),)
100+
alg_ops=(SimpleKlement(),)
101101

102-
broken_tests = Dict(alg => Int[] for alg in alg_ops)
103-
broken_tests[alg_ops[1]] = [1, 2, 4, 5, 11, 12, 22]
102+
broken_tests=Dict(alg=>Int[] for alg in alg_ops)
103+
broken_tests[alg_ops[1]]=[1, 2, 4, 5, 11, 12, 22]
104104

105105
test_on_library(problems, dicts, alg_ops, broken_tests)
106106
end

test/core/exotic_type_tests.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ end
1717

1818
for alg in [SimpleNewtonRaphson(), SimpleBroyden(), SimpleKlement(), SimpleDFSane(),
1919
SimpleTrustRegion(), SimpleLimitedMemoryBroyden(; threshold = 2), SimpleHalley()]
20-
sol = solve(prob_oop_bf, alg)
20+
sol=solve(prob_oop_bf, alg)
2121
@test norm(sol.resid, Inf) < 1e-6
2222
@test SciMLBase.successful_retcode(sol.retcode)
2323

24-
alg isa SimpleHalley && continue
24+
alg isa SimpleHalley&&continue
2525

26-
sol = solve(prob_iip_bf, alg)
26+
sol=solve(prob_iip_bf, alg)
2727
@test norm(sol.resid, Inf) < 1e-6
2828
@test SciMLBase.successful_retcode(sol.retcode)
2929
end

test/core/forward_ad_tests.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export test_f, test_f!, jacobian_f, solve_with, __compatible
4141
end
4242

4343
@testitem "ForwardDiff.jl Integration: Rootfinding" setup=[ForwardADRootfindingTesting] tags=[:core] begin
44-
@testset "$(nameof(typeof(alg)))" for alg in (
45-
SimpleNewtonRaphson(), SimpleTrustRegion(),
44+
@testset "$(nameof(typeof(alg)))" for alg in
45+
(SimpleNewtonRaphson(), SimpleTrustRegion(),
4646
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
4747
SimpleHalley(), SimpleBroyden(), SimpleKlement(), SimpleDFSane())
4848
us = (2.0, @SVector[1.0, 1.0], [1.0, 1.0], ones(2, 2), @SArray ones(2, 2))
@@ -135,8 +135,8 @@ export loss_function, loss_function!, loss_function_jac, loss_function_vjp,
135135
end
136136

137137
@testitem "ForwardDiff.jl Integration: NLLS" setup=[ForwardADNLLSTesting] tags=[:core] begin
138-
@testset "$(nameof(typeof(alg)))" for alg in (
139-
SimpleNewtonRaphson(), SimpleGaussNewton(),
138+
@testset "$(nameof(typeof(alg)))" for alg in
139+
(SimpleNewtonRaphson(), SimpleGaussNewton(),
140140
SimpleNewtonRaphson(AutoFiniteDiff()), SimpleGaussNewton(AutoFiniteDiff()))
141141
function obj_1(p)
142142
prob_oop = NonlinearLeastSquaresProblem{false}(loss_function, θ_init, p)

0 commit comments

Comments
 (0)