Skip to content

Commit 62d29be

Browse files
committed
Fix SimpleNonlinearSolve CI
1 parent d8ae329 commit 62d29be

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

lib/BracketingNonlinearSolve/src/muller.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ initial guesses `(left, middle, right)` for the root.
88
99
### Keyword Arguments
1010
11-
- `middle`: the initial guess for the middle point. If not provided, the
12-
midpoint of the interval `(left, right)` is used.
11+
- `middle`: the initial guess for the middle point. If not provided, the
12+
midpoint of the interval `(left, right)` is used.
1313
"""
1414
struct Muller{T} <: AbstractBracketingAlgorithm
1515
middle::T
@@ -18,7 +18,7 @@ end
1818
Muller() = Muller(nothing)
1919

2020
function CommonSolve.solve(prob::IntervalNonlinearProblem, alg::Muller, args...;
21-
abstol = nothing, maxiters = 1000, kwargs...)
21+
abstol = nothing, maxiters = 1000, kwargs...)
2222
@assert !SciMLBase.isinplace(prob) "`Muller` only supports out-of-place problems."
2323
xᵢ₋₂, xᵢ = prob.tspan
2424
xᵢ₋₁ = isnothing(alg.middle) ? (xᵢ₋₂ + xᵢ) / 2 : alg.middle
@@ -32,35 +32,35 @@ function CommonSolve.solve(prob::IntervalNonlinearProblem, alg::Muller, args...;
3232
abstol = abs(NonlinearSolveBase.get_tolerance(
3333
xᵢ₋₂, abstol, promote_type(eltype(xᵢ₋₂), eltype(xᵢ))))
3434

35-
for _ 1:maxiters
36-
q = (xᵢ - xᵢ₋₁)/(xᵢ₋₁ - xᵢ₋₂)
37-
A = q*fxᵢ - q*(1 + q)*fxᵢ₋₁ + q^2*fxᵢ₋₂
38-
B = (2*q + 1)*fxᵢ - (1 + q)^2*fxᵢ₋₁ + q^2*fxᵢ₋₂
39-
C = (1 + q)*fxᵢ
35+
for _ in 1:maxiters
36+
q = (xᵢ - xᵢ₋₁) / (xᵢ₋₁ - xᵢ₋₂)
37+
A = q * fxᵢ - q * (1 + q) * fxᵢ₋₁ + q^2 * fxᵢ₋₂
38+
B = (2 * q + 1) * fxᵢ - (1 + q)^2 * fxᵢ₋₁ + q^2 * fxᵢ₋₂
39+
C = (1 + q) * fxᵢ
4040

41-
denom₊ = B + (B^2 - 4*A*C)
42-
denom₋ = B - (B^2 - 4*A*C)
41+
denom₊ = B + (B^2 - 4 * A * C)
42+
denom₋ = B - (B^2 - 4 * A * C)
4343

4444
if abs(denom₊) abs(denom₋)
45-
xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁)*2*C/denom₊
45+
xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁) * 2 * C / denom₊
4646
else
47-
xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁)*2*C/denom₋
47+
xᵢ₊₁ = xᵢ - (xᵢ - xᵢ₋₁) * 2 * C / denom₋
4848
end
4949

5050
fxᵢ₊₁ = f(xᵢ₊₁)
5151

5252
# Termination Check
5353
if abstol abs(fxᵢ₊₁)
5454
return SciMLBase.build_solution(prob, alg, xᵢ₊₁, fxᵢ₊₁;
55-
retcode = ReturnCode.Success,
56-
left = xᵢ₊₁, right = xᵢ₊₁)
55+
retcode = ReturnCode.Success,
56+
left = xᵢ₊₁, right = xᵢ₊₁)
5757
end
5858

5959
xᵢ₋₂, xᵢ₋₁, xᵢ = xᵢ₋₁, xᵢ, xᵢ₊₁
6060
fxᵢ₋₂, fxᵢ₋₁, fxᵢ = fxᵢ₋₁, fxᵢ, fxᵢ₊₁
6161
end
6262

6363
return SciMLBase.build_solution(prob, alg, xᵢ₊₁, fxᵢ₊₁;
64-
retcode = ReturnCode.MaxIters,
65-
left = xᵢ₊₁, right = xᵢ₊₁)
64+
retcode = ReturnCode.MaxIters,
65+
left = xᵢ₊₁, right = xᵢ₊₁)
6666
end

lib/BracketingNonlinearSolve/test/muller_tests.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testitem "Muller" begin
22
f(u, p) = u^2 - p
33
g(u, p) = sin(u)
4-
h(u, p) = exp(-u)*sin(u)
4+
h(u, p) = exp(-u) * sin(u)
55
i(u, p) = u^3 - 1
66

77
@testset "Quadratic function" begin
@@ -30,7 +30,7 @@
3030
prob = IntervalNonlinearProblem{false}(g, tspan)
3131
sol = solve(prob, Muller())
3232

33-
@test sol.u 2*π
33+
@test sol.u 2 * π
3434
end
3535

3636
@testset "Exponential-sine function" begin
@@ -44,7 +44,7 @@
4444
prob = IntervalNonlinearProblem{false}(h, tspan)
4545
sol = solve(prob, Muller())
4646

47-
@test sol.u 0 atol = 1e-15
47+
@test sol.u0 atol=1e-15
4848

4949
tspan = (-1.0, 1.0)
5050
prob = IntervalNonlinearProblem{false}(h, tspan)
@@ -54,17 +54,17 @@
5454
end
5555

5656
@testset "Complex roots" begin
57-
tspan = (-1.0, 1.0*im)
57+
tspan = (-1.0, 1.0 * im)
5858
prob = IntervalNonlinearProblem{false}(i, tspan)
5959
sol = solve(prob, Muller())
6060

61-
@test sol.u (-1 + 3*im)/2
61+
@test sol.u (-1 + 3 * im) / 2
6262

63-
tspan = (-1.0, -1.0*im)
63+
tspan = (-1.0, -1.0 * im)
6464
prob = IntervalNonlinearProblem{false}(i, tspan)
6565
sol = solve(prob, Muller())
6666

67-
@test sol.u (-1 - 3*im)/2
67+
@test sol.u (-1 - 3 * im) / 2
6868
end
6969

7070
@testset "Middle" begin
@@ -87,10 +87,10 @@
8787

8888
@test sol.u -π
8989

90-
tspan = (-1.0, 1.0*im)
90+
tspan = (-1.0, 1.0 * im)
9191
prob = IntervalNonlinearProblem{false}(i, tspan)
9292
sol = solve(prob, Muller(0.0))
9393

94-
@test sol.u (-1 + 3*im)/2
94+
@test sol.u (-1 + 3 * im) / 2
9595
end
9696
end

lib/BracketingNonlinearSolve/test/rootfind_tests.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ end
77
@testitem "Interval Nonlinear Problems" setup=[RootfindingTestSnippet] tags=[:core] begin
88
using ForwardDiff
99

10-
@testset for alg in (Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing)
10+
@testset for alg in (
11+
Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing)
1112
tspan = (1.0, 20.0)
1213

1314
function g(p)
@@ -76,7 +77,8 @@ end
7677
end
7778

7879
@testitem "Flipped Signs and Reversed Tspan" setup=[RootfindingTestSnippet] tags=[:core] begin
79-
@testset for alg in (Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing)
80+
@testset for alg in (
81+
Alefeld(), Bisection(), Brent(), Falsi(), ITP(), Muller(), Ridder(), nothing)
8082
f1(u, p) = u * u - p
8183
f2(u, p) = p - u * u
8284

lib/SimpleNonlinearSolve/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ NonlinearSolveBase = "be0214bd-f91f-a760-ac4e-3421ce2b2da0"
2020
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
2121
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2222
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
23+
SciMLJacobianOperators = "19f34311-ddf3-4b8b-af20-060888a46c0e"
2324
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2425
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
2526

lib/SimpleNonlinearSolve/src/halley.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function SciMLBase.__solve(
7474
end
7575

7676
aᵢ = J_fact \ NLBUtils.safe_vec(fx)
77-
hvvp = Utils.compute_hvvp(prob, autodiff, fx_cache, x, aᵢ)
77+
hvvp = Utils.compute_hvvp(prob, autodiff, fx_cache, NLBUtils.safe_vec(x), aᵢ)
7878
bᵢ = J_fact \ NLBUtils.safe_vec(hvvp)
7979

8080
cᵢ_ = NLBUtils.safe_vec(cᵢ)

lib/SimpleNonlinearSolve/src/utils.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,13 @@ function compute_hvvp(prob, autodiff, fx, x, dir)
166166
jvp_fn = if SciMLBase.isinplace(prob)
167167
@closure (u, p) -> begin
168168
du = NLBUtils.safe_similar(fx, promote_type(eltype(fx), eltype(u)))
169-
return only(DI.pushforward(prob.f, du, autodiff, u, (dir,), Constant(p)))
169+
return only(DI.pushforward(
170+
prob.f, NLBUtils.safe_vec(du), autodiff, u, (dir,), Constant(p)))
170171
end
171172
else
172173
@closure (u, p) -> only(DI.pushforward(prob.f, autodiff, u, (dir,), Constant(p)))
173174
end
174-
only(DI.pushforward(jvp_fn, autodiff, x, (dir,), Constant(prob.p)))
175+
only(DI.pushforward(jvp_fn, autodiff, x, (dir,), Constant(NLBUtils.safe_vec(prob.p))))
175176
end
176177

177178
end

0 commit comments

Comments
 (0)