I am getting a lot of NaNs from ForwardDiff.gradient on a fairly complicated function. I have an analytical function to compute the gradient that works fine (doesn’t give NaN), and coincides with ForwardDiff’s result when it is not NaN.
I already enabled the NANSAFE_MODE_ENABLED setting, but it is not helping. Is there a way to find the point in my code which makes ForwardDiff return a NaN?
Do you have calls do divrem (or similar?). That’s the only place I’ve seen ForwardDiff produce NaNs so far (and only at isolated points where the remainder is zero)