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

Commit b9aff11

Browse files
committed
Add some tests
1 parent 4bc5f24 commit b9aff11

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SimpleNonlinearSolve"
22
uuid = "727e6d20-b764-4bd8-a329-72de5adea6c7"
33
authors = ["SciML"]
4-
version = "0.1.10"
4+
version = "0.1.11"
55

66
[deps]
77
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"

src/lbroyden.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
LBroyden(threshold::Int = 27)
3+
4+
A limited memory implementation of Broyden. This method applies the L-BFGS scheme to
5+
Broyden's method.
6+
"""
17
Base.@kwdef struct LBroyden <: AbstractSimpleNonlinearSolveAlgorithm
28
threshold::Int = 27
39
end
@@ -57,7 +63,7 @@ end
5763

5864
vᵀ = _rmatvec(_U, _Vᵀ, Δxₙ)
5965
mvec = _matvec(_U, _Vᵀ, Δfₙ)
60-
Δxₙ = (Δxₙ .- mvec) ./ (sum(vᵀ .* Δfₙ) .+ eps(T))
66+
Δxₙ = (Δxₙ .- mvec) ./ (sum(vᵀ .* Δfₙ) .+ convert(T, 1e-5))
6167

6268
Vᵀ[:, mod1(i, threshold)] .= vᵀ
6369
U[mod1(i, threshold), :] .= Δxₙ

test/basictests.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ using ForwardDiff
7878
# Immutable
7979
f, u0 = (u, p) -> u .* u .- p, @SVector[1.0, 1.0]
8080

81-
for alg in (SimpleNewtonRaphson(), Broyden(), Klement(), SimpleTrustRegion(),
81+
for alg in (SimpleNewtonRaphson(), Broyden(), LBroyden(), Klement(), SimpleTrustRegion(),
8282
SimpleDFSane())
8383
g = function (p)
8484
probN = NonlinearProblem{false}(f, csu0, p)
@@ -94,7 +94,7 @@ end
9494

9595
# Scalar
9696
f, u0 = (u, p) -> u * u - p, 1.0
97-
for alg in (SimpleNewtonRaphson(), Broyden(), Klement(), SimpleTrustRegion(),
97+
for alg in (SimpleNewtonRaphson(), Broyden(), LBroyden(), Klement(), SimpleTrustRegion(),
9898
SimpleDFSane())
9999
g = function (p)
100100
probN = NonlinearProblem{false}(f, oftype(p, u0), p)
@@ -160,7 +160,7 @@ for alg in [Bisection(), Falsi(), Ridder(), Brent()]
160160
@test ForwardDiff.jacobian(g, p) ForwardDiff.jacobian(t, p)
161161
end
162162

163-
for alg in (SimpleNewtonRaphson(), Broyden(), Klement(), SimpleTrustRegion(),
163+
for alg in (SimpleNewtonRaphson(), Broyden(), LBroyden(), Klement(), SimpleTrustRegion(),
164164
SimpleDFSane())
165165
global g, p
166166
g = function (p)
@@ -181,6 +181,7 @@ probN = NonlinearProblem(f, u0)
181181
@test solve(probN, SimpleTrustRegion()).u[end] sqrt(2.0)
182182
@test solve(probN, SimpleTrustRegion(; autodiff = false)).u[end] sqrt(2.0)
183183
@test solve(probN, Broyden()).u[end] sqrt(2.0)
184+
@test solve(probN, LBroyden()).u[end] sqrt(2.0)
184185
@test solve(probN, Klement()).u[end] sqrt(2.0)
185186
@test solve(probN, SimpleDFSane()).u[end] sqrt(2.0)
186187

@@ -199,6 +200,7 @@ for u0 in [1.0, [1, 1.0]]
199200
@test solve(probN, SimpleTrustRegion(; autodiff = false)).u sol
200201

201202
@test solve(probN, Broyden()).u sol
203+
@test solve(probN, LBroyden()).u sol
202204
@test solve(probN, Klement()).u sol
203205
@test solve(probN, SimpleDFSane()).u sol
204206
end

0 commit comments

Comments
 (0)