diff --git a/src/scalar.jl b/src/scalar.jl index 60bf61466..742a9e26a 100644 --- a/src/scalar.jl +++ b/src/scalar.jl @@ -8,15 +8,15 @@ function DiffEqBase.solve(prob::NonlinearProblem{<:Number}, ::NewtonRaphson, arg xo = oftype(x, Inf) for i in 1:maxiters fx, dfx = value_derivative(f, x) - iszero(fx) && return x + iszero(fx) && return NewtonSolution(x, :Default) Δx = dfx \ fx x -= Δx if isapprox(x, xo, atol=atol, rtol=rtol) - return x + return NewtonSolution(x, :Default) end xo = x end - return oftype(x, NaN) + return NewtonSolution(x, :MaxitersExceeded) end function DiffEqBase.solve(prob::NonlinearProblem{<:Number}, ::Bisection, args...; maxiters = 1000, kwargs...) diff --git a/src/solve.jl b/src/solve.jl index 2857dd2e1..1b50121ed 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -9,6 +9,7 @@ end function DiffEqBase.init(prob::NonlinearProblem{uType, iip}, alg::AbstractBracketingAlgorithm, args...; alias_u0 = false, maxiters = 1000, + # bracketing algorithms only solve scalar problems immutable = (prob.u0 isa StaticArray || prob.u0 isa Number), kwargs... ) where {uType, iip} diff --git a/test/runtests.jl b/test/runtests.jl index 42ac240eb..51530c0a0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -23,11 +23,14 @@ end f, u0 = (u,p) -> u .* u .- 2, @SVector[1.0, 1.0] sf, su0 = (u,p) -> u * u - 2, 1.0 sol = benchmark_immutable(f, u0) +@test sol.retcode === :Default @test all(sol.u .* sol.u .- 2 .< 1e-9) sol = benchmark_mutable(f, u0) +@test sol.retcode === :Default @test all(sol.u .* sol.u .- 2 .< 1e-9) sol = benchmark_scalar(sf, su0) -@test sol * sol - 2 < 1e-9 +@test sol.retcode === :Default +@test sol.u * sol.u - 2 < 1e-9 @test (@ballocated benchmark_immutable($f, $u0)) == 0 @test (@ballocated benchmark_mutable($f, $u0)) < 200