Skip to content

Commit 63418b8

Browse files
committed
Always return a solution type
1 parent dc869a9 commit 63418b8

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/scalar.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ function DiffEqBase.solve(prob::NonlinearProblem{<:Number}, ::NewtonRaphson, arg
88
xo = oftype(x, Inf)
99
for i in 1:maxiters
1010
fx, dfx = value_derivative(f, x)
11-
iszero(fx) && return x
11+
iszero(fx) && return NewtonSolution(x, :Default)
1212
Δx = dfx \ fx
1313
x -= Δx
1414
if isapprox(x, xo, atol=atol, rtol=rtol)
15-
return x
15+
return NewtonSolution(x, :Default)
1616
end
1717
xo = x
1818
end
19-
return oftype(x, NaN)
19+
return NewtonSolution(x, :MaxitersExceeded)
2020
end
2121

22-
function DiffEqBase.solve(prob::NonlinearProblem{<:Number}, ::Bisection, args...; maxiters = 1000, kwargs...)
22+
function DiffEqBase.solve(prob::NonlinearProblem, ::Bisection, args...; maxiters = 1000, kwargs...)
2323
f = Base.Fix2(prob.f, prob.p)
2424
left, right = prob.u0
2525
fl, fr = f(left), f(right)

src/solve.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ end
99
function DiffEqBase.init(prob::NonlinearProblem{uType, iip}, alg::AbstractBracketingAlgorithm, args...;
1010
alias_u0 = false,
1111
maxiters = 1000,
12+
# bracketing algorithms only solve scalar problems
1213
immutable = (prob.u0 isa StaticArray || prob.u0 isa Number),
1314
kwargs...
1415
) where {uType, iip}

test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ end
2323
f, u0 = (u,p) -> u .* u .- 2, @SVector[1.0, 1.0]
2424
sf, su0 = (u,p) -> u * u - 2, 1.0
2525
sol = benchmark_immutable(f, u0)
26+
@test sol.retcode === :Default
2627
@test all(sol.u .* sol.u .- 2 .< 1e-9)
2728
sol = benchmark_mutable(f, u0)
29+
@test sol.retcode === :Default
2830
@test all(sol.u .* sol.u .- 2 .< 1e-9)
2931
sol = benchmark_scalar(sf, su0)
30-
@test sol * sol - 2 < 1e-9
32+
@test sol.retcode === :Default
33+
@test sol.u * sol.u - 2 < 1e-9
3134

3235
@test (@ballocated benchmark_immutable($f, $u0)) == 0
3336
@test (@ballocated benchmark_mutable($f, $u0)) < 200

0 commit comments

Comments
 (0)