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

Commit 2893a8e

Browse files
Merge pull request #27 from SciML/base
Use DiffEqBase high level handling
2 parents 9aab971 + 0d593de commit 2893a8e

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.1.5"
55

66
[deps]
77
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
8+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
89
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
910
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1011
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -15,6 +16,7 @@ StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1516

1617
[compat]
1718
ArrayInterfaceCore = "0.1.1"
19+
DiffEqBase = "6.114"
1820
FiniteDiff = "2"
1921
ForwardDiff = "0.10.3"
2022
Reexport = "0.2, 1"

src/SimpleNonlinearSolve.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using ForwardDiff: Dual
66
using StaticArraysCore
77
using LinearAlgebra
88
import ArrayInterfaceCore
9+
using DiffEqBase
910

1011
@reexport using SciMLBase
1112

@@ -28,11 +29,11 @@ import SnoopPrecompile
2829
SnoopPrecompile.@precompile_all_calls begin for T in (Float32, Float64)
2930
prob_no_brack = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2))
3031
for alg in (SimpleNewtonRaphson, Broyden, Klement)
31-
solve(prob_no_brack, alg(), tol = T(1e-2))
32+
solve(prob_no_brack, alg(), abstol = T(1e-2))
3233
end
3334

3435
for alg in (TrustRegion(10.0),)
35-
solve(prob_no_brack, alg, tol = T(1e-2))
36+
solve(prob_no_brack, alg, abstol = T(1e-2))
3637
end
3738

3839
#=
@@ -47,7 +48,7 @@ SnoopPrecompile.@precompile_all_calls begin for T in (Float32, Float64)
4748

4849
prob_brack = IntervalNonlinearProblem{false}((u, p) -> u * u - p, T.((0.0, 2.0)), T(2))
4950
for alg in (Bisection, Falsi)
50-
solve(prob_brack, alg(), tol = T(1e-2))
51+
solve(prob_brack, alg(), abstol = T(1e-2))
5152
end
5253
end end
5354

src/broyden.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ and static array problems.
88
"""
99
struct Broyden <: AbstractSimpleNonlinearSolveAlgorithm end
1010

11-
function SciMLBase.solve(prob::NonlinearProblem,
12-
alg::Broyden, args...; abstol = nothing,
13-
reltol = nothing,
14-
maxiters = 1000, kwargs...)
11+
function SciMLBase.__solve(prob::NonlinearProblem,
12+
alg::Broyden, args...; abstol = nothing,
13+
reltol = nothing,
14+
maxiters = 1000, kwargs...)
1515
f = Base.Fix2(prob.f, prob.p)
1616
x = float(prob.u0)
1717
fₙ = f(x)

src/klement.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ This method is non-allocating on scalar problems.
88
"""
99
struct Klement <: AbstractSimpleNonlinearSolveAlgorithm end
1010

11-
function SciMLBase.solve(prob::NonlinearProblem,
12-
alg::Klement, args...; abstol = nothing,
13-
reltol = nothing,
14-
maxiters = 1000, kwargs...)
11+
function SciMLBase.__solve(prob::NonlinearProblem,
12+
alg::Klement, args...; abstol = nothing,
13+
reltol = nothing,
14+
maxiters = 1000, kwargs...)
1515
f = Base.Fix2(prob.f, prob.p)
1616
x = float(prob.u0)
1717
fₙ = f(x)

src/raphson.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ struct SimpleNewtonRaphson{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT}
3636
end
3737
end
3838

39-
function SciMLBase.solve(prob::NonlinearProblem,
40-
alg::SimpleNewtonRaphson, args...; abstol = nothing,
41-
reltol = nothing,
42-
maxiters = 1000, kwargs...)
39+
function SciMLBase.__solve(prob::NonlinearProblem,
40+
alg::SimpleNewtonRaphson, args...; abstol = nothing,
41+
reltol = nothing,
42+
maxiters = 1000, kwargs...)
4343
f = Base.Fix2(prob.f, prob.p)
4444
x = float(prob.u0)
4545
fx = float(prob.u0)

src/trustRegion.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ struct TrustRegion{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT}
7777
end
7878
end
7979

80-
function SciMLBase.solve(prob::NonlinearProblem,
81-
alg::TrustRegion, args...; abstol = nothing,
82-
reltol = nothing,
83-
maxiters = 1000, kwargs...)
80+
function SciMLBase.__solve(prob::NonlinearProblem,
81+
alg::TrustRegion, args...; abstol = nothing,
82+
reltol = nothing,
83+
maxiters = 1000, kwargs...)
8484
f = Base.Fix2(prob.f, prob.p)
8585
x = float(prob.u0)
8686
T = typeof(x)

test/basictests.jl

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ sol = benchmark_scalar(sf, csu0)
2222
@test sol.retcode === ReturnCode.Success
2323
@test sol.u * sol.u - 2 < 1e-9
2424

25-
@test (@ballocated benchmark_scalar(sf, csu0)) == 0
25+
if VERSION >= v"1.7"
26+
@test (@ballocated benchmark_scalar(sf, csu0)) == 0
27+
end
2628

2729
# Broyden
2830
function benchmark_scalar(f, u0)
@@ -33,7 +35,9 @@ end
3335
sol = benchmark_scalar(sf, csu0)
3436
@test sol.retcode === ReturnCode.Success
3537
@test sol.u * sol.u - 2 < 1e-9
36-
@test (@ballocated benchmark_scalar(sf, csu0)) == 0
38+
if VERSION >= v"1.7"
39+
@test (@ballocated benchmark_scalar(sf, csu0)) == 0
40+
end
3741

3842
# Klement
3943
function benchmark_scalar(f, u0)
@@ -44,7 +48,9 @@ end
4448
sol = benchmark_scalar(sf, csu0)
4549
@test sol.retcode === ReturnCode.Success
4650
@test sol.u * sol.u - 2 < 1e-9
47-
@test (@ballocated benchmark_scalar(sf, csu0)) == 0
51+
if VERSION >= v"1.7"
52+
@test (@ballocated benchmark_scalar(sf, csu0)) == 0
53+
end
4854

4955
# TrustRegion
5056
function benchmark_scalar(f, u0)
@@ -66,7 +72,7 @@ for alg in [SimpleNewtonRaphson(), Broyden(), Klement(),
6672
TrustRegion(10.0)]
6773
g = function (p)
6874
probN = NonlinearProblem{false}(f, csu0, p)
69-
sol = solve(probN, alg, tol = 1e-9)
75+
sol = solve(probN, alg, abstol = 1e-9)
7076
return sol.u[end]
7177
end
7278

@@ -137,20 +143,11 @@ f, u0 = (u, p) -> u .* u .- 2.0, @SVector[1.0, 1.0]
137143
probN = NonlinearProblem(f, u0)
138144

139145
@test solve(probN, SimpleNewtonRaphson()).u[end] sqrt(2.0)
140-
@test solve(probN, SimpleNewtonRaphson(); immutable = false).u[end] sqrt(2.0)
141-
@test solve(probN, SimpleNewtonRaphson(; autodiff = false)).u[end] sqrt(2.0)
142146
@test solve(probN, SimpleNewtonRaphson(; autodiff = false)).u[end] sqrt(2.0)
143-
144147
@test solve(probN, TrustRegion(10.0)).u[end] sqrt(2.0)
145-
@test solve(probN, TrustRegion(10.0); immutable = false).u[end] sqrt(2.0)
146-
@test solve(probN, TrustRegion(10.0; autodiff = false)).u[end] sqrt(2.0)
147148
@test solve(probN, TrustRegion(10.0; autodiff = false)).u[end] sqrt(2.0)
148-
149149
@test solve(probN, Broyden()).u[end] sqrt(2.0)
150-
@test solve(probN, Broyden(); immutable = false).u[end] sqrt(2.0)
151-
152150
@test solve(probN, Klement()).u[end] sqrt(2.0)
153-
@test solve(probN, Klement(); immutable = false).u[end] sqrt(2.0)
154151

155152
for u0 in [1.0, [1, 1.0]]
156153
local f, probN, sol

0 commit comments

Comments
 (0)