@@ -371,17 +371,27 @@ function estimate_step(
371371 return _limit_step (m, x, step, acc)
372372end
373373
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+
374382function _estimate_magnitudes (
375383 m:: FiniteDifferenceMethod{P,Q} , f:: TF , x:: T ,
376384) where {P,Q,TF,T<: AbstractFloat }
377385 step = first (estimate_step (m, f, x))
378386 fs = _eval_function (m, f, x, step)
387+ fs = finite_or_zero (fs)
379388 # Estimate magnitude of `∇f` in a neighbourhood of `x`.
380389 ∇fs = SVector {3} (
381390 _compute_estimate (m, fs, x, step, m. coefs_neighbourhood[1 ]),
382391 _compute_estimate (m, fs, x, step, m. coefs_neighbourhood[2 ]),
383392 _compute_estimate (m, fs, x, step, m. coefs_neighbourhood[3 ])
384393 )
394+ ∇fs = finite_or_zero (∇fs)
385395 ∇f_magnitude = maximum (maximum .(abs, ∇fs))
386396 # Estimate magnitude of `f` in a neighbourhood of `x`.
387397 f_magnitude = maximum (maximum .(abs, fs))
0 commit comments