@@ -371,17 +371,27 @@ function estimate_step(
371
371
return _limit_step (m, x, step, acc)
372
372
end
373
373
374
+ function finite_or_zero (fs:: AbstractArray{<:Number} )
375
+ ifelse .(isfinite .(fs), fs, zero (fs))
376
+ end
377
+
378
+ function finite_or_zero (fs:: AbstractArray{<:AbstractArray} )
379
+ finite_or_zero .(fs)
380
+ end
381
+
374
382
function _estimate_magnitudes (
375
383
m:: FiniteDifferenceMethod{P,Q} , f:: TF , x:: T ,
376
384
) where {P,Q,TF,T<: AbstractFloat }
377
385
step = first (estimate_step (m, f, x))
378
386
fs = _eval_function (m, f, x, step)
387
+ fs = finite_or_zero (fs)
379
388
# Estimate magnitude of `∇f` in a neighbourhood of `x`.
380
389
∇fs = SVector {3} (
381
390
_compute_estimate (m, fs, x, step, m. coefs_neighbourhood[1 ]),
382
391
_compute_estimate (m, fs, x, step, m. coefs_neighbourhood[2 ]),
383
392
_compute_estimate (m, fs, x, step, m. coefs_neighbourhood[3 ])
384
393
)
394
+ ∇fs = finite_or_zero (∇fs)
385
395
∇f_magnitude = maximum (maximum .(abs, ∇fs))
386
396
# Estimate magnitude of `f` in a neighbourhood of `x`.
387
397
f_magnitude = maximum (maximum .(abs, fs))
0 commit comments