@@ -14,15 +14,15 @@ function SciMLBase.solve(prob::NonlinearProblem{<:Number}, alg::NewtonRaphson, a
14
14
fx = f (x)
15
15
dfx = FiniteDiff. finite_difference_derivative (f, x, alg. diff_type, eltype (x), fx)
16
16
end
17
- iszero (fx) && return NewtonSolution (x, DEFAULT, fx )
17
+ iszero (fx) && return SciMLBase . build_solution (prob, alg, x, fx; retcode = Symbol (DEFAULT) )
18
18
Δx = dfx \ fx
19
19
x -= Δx
20
20
if isapprox (x, xo, atol= atol, rtol= rtol)
21
- return NewtonSolution (x, DEFAULT, fx )
21
+ return SciMLBase . build_solution (prob, alg, x, fx; retcode = Symbol (DEFAULT) )
22
22
end
23
23
xo = x
24
24
end
25
- return NewtonSolution (x, MAXITERS_EXCEED, fx )
25
+ return SciMLBase . build_solution (prob, alg, x, fx; retcode = Symbol (MAXITERS_EXCEED) )
26
26
end
27
27
28
28
function scalar_nlsolve_ad (prob, alg, args... ; kwargs... )
@@ -33,7 +33,7 @@ function scalar_nlsolve_ad(prob, alg, args...; kwargs...)
33
33
newprob = NonlinearProblem (f, u0, p; prob. kwargs... )
34
34
sol = solve (newprob, alg, args... ; kwargs... )
35
35
36
- uu = getsolution ( sol)
36
+ uu = sol. u
37
37
if p isa Number
38
38
f_p = ForwardDiff. derivative (Base. Fix1 (f, uu), p)
39
39
else
51
51
52
52
function SciMLBase. solve (prob:: NonlinearProblem{<:Number, iip, <:Dual{T,V,P}} , alg:: NewtonRaphson , args... ; kwargs... ) where {iip, T, V, P}
53
53
sol, partials = scalar_nlsolve_ad (prob, alg, args... ; kwargs... )
54
- return NewtonSolution (Dual {T,V,P} (sol. u, partials), sol. retcode, sol. resid)
54
+ return SciMLBase. build_solution (prob, alg, Dual {T,V,P} (sol. u, partials), sol. resid; retcode= sol. retcode)
55
+ # return NewtonSolution(Dual{T,V,P}(sol.u, partials), sol.retcode, sol.resid)
55
56
end
56
57
function SciMLBase. solve (prob:: NonlinearProblem{<:Number, iip, <:AbstractArray{<:Dual{T,V,P}}} , alg:: NewtonRaphson , args... ; kwargs... ) where {iip, T, V, P}
57
58
sol, partials = scalar_nlsolve_ad (prob, alg, args... ; kwargs... )
58
- return NewtonSolution (Dual {T,V,P} (sol. u, partials), sol. retcode, sol. resid)
59
+ return SciMLBase. build_solution (prob, alg, Dual {T,V,P} (sol. u, partials), sol. resid; retcode= sol. retcode)
60
+ # return NewtonSolution(Dual{T,V,P}(sol.u, partials), sol.retcode, sol.resid)
59
61
end
60
62
61
63
# avoid ambiguities
62
64
for Alg in [Bisection]
63
65
@eval function SciMLBase. solve (prob:: NonlinearProblem{uType, iip, <:Dual{T,V,P}} , alg:: $Alg , args... ; kwargs... ) where {uType, iip, T, V, P}
64
66
sol, partials = scalar_nlsolve_ad (prob, alg, args... ; kwargs... )
65
- return BracketingSolution (Dual {T,V,P} (sol. left, partials), Dual {T,V,P} (sol. right, partials), sol. retcode, sol. resid)
67
+ return SciMLBase. build_solution (prob, alg, Dual {T,V,P} (sol. u, partials), sol. resid; retcode= sol. retcode,left = Dual {T,V,P} (sol. left, partials), right = Dual {T,V,P} (sol. right, partials))
68
+ # return BracketingSolution(Dual{T,V,P}(sol.left, partials), Dual{T,V,P}(sol.right, partials), sol.retcode, sol.resid)
66
69
end
67
70
@eval function SciMLBase. solve (prob:: NonlinearProblem{uType, iip, <:AbstractArray{<:Dual{T,V,P}}} , alg:: $Alg , args... ; kwargs... ) where {uType, iip, T, V, P}
68
71
sol, partials = scalar_nlsolve_ad (prob, alg, args... ; kwargs... )
69
- return BracketingSolution (Dual {T,V,P} (sol. left, partials), Dual {T,V,P} (sol. right, partials), sol. retcode, sol. resid)
72
+ return SciMLBase. build_solution (prob, alg, Dual {T,V,P} (sol. u, partials), sol. resid; retcode= sol. retcode,left = Dual {T,V,P} (sol. left, partials), right = Dual {T,V,P} (sol. right, partials))
73
+ # return BracketingSolution(Dual{T,V,P}(sol.left, partials), Dual{T,V,P}(sol.right, partials), sol.retcode, sol.resid)
70
74
end
71
75
end
72
76
73
- function SciMLBase. solve (prob:: NonlinearProblem , :: Bisection , args... ; maxiters = 1000 , kwargs... )
77
+ function SciMLBase. solve (prob:: NonlinearProblem , alg :: Bisection , args... ; maxiters = 1000 , kwargs... )
74
78
f = Base. Fix2 (prob. f, prob. p)
75
79
left, right = prob. u0
76
80
fl, fr = f (left), f (right)
77
81
78
82
if iszero (fl)
79
- return BracketingSolution (left, right, EXACT_SOLUTION_LEFT,fl )
83
+ return SciMLBase . build_solution (prob, alg, left, fl; retcode = Symbol (EXACT_SOLUTION_LEFT), left = left, right = right )
80
84
end
81
85
82
86
i = 1
83
87
if ! iszero (fr)
84
88
while i < maxiters
85
89
mid = (left + right) / 2
86
- (mid == left || mid == right) && return BracketingSolution (left, right, FLOATING_POINT_LIMIT , fl)
90
+ (mid == left || mid == right) && return SciMLBase . build_solution (prob, alg, left , fl; retcode = Symbol (FLOATING_POINT_LIMIT), left = left, right = right )
87
91
fm = f (mid)
88
92
if iszero (fm)
89
93
right = mid
@@ -102,7 +106,7 @@ function SciMLBase.solve(prob::NonlinearProblem, ::Bisection, args...; maxiters
102
106
103
107
while i < maxiters
104
108
mid = (left + right) / 2
105
- (mid == left || mid == right) && return BracketingSolution (left, right, FLOATING_POINT_LIMIT , fl)
109
+ (mid == left || mid == right) && return SciMLBase . build_solution (prob, alg, left , fl; retcode = Symbol (FLOATING_POINT_LIMIT), left = left, right = right )
106
110
fm = f (mid)
107
111
if iszero (fm)
108
112
right = mid
@@ -114,23 +118,23 @@ function SciMLBase.solve(prob::NonlinearProblem, ::Bisection, args...; maxiters
114
118
i += 1
115
119
end
116
120
117
- return BracketingSolution (left, right, MAXITERS_EXCEED,fl )
121
+ return SciMLBase . build_solution (prob, alg, left, fl; retcode = Symbol (MAXITERS_EXCEED), left = left, right = right )
118
122
end
119
123
120
- function SciMLBase. solve (prob:: NonlinearProblem , :: Falsi , args... ; maxiters = 1000 , kwargs... )
124
+ function SciMLBase. solve (prob:: NonlinearProblem , alg :: Falsi , args... ; maxiters = 1000 , kwargs... )
121
125
f = Base. Fix2 (prob. f, prob. p)
122
126
left, right = prob. u0
123
127
fl, fr = f (left), f (right)
124
128
125
129
if iszero (fl)
126
- return BracketingSolution (left, right, EXACT_SOLUTION_LEFT,fl )
130
+ return SciMLBase . build_solution (prob, alg, left, fl; retcode = Symbol (EXACT_SOLUTION_LEFT), left = left, right = right )
127
131
end
128
132
129
133
i = 1
130
134
if ! iszero (fr)
131
135
while i < maxiters
132
136
if nextfloat_tdir (left, prob. u0... ) == right
133
- return BracketingSolution (left, right, FLOATING_POINT_LIMIT, fx )
137
+ return SciMLBase . build_solution (prob, alg, left, fl; retcode = Symbol ( FLOATING_POINT_LIMIT), left = left, right = right )
134
138
end
135
139
mid = (fr * left - fl * right) / (fr - fl)
136
140
for i in 1 : 10
@@ -157,7 +161,7 @@ function SciMLBase.solve(prob::NonlinearProblem, ::Falsi, args...; maxiters = 10
157
161
158
162
while i < maxiters
159
163
mid = (left + right) / 2
160
- (mid == left || mid == right) && return BracketingSolution (left, right, FLOATING_POINT_LIMIT , fl)
164
+ (mid == left || mid == right) && return SciMLBase . build_solution (prob, alg, left , fl; retcode = Symbol (FLOATING_POINT_LIMIT), left = left, right = right )
161
165
fm = f (mid)
162
166
if iszero (fm)
163
167
right = mid
@@ -172,5 +176,5 @@ function SciMLBase.solve(prob::NonlinearProblem, ::Falsi, args...; maxiters = 10
172
176
i += 1
173
177
end
174
178
175
- return BracketingSolution (left, right, MAXITERS_EXCEED,fl )
179
+ return SciMLBase . build_solution (prob, alg, left, fl; retcode = Symbol (MAXITERS_EXCEED), left = left, right = right )
176
180
end
0 commit comments