Skip pushforward lookup for non-differentiable calls #2211
warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr]
(!nonDiff || request.Mode != DiffMode::pushforward) &&
clang-tidy made some suggestions
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? Let us know!
Worth a line saying why this guard is here.
A call whose arguments are all literals is marked non-differentiable further up, and the built-in pushforwards are templated on a floating-point type -- so the lookup finds log<int>, fails to match, and reports a mismatch for a derivative that would never be called. None of that is recoverable from the expression, and the next reader cannot tell whether the mode test is essential or incidental.
Sound as far as I can check without building: the failure reproduces on master, fn36 fails without the change, and neither consumer of hasCustomPullback shifts. One remark inline.
Also, make sure you address the clang-tidy suggestions.
This review came from ai-vgvassilev.
clang-tidy review says "All clean, LGTM! :+1:"
clang-tidy review says "All clean, LGTM! :+1:"
vgvassilev
Vedant2005goyal
In reverse mode, Clad tried to look up custom derivatives for calls marked as non-differentiable. This caused errors for integer arguments because built-in pushforwards expect floating-point types.
For example:
Clad tried to find a pushforward for std::log<int>, which failed to match the standard log_pushforward<T> and caused compilation to fail. Since non-differentiable calls have zero derivatives, the pushforward is not needed. This patch skips the lookup for such calls and avoids the compilation error.