@@ -11,6 +11,7 @@ struct TRARCWorkspace{T,S,Hess}
1111 ∇f:: S
1212 ∇fnext:: S
1313 Hstruct:: Hess
14+ Hd:: S
1415 Fx:: S
1516 function TRARCWorkspace (nlp:: AbstractNLPModel{T,S} , :: Type{Hess} ) where {T,S,Hess}
1617 n = nlp. meta. nvar
@@ -21,6 +22,7 @@ struct TRARCWorkspace{T,S,Hess}
2122 S (undef, n), # ∇f
2223 S (undef, n), # ∇fnext
2324 Hess (nlp, n),
25+ S (undef, n), # H * d
2426 S (undef, 0 ),
2527 )
2628 end
@@ -33,6 +35,7 @@ struct TRARCWorkspace{T,S,Hess}
3335 S (undef, n), # ∇f
3436 S (undef, n), # ∇fnext
3537 Hess (nlp, n),
38+ S (undef, n), # H * d
3639 S (undef, nlp. nls_meta. nequ),
3740 )
3841 end
@@ -152,6 +155,18 @@ function TRARC(
152155 return TRARC (nlp_stop, PData, workspace, TR; kwargs... )
153156end
154157
158+ """
159+ compute_Δq(Hx, d, ∇f)
160+
161+ Update `Δq = -(∇f + 0.5 * (Hx * d)) ⋅ d` in-place.
162+ """
163+ function compute_Δq (workspace, Hx, d, ∇f) # -(∇f + 0.5 * (nlp_at_x.Hx * d)) ⋅ d
164+ mul! (workspace. Hd, Hx, d)
165+ workspace. Hd .*= 0.5
166+ workspace. Hd .+ = ∇f
167+ return - dot (workspace. Hd, d)
168+ end
169+
155170function TRARC (
156171 nlp_stop:: NLPStopping{Pb,M,SRC,NLPAtX{T,S},MStp,LoS} ,
157172 PData:: ParamData ,
@@ -204,7 +219,7 @@ function TRARC(
204219 compute_direction (nlp_stop, PData, workspace, ∇f, norm_∇f, α, solve_model)
205220
206221 slope = ∇f ⋅ d
207- Δq = - (∇f + 0.5 * (nlp_at_x. Hx * d)) ⋅ d
222+ Δq = compute_Δq (workspace, nlp_at_x . Hx, d, ∇f) # -(∇f + 0.5 * (nlp_at_x.Hx * d)) ⋅ d
208223
209224 xtnext .= xt .+ d
210225 ftnext = obj (nlp, xtnext, workspace)
0 commit comments