@@ -7,10 +7,30 @@ function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, <:AbstractArray}
77 sol. original)
88end
99
10- function __nlsolve_ad (prob:: NonlinearProblem{uType, iip} , alg, args... ;
11- kwargs... ) where {uType, iip}
10+ # Handle Ambiguities
11+ for algType in (Bisection, Brent, Alefeld, Falsi, ITP, Ridder)
12+ @eval begin
13+ function SciMLBase. solve (prob:: IntervalNonlinearProblem {uType, iip,
14+ <: Union{<:Dual{T, V, P}, <:AbstractArray{<:Dual{T, V, P}}} },
15+ alg:: $ (algType), args... ; kwargs... ) where {uType, T, V, P, iip}
16+ sol, partials = __nlsolve_ad (prob, alg, args... ; kwargs... )
17+ dual_soln = __nlsolve_dual_soln (sol. u, partials, prob. p)
18+ return SciMLBase. build_solution (prob, alg, dual_soln, sol. resid; sol. retcode,
19+ sol. stats, sol. original, left = Dual {T, V, P} (sol. left, partials),
20+ right = Dual {T, V, P} (sol. right, partials))
21+ end
22+ end
23+ end
24+
25+ function __nlsolve_ad (prob, alg, args... ; kwargs... )
1226 p = value (prob. p)
13- newprob = NonlinearProblem (prob. f, value (prob. u0), p; prob. kwargs... )
27+ if prob isa IntervalNonlinearProblem
28+ tspan = value .(prob. tspan)
29+ newprob = IntervalNonlinearProblem (prob. f, tspan, p; prob. kwargs... )
30+ else
31+ u0 = value (prob. u0)
32+ newprob = NonlinearProblem (prob. f, u0, p; prob. kwargs... )
33+ end
1434
1535 sol = solve (newprob, alg, args... ; kwargs... )
1636
7797 _partials = _restructure (u, partials)
7898 return map (((uᵢ, pᵢ),) -> Dual {T, V, P} (uᵢ, pᵢ), zip (u, _partials))
7999end
80-
81- # avoid ambiguities
82- for Alg in [Bisection]
83- @eval function SciMLBase. solve (prob:: IntervalNonlinearProblem {uType, iip,
84- <: Dual{T, V, P} }, alg:: $Alg , args... ; kwargs... ) where {uType, iip, T, V, P}
85- sol, partials = __nlsolve_ad (prob, alg, args... ; kwargs... )
86- dual_soln = __nlsolve_dual_soln (sol. u, partials, prob. p)
87- return SciMLBase. build_solution (prob, alg, dual_soln, sol. resid; sol. retcode,
88- left = Dual {T, V, P} (sol. left, partials),
89- right = Dual {T, V, P} (sol. right, partials))
90- end
91- @eval function SciMLBase. solve (prob:: IntervalNonlinearProblem {uType, iip,
92- <: AbstractArray{<:Dual{T, V, P}} }, alg:: $Alg , args... ;
93- kwargs... ) where {uType, iip, T, V, P}
94- sol, partials = __nlsolve_ad (prob, alg, args... ; kwargs... )
95- dual_soln = __nlsolve_dual_soln (sol. u, partials, prob. p)
96- return SciMLBase. build_solution (prob, alg, dual_soln, sol. resid; sol. retcode,
97- left = Dual {T, V, P} (sol. left, partials),
98- right = Dual {T, V, P} (sol. right, partials))
99- end
100- end
0 commit comments