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

Commit 5c569ae

Browse files
Merge pull request #99 from FHoltorf/TR
SimpleTrustRegion bug
2 parents a65354a + f35fafe commit 5c569ae

21 files changed

+118
-117
lines changed

ext/SimpleNonlinearSolveNNlibExt.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ function __init__()
1010
end
1111

1212
@views function SciMLBase.__solve(prob::NonlinearProblem,
13-
alg::BatchedBroyden;
14-
abstol = nothing,
15-
reltol = nothing,
16-
maxiters = 1000,
17-
kwargs...)
13+
alg::BatchedBroyden;
14+
abstol = nothing,
15+
reltol = nothing,
16+
maxiters = 1000,
17+
kwargs...)
1818
iip = isinplace(prob)
1919

2020
u, f, reconstruct = _construct_batched_problem_structure(prob)

src/SimpleNonlinearSolve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function SciMLBase.solve(prob::IntervalNonlinearProblem; kwargs...)
5050
end
5151

5252
function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Nothing,
53-
args...; kwargs...)
53+
args...; kwargs...)
5454
SciMLBase.solve(prob, ITP(), args...; kwargs...)
5555
end
5656

src/ad.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ function scalar_nlsolve_ad(prob, alg, args...; kwargs...)
2929
end
3030

3131
function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector},
32-
iip,
33-
<:Dual{T, V, P}},
34-
alg::AbstractSimpleNonlinearSolveAlgorithm,
35-
args...; kwargs...) where {iip, T, V, P}
32+
iip,
33+
<:Dual{T, V, P}},
34+
alg::AbstractSimpleNonlinearSolveAlgorithm,
35+
args...; kwargs...) where {iip, T, V, P}
3636
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
3737
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid;
3838
retcode = sol.retcode)
3939
end
4040
function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector},
41-
iip,
42-
<:AbstractArray{<:Dual{T, V, P}}},
43-
alg::AbstractSimpleNonlinearSolveAlgorithm, args...;
44-
kwargs...) where {iip, T, V, P}
41+
iip,
42+
<:AbstractArray{<:Dual{T, V, P}}},
43+
alg::AbstractSimpleNonlinearSolveAlgorithm, args...;
44+
kwargs...) where {iip, T, V, P}
4545
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
4646
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid;
4747
retcode = sol.retcode)
@@ -50,9 +50,9 @@ end
5050
# avoid ambiguities
5151
for Alg in [Bisection]
5252
@eval function SciMLBase.solve(prob::IntervalNonlinearProblem{uType, iip,
53-
<:Dual{T, V, P}},
54-
alg::$Alg, args...;
55-
kwargs...) where {uType, iip, T, V, P}
53+
<:Dual{T, V, P}},
54+
alg::$Alg, args...;
55+
kwargs...) where {uType, iip, T, V, P}
5656
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
5757
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials),
5858
sol.resid; retcode = sol.retcode,
@@ -61,13 +61,13 @@ for Alg in [Bisection]
6161
#return BracketingSolution(Dual{T,V,P}(sol.left, partials), Dual{T,V,P}(sol.right, partials), sol.retcode, sol.resid)
6262
end
6363
@eval function SciMLBase.solve(prob::IntervalNonlinearProblem{uType, iip,
64-
<:AbstractArray{
65-
<:Dual{T,
66-
V,
67-
P},
68-
}},
69-
alg::$Alg, args...;
70-
kwargs...) where {uType, iip, T, V, P}
64+
<:AbstractArray{
65+
<:Dual{T,
66+
V,
67+
P},
68+
}},
69+
alg::$Alg, args...;
70+
kwargs...) where {uType, iip, T, V, P}
7171
sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)
7272
return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials),
7373
sol.resid; retcode = sol.retcode,

src/alefeld.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ algorithm 4.1 because, in certain sense, the second algorithm(4.2) is an optimal
99
struct Alefeld <: AbstractBracketingAlgorithm end
1010

1111
function SciMLBase.solve(prob::IntervalNonlinearProblem,
12-
alg::Alefeld, args...; abstol = nothing,
13-
reltol = nothing,
14-
maxiters = 1000, kwargs...)
12+
alg::Alefeld, args...; abstol = nothing,
13+
reltol = nothing,
14+
maxiters = 1000, kwargs...)
1515
f = Base.Fix2(prob.f, prob.p)
1616
a, b = prob.tspan
1717
c = a - (b - a) / (f(b) - f(a)) * f(a)

src/batched/dfsane.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ Base.@kwdef struct BatchedSimpleDFSane{T, F, TC <: NLSolveTerminationCondition}
1616
end
1717

1818
function SciMLBase.__solve(prob::NonlinearProblem,
19-
alg::BatchedSimpleDFSane,
20-
args...;
21-
abstol = nothing,
22-
reltol = nothing,
23-
maxiters = 100,
24-
kwargs...)
19+
alg::BatchedSimpleDFSane,
20+
args...;
21+
abstol = nothing,
22+
reltol = nothing,
23+
maxiters = 100,
24+
kwargs...)
2525
iip = isinplace(prob)
2626

2727
u, f, reconstruct = _construct_batched_problem_structure(prob)

src/batched/raphson.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ alg_autodiff(alg::BatchedSimpleNewtonRaphson{CS, AD, FDT}) where {CS, AD, FDT} =
77
diff_type(alg::BatchedSimpleNewtonRaphson{CS, AD, FDT}) where {CS, AD, FDT} = FDT
88

99
function BatchedSimpleNewtonRaphson(; chunk_size = Val{0}(),
10-
autodiff = Val{true}(),
11-
diff_type = Val{:forward},
12-
termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault;
13-
abstol = nothing,
14-
reltol = nothing))
10+
autodiff = Val{true}(),
11+
diff_type = Val{:forward},
12+
termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault;
13+
abstol = nothing,
14+
reltol = nothing))
1515
return BatchedSimpleNewtonRaphson{SciMLBase._unwrap_val(chunk_size),
1616
SciMLBase._unwrap_val(autodiff),
1717
SciMLBase._unwrap_val(diff_type), typeof(termination_condition)}(termination_condition)
1818
end
1919

2020
function SciMLBase.__solve(prob::NonlinearProblem, alg::BatchedSimpleNewtonRaphson;
21-
abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...)
21+
abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...)
2222
iip = SciMLBase.isinplace(prob)
2323
iip &&
2424
@assert alg_autodiff(alg) "Inplace BatchedSimpleNewtonRaphson currently only supports autodiff."

src/batched/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ function _construct_batched_problem_structure(prob)
2727
end
2828

2929
function _construct_batched_problem_structure(u0::AbstractArray{T, N},
30-
f,
31-
p,
32-
::Val{iip}) where {T, N, iip}
30+
f,
31+
p,
32+
::Val{iip}) where {T, N, iip}
3333
# Reconstruct `u`
3434
reconstruct = N == 2 ? identity : Base.Fix2(reshape, size(u0))
3535
# Standardize `u`

src/bisection.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function Bisection(; exact_left = false, exact_right = false)
2020
end
2121

2222
function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Bisection, args...;
23-
maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])),
24-
kwargs...)
23+
maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])),
24+
kwargs...)
2525
f = Base.Fix2(prob.f, prob.p)
2626
left, right = prob.tspan
2727
fl, fr = f(left), f(right)

src/brent.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ A non-allocating Brent method
77
struct Brent <: AbstractBracketingAlgorithm end
88

99
function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Brent, args...;
10-
maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])),
11-
kwargs...)
10+
maxiters = 1000, abstol = min(eps(prob.tspan[1]), eps(prob.tspan[2])),
11+
kwargs...)
1212
f = Base.Fix2(prob.f, prob.p)
1313
a, b = prob.tspan
1414
fa, fb = f(a), f(b)

src/broyden.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ struct Broyden{TC <: NLSolveTerminationCondition} <:
1818
end
1919

2020
function Broyden(; batched = false,
21-
termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault;
22-
abstol = nothing,
23-
reltol = nothing))
21+
termination_condition = NLSolveTerminationCondition(NLSolveTerminationMode.NLSolveDefault;
22+
abstol = nothing,
23+
reltol = nothing))
2424
if batched
2525
@assert NNlibExtLoaded[] "Please install and load `NNlib.jl` to use batched Broyden."
2626
return BatchedBroyden(termination_condition)
@@ -29,7 +29,7 @@ function Broyden(; batched = false,
2929
end
3030

3131
function SciMLBase.__solve(prob::NonlinearProblem, alg::Broyden, args...;
32-
abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...)
32+
abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...)
3333
tc = alg.termination_condition
3434
mode = DiffEqBase.get_termination_mode(tc)
3535
f = Base.Fix2(prob.f, prob.p)

0 commit comments

Comments
 (0)