From cf21fcfddbcd9cba05056db13375abd2434a54e8 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 17 Oct 2023 06:11:55 -0400 Subject: [PATCH 1/3] Halley -> SimpleHalley --- src/SimpleNonlinearSolve.jl | 3 +-- src/halley.jl | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/SimpleNonlinearSolve.jl b/src/SimpleNonlinearSolve.jl index 85052e5..9c9c70f 100644 --- a/src/SimpleNonlinearSolve.jl +++ b/src/SimpleNonlinearSolve.jl @@ -88,8 +88,7 @@ PrecompileTools.@compile_workload begin end end -# DiffEq styled algorithms -export Bisection, Brent, Broyden, LBroyden, SimpleDFSane, Falsi, Halley, Klement, +export Bisection, Brent, Broyden, LBroyden, SimpleDFSane, Falsi, SimpleHalley, Klement, Ridder, SimpleNewtonRaphson, SimpleTrustRegion, Alefeld, ITP export BatchedBroyden, BatchedSimpleNewtonRaphson, BatchedSimpleDFSane diff --git a/src/halley.jl b/src/halley.jl index 9e97a57..d307f99 100644 --- a/src/halley.jl +++ b/src/halley.jl @@ -1,6 +1,6 @@ """ ```julia -Halley(; chunk_size = Val{0}(), autodiff = Val{true}(), +SimpleHalley(; chunk_size = Val{0}(), autodiff = Val{true}(), diff_type = Val{:forward}) ``` @@ -28,8 +28,8 @@ and static array problems. `Val{:forward}` for forward finite differences. For more details on the choices, see the [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl) documentation. """ -struct Halley{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT} - function Halley(; chunk_size = Val{0}(), autodiff = Val{true}(), +struct SimpleHalley{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT} + function SimpleHalley(; chunk_size = Val{0}(), autodiff = Val{true}(), diff_type = Val{:forward}) new{SciMLBase._unwrap_val(chunk_size), SciMLBase._unwrap_val(autodiff), SciMLBase._unwrap_val(diff_type)}() @@ -37,7 +37,7 @@ struct Halley{CS, AD, FDT} <: AbstractNewtonAlgorithm{CS, AD, FDT} end function SciMLBase.__solve(prob::NonlinearProblem, - alg::Halley, args...; abstol = nothing, + alg::SimpleHalley, args...; abstol = nothing, reltol = nothing, maxiters = 1000, kwargs...) f = Base.Fix2(prob.f, prob.p) From 9a5b4c7b72db869b4e07630158447d62f28cef40 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 17 Oct 2023 06:16:53 -0400 Subject: [PATCH 2/3] fix naming --- src/SimpleNonlinearSolve.jl | 4 ++-- src/halley.jl | 4 ++-- test/basictests.jl | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/SimpleNonlinearSolve.jl b/src/SimpleNonlinearSolve.jl index 9c9c70f..c5632d7 100644 --- a/src/SimpleNonlinearSolve.jl +++ b/src/SimpleNonlinearSolve.jl @@ -36,7 +36,7 @@ include("ridder.jl") include("brent.jl") include("dfsane.jl") include("ad.jl") -include("halley.jl") +include("SimpleHalley.jl") include("alefeld.jl") include("itp.jl") @@ -64,7 +64,7 @@ import PrecompileTools PrecompileTools.@compile_workload begin for T in (Float32, Float64) prob_no_brack = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2)) - for alg in (SimpleNewtonRaphson, Halley, Broyden, Klement, SimpleTrustRegion, + for alg in (SimpleNewtonRaphson, SimpleHalley, Broyden, Klement, SimpleTrustRegion, SimpleDFSane) solve(prob_no_brack, alg(), abstol = T(1e-2)) end diff --git a/src/halley.jl b/src/halley.jl index d307f99..29cc1e5 100644 --- a/src/halley.jl +++ b/src/halley.jl @@ -4,7 +4,7 @@ SimpleHalley(; chunk_size = Val{0}(), autodiff = Val{true}(), diff_type = Val{:forward}) ``` -A low-overhead implementation of Halley's Method. This method is non-allocating on scalar +A low-overhead implementation of SimpleHalley's Method. This method is non-allocating on scalar and static array problems. !!! note @@ -49,7 +49,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, T = typeof(x) if SciMLBase.isinplace(prob) - error("Halley currently only supports out-of-place nonlinear problems") + error("SimpleHalley currently only supports out-of-place nonlinear problems") end atol = abstol !== nothing ? abstol : diff --git a/test/basictests.jl b/test/basictests.jl index 34468be..027f766 100644 --- a/test/basictests.jl +++ b/test/basictests.jl @@ -56,10 +56,10 @@ if VERSION >= v"1.7" @test (@ballocated benchmark_scalar(sf, csu0)) == 0 end -# Halley +# SimpleHalley function benchmark_scalar(f, u0) probN = NonlinearProblem{false}(f, u0) - sol = (solve(probN, Halley())) + sol = (solve(probN, SimpleHalley())) end function ff(u, p) @@ -139,7 +139,7 @@ using ForwardDiff f, u0 = (u, p) -> u .* u .- p, @SVector[1.0, 1.0] for alg in (SimpleNewtonRaphson(), LBroyden(), Klement(), SimpleTrustRegion(), - SimpleDFSane(), Halley(), BROYDEN_SOLVERS...) + SimpleDFSane(), SimpleHalley(), BROYDEN_SOLVERS...) g = function (p) probN = NonlinearProblem{false}(f, csu0, p) sol = solve(probN, alg, abstol = 1e-9) @@ -162,7 +162,7 @@ end # Scalar f, u0 = (u, p) -> u * u - p, 1.0 for alg in (SimpleNewtonRaphson(), Klement(), SimpleTrustRegion(), - SimpleDFSane(), Halley(), BROYDEN_SOLVERS..., LBROYDEN_SOLVERS...) + SimpleDFSane(), SimpleHalley(), BROYDEN_SOLVERS..., LBROYDEN_SOLVERS...) g = function (p) probN = NonlinearProblem{false}(f, oftype(p, u0), p) sol = solve(probN, alg) @@ -271,7 +271,7 @@ for alg in [Bisection(), Falsi(), Ridder(), Brent(), ITP()] end for alg in (SimpleNewtonRaphson(), Klement(), SimpleTrustRegion(), - SimpleDFSane(), Halley(), BROYDEN_SOLVERS..., LBROYDEN_SOLVERS...) + SimpleDFSane(), SimpleHalley(), BROYDEN_SOLVERS..., LBROYDEN_SOLVERS...) global g, p g = function (p) probN = NonlinearProblem{false}(f, 0.5, p) @@ -288,7 +288,7 @@ probN = NonlinearProblem(f, u0) for alg in (SimpleNewtonRaphson(), SimpleNewtonRaphson(; autodiff = false), SimpleTrustRegion(), - SimpleTrustRegion(; autodiff = false), Halley(), Halley(; autodiff = false), + SimpleTrustRegion(; autodiff = false), SimpleHalley(), SimpleHalley(; autodiff = false), Klement(), SimpleDFSane(), BROYDEN_SOLVERS..., LBROYDEN_SOLVERS...) sol = solve(probN, alg) From 2107cd7e21c72e0e2a14c2f3f0b0e38ab49d81df Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 17 Oct 2023 06:19:41 -0400 Subject: [PATCH 3/3] fix page name --- src/SimpleNonlinearSolve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SimpleNonlinearSolve.jl b/src/SimpleNonlinearSolve.jl index c5632d7..96d76d9 100644 --- a/src/SimpleNonlinearSolve.jl +++ b/src/SimpleNonlinearSolve.jl @@ -36,7 +36,7 @@ include("ridder.jl") include("brent.jl") include("dfsane.jl") include("ad.jl") -include("SimpleHalley.jl") +include("halley.jl") include("alefeld.jl") include("itp.jl")