@@ -230,13 +230,16 @@ function _morethuente!(df,
230
230
231
231
f = NLSolversBase. value_gradient! (df, x_new)
232
232
gdf = NLSolversBase. gradient (df)
233
+ nfev += 1 # This includes calls to f() and g!()
233
234
iterfinite = 0
234
235
while (! isfinite (f) || any (.! isfinite .(gdf))) && iterfinite < iterfinitemax
235
236
iterfinite += 1
236
237
stp = 0.5 * stp
237
238
@. x_new = x + stp* s
238
239
f = NLSolversBase. value_gradient! (df, x_new)
239
240
gdf = NLSolversBase. gradient (df)
241
+ nfev += 1 # This includes calls to f() and g!()
242
+
240
243
# Make stpmax = (3/2)*stp < 2stp in the first iteration below
241
244
stx = (7 / 8 )* stp
242
245
end
@@ -289,12 +292,12 @@ function _morethuente!(df,
289
292
290
293
f = NLSolversBase. value_gradient! (df, x_new)
291
294
gdf = NLSolversBase. gradient (df)
295
+ nfev += 1 # This includes calls to f() and g!()
292
296
293
297
if isapprox (norm (gdf), 0.0 ) # TODO : this should be tested vs Optim's g_tol
294
298
return stp
295
299
end
296
300
297
- nfev += 1 # This includes calls to f() and g!()
298
301
dg = vecdot (gdf, s)
299
302
push! (lsr, stp, f, dg)
300
303
ftest1 = finit + stp * dgtest
@@ -564,8 +567,8 @@ function cstep(stx::Real, fx::Real, dgx::Real,
564
567
# The case gamma = 0 only arises if the cubic does not tend
565
568
# to infinity in the direction of the step
566
569
#
567
- #
568
- gamma = (s > zero (s)) ? s * sqrt (( theta / s)^ 2 - (dgx / s) * (dg / s)) : zero (s )
570
+ # # Use NaNMath in case s == zero(s)
571
+ gamma = s * sqrt (NaNMath . max ( zero (s), ( theta / s)^ 2 - (dgx / s) * (dg / s)))
569
572
570
573
if stp > stx
571
574
gamma = - gamma
0 commit comments