ForwardDiff.jl icon indicating copy to clipboard operation
ForwardDiff.jl copied to clipboard

Product of Inf terms leading to NaNs

Open Uroc327 opened this issue 7 months ago • 0 comments

ForwardDiff (v1.0.1 as well as v0.10.38) fails to compute the gradient when the inputs are too large for the following function.

julia> using ForwardDiff

julia> foo(a) = a[1] * exp(-a[2])
foo (generic function with 1 method)

julia> ForwardDiff.gradient(foo, [1., -1e3])
2-element Vector{Float64}:
 NaN
 NaN

The correct gradient should be [Inf, -Inf]. This works for values a2 small enough such that exp(a2) is finite.

Uroc327 avatar Apr 09 '25 20:04 Uroc327