@@ -51,9 +51,9 @@ Computation, 75, 1429-1448.](https://www.researchgate.net/publication/220576479_
5151end
5252
5353function SciMLBase. __solve (prob:: NonlinearProblem , alg:: SimpleDFSane , args... ;
54- abstol = nothing , reltol = nothing , maxiters = 1000 ,
54+ abstol = nothing , reltol = nothing , maxiters = 1000 , alias_u0 = false ,
5555 termination_condition = nothing , kwargs... )
56- x = float ( copy ( prob. u0) )
56+ x = __maybe_unaliased ( prob. u0, alias_u0 )
5757 fx = _get_fx (prob, x)
5858 T = eltype (x)
5959
@@ -76,6 +76,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleDFSane, args...;
7676 history_f_k = fill (fx_norm, M)
7777
7878 # Generate the cache
79+ @bb x_cache = similar (x)
7980 @bb d = copy (x)
8081 @bb xo = copy (x)
8182 @bb δx = copy (x)
@@ -89,38 +90,40 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleDFSane, args...;
8990 # Line search direction
9091 @bb @. d = - σ_k * fx
9192
92- η = η_strategy (f_1, k, x, fx)
93+ η = η_strategy (f_1, k + 1 , x, fx)
9394 f_bar = maximum (history_f_k)
9495 α_p = α_1
9596 α_m = α_1
9697
97- @bb @. x += α_p * d
98+ @bb @. x_cache = x + α_p * d
9899
99- fx = __eval_f (prob, fx, x )
100+ fx = __eval_f (prob, fx, x_cache )
100101 fx_norm_new = NONLINEARSOLVE_DEFAULT_NORM (fx)^ nexp
101102
102103 while k < maxiters
103104 Bool (fx_norm_new ≤ (f_bar + η - γ * α_p^ 2 * fx_norm)) && break
104105
105- α_p = α_p^ 2 * fx_norm / (fx_norm_new + (T (2 ) * α_p - T (1 )) * fx_norm)
106- @bb @. x -= α_m * d
106+ α_tp = α_p^ 2 * fx_norm / (fx_norm_new + (T (2 ) * α_p - T (1 )) * fx_norm)
107+ @bb @. x_cache = x - α_m * d
107108
108- fx = __eval_f (prob, fx, x )
109+ fx = __eval_f (prob, fx, x_cache )
109110 fx_norm_new = NONLINEARSOLVE_DEFAULT_NORM (fx)^ nexp
110111
111112 Bool (fx_norm_new ≤ (f_bar + η - γ * α_m^ 2 * fx_norm)) && break
112113
113114 α_tm = α_m^ 2 * fx_norm / (fx_norm_new + (T (2 ) * α_m - T (1 )) * fx_norm)
114- α_p = clamp (α_p , τ_min * α_p, τ_max * α_p)
115+ α_p = clamp (α_tp , τ_min * α_p, τ_max * α_p)
115116 α_m = clamp (α_tm, τ_min * α_m, τ_max * α_m)
116- @bb @. x += α_p * d
117+ @bb @. x_cache = x + α_p * d
117118
118- fx = __eval_f (prob, fx, x )
119+ fx = __eval_f (prob, fx, x_cache )
119120 fx_norm_new = NONLINEARSOLVE_DEFAULT_NORM (fx)^ nexp
120121
121122 k += 1
122123 end
123124
125+ @bb copyto! (x, x_cache)
126+
124127 tc_sol = check_termination (tc_cache, fx, x, xo, prob, alg)
125128 tc_sol != = nothing && return tc_sol
126129
0 commit comments