Skip to content

Commit e8e73cd

Browse files
authored
fix gradient sign (#165)
1 parent 4cf4b4f commit e8e73cd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/trunk.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ function SolverCore.solve!(
228228
# minimize g's + 1/2 s'Hs subject to ‖s‖ ≤ radius.
229229
# In this particular case, we may use an operator with preallocation.
230230
cgtol = max(rtol, min(T(0.1), ∇fNorm2, T(0.9) * cgtol))
231+
∇f .*= -1
231232
Krylov.solve!(
232233
subsolver,
233234
H,
@@ -242,9 +243,8 @@ function SolverCore.solve!(
242243

243244
# Compute actual vs. predicted reduction.
244245
sNorm = nrm2(n, s)
245-
@. s = -s
246246
copyaxpy!(n, one(T), s, x, xt)
247-
slope = dot(n, s, ∇f)
247+
slope = -dot(n, s, ∇f)
248248
mul!(Hs, H, s)
249249
curv = dot(n, s, Hs)
250250
Δq = slope + curv / 2
@@ -366,7 +366,7 @@ function SolverCore.solve!(
366366

367367
if isa(nlp, QuasiNewtonModel)
368368
∇fn .-= ∇f
369-
@. ∇fn = -∇fn # = ∇f(xₖ₊₁) - ∇f(xₖ)
369+
∇fn .*= -1 # = ∇f(xₖ₊₁) - ∇f(xₖ)
370370
push!(nlp, s, ∇fn)
371371
∇fn .= ∇f
372372
end

0 commit comments

Comments
 (0)