Skip to content

Commit dc869a9

Browse files
committed
Use dispatch instead of adding Scalar* solvers
1 parent b8e36e7 commit dc869a9

File tree

4 files changed

+4
-20
lines changed

4 files changed

+4
-20
lines changed

src/NonlinearSolve.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module NonlinearSolve
2727

2828
# DiffEq styled algorithms
2929
export Bisection, Falsi, NewtonRaphson
30-
export ScalarBisection, ScalarNewton
3130

3231
export reinit!
3332
end # module

src/scalar.jl

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
"""
2-
ScalarNewton
3-
4-
Fast Newton Raphson for scalar problems.
5-
"""
6-
struct ScalarNewton <: AbstractNonlinearSolveAlgorithm end
7-
8-
function DiffEqBase.solve(prob::NonlinearProblem{uType, false}, ::ScalarNewton, args...; xatol = nothing, xrtol = nothing, maxiters = 1000, kwargs...) where {uType}
1+
function DiffEqBase.solve(prob::NonlinearProblem{<:Number}, ::NewtonRaphson, args...; xatol = nothing, xrtol = nothing, maxiters = 1000, kwargs...)
92
f = Base.Fix2(prob.f, prob.p)
103
x = float(prob.u0)
114
T = typeof(x)
@@ -26,15 +19,7 @@ function DiffEqBase.solve(prob::NonlinearProblem{uType, false}, ::ScalarNewton,
2619
return oftype(x, NaN)
2720
end
2821

29-
"""
30-
ScalarBisection
31-
32-
Fast Bisection for scalar problems. Note that it doesn't returns exact solution, but returns
33-
the best left limit of the exact solution.
34-
"""
35-
struct ScalarBisection <: AbstractNonlinearSolveAlgorithm end
36-
37-
function DiffEqBase.solve(prob::NonlinearProblem{uType, false}, ::ScalarBisection, args...; maxiters = 1000, kwargs...) where {uType}
22+
function DiffEqBase.solve(prob::NonlinearProblem{<:Number}, ::Bisection, args...; maxiters = 1000, kwargs...)
3823
f = Base.Fix2(prob.f, prob.p)
3924
left, right = prob.u0
4025
fl, fr = f(left), f(right)

src/solve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function DiffEqBase.init(prob::NonlinearProblem{uType, iip}, alg::AbstractBracke
1212
immutable = (prob.u0 isa StaticArray || prob.u0 isa Number),
1313
kwargs...
1414
) where {uType, iip}
15-
15+
1616
if !(prob.u0 isa Tuple)
1717
error("You need to pass a tuple of u0 in bracketing algorithms.")
1818
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
function benchmark_scalar(f, u0)
1919
probN = NonlinearProblem{false}(f, u0)
20-
sol = (solve(probN, ScalarNewton()))
20+
sol = (solve(probN, NewtonRaphson()))
2121
end
2222

2323
f, u0 = (u,p) -> u .* u .- 2, @SVector[1.0, 1.0]

0 commit comments

Comments
 (0)