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

Commit 7fff540

Browse files
committed
Cleanup
1 parent be9e2d2 commit 7fff540

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/SimpleNonlinearSolve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Reexport
44
using FiniteDiff, ForwardDiff
55
using ForwardDiff: Dual
66
using StaticArraysCore
7-
using LinearAlgebra # TODO check if it is ok to add this
7+
using LinearAlgebra
88
import ArrayInterfaceCore
99

1010
@reexport using SciMLBase

src/broyden.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
# TODO add docstrings
1+
"""
2+
```julia
3+
Broyden()
4+
```
5+
6+
A low-overhead implementation of Broyden. This method is non-allocating on scalar
7+
and static array problems.
8+
"""
29

3-
# TODO check what the supertype should be
4-
# TODO check if this should be defined as in raphson.jl
510
struct Broyden <: AbstractSimpleNonlinearSolveAlgorithm end
611

712
function SciMLBase.solve(prob::NonlinearProblem,
8-
alg::Broyden, args...; abstol = nothing,
9-
reltol = nothing,
10-
maxiters = 1000, kwargs...)
11-
13+
alg::Broyden, args...; abstol = nothing,
14+
reltol = nothing,
15+
maxiters = 1000, kwargs...)
1216
f = Base.Fix2(prob.f, prob.p)
1317
x = float(prob.u0)
1418
fₙ = f(x)
@@ -30,8 +34,7 @@ function SciMLBase.solve(prob::NonlinearProblem,
3034
xₙ = x
3135
xₙ₋₁ = x
3236
fₙ₋₁ = fₙ
33-
for n in 1:maxiters
34-
37+
for _ in 1:maxiters
3538
xₙ = xₙ₋₁ - J⁻¹ * fₙ₋₁
3639
fₙ = f(xₙ)
3740
Δxₙ = xₙ - xₙ₋₁

test/basictests.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ end
5757
# Scalar
5858
f, u0 = (u, p) -> u * u - p, 1.0
5959
for alg in [SimpleNewtonRaphson(), Broyden()]
60-
6160
g = function (p)
6261
probN = NonlinearProblem{false}(f, oftype(p, u0), p)
6362
sol = solve(probN, alg)
6463
return sol.u
6564
end
6665

67-
p = 1.1
68-
@test ForwardDiff.derivative(g, p) 1 / (2 * sqrt(p))
69-
7066
for p in 1.1:0.1:100.0
7167
@test g(p) sqrt(p)
7268
@test ForwardDiff.derivative(g, p) 1 / (2 * sqrt(p))
@@ -120,7 +116,7 @@ probN = NonlinearProblem(f, u0)
120116
@test solve(probN, SimpleNewtonRaphson(); immutable = false).u[end] sqrt(2.0)
121117
@test solve(probN, SimpleNewtonRaphson(; autodiff = false)).u[end] sqrt(2.0)
122118
@test solve(probN, SimpleNewtonRaphson(; autodiff = false)).u[end] sqrt(2.0)
123-
# TODO check why the 2 lines above are identical
119+
124120
@test solve(probN, Broyden()).u[end] sqrt(2.0)
125121
@test solve(probN, Broyden(); immutable = false).u[end] sqrt(2.0)
126122

@@ -130,10 +126,10 @@ for u0 in [1.0, [1, 1.0]]
130126
probN = NonlinearProblem(f, u0)
131127
sol = sqrt(2) * u0
132128

133-
# TODO check why the two lines below are identical
134129
@test solve(probN, SimpleNewtonRaphson()).u sol
135130
@test solve(probN, SimpleNewtonRaphson()).u sol
136131
@test solve(probN, SimpleNewtonRaphson(; autodiff = false)).u sol
132+
137133
@test solve(probN, Broyden()).u sol
138134
end
139135

0 commit comments

Comments
 (0)