clad
clad copied to clipboard
Custom derivatives are not considered for direct differentiation request.
Reproducible example:
double identity(double i) {
return i;
}
namespace custom_derivatives {
void identity_grad(double i, clad::array_ref<double> d_i) {
d_i += 1;
}
}
auto d_identity = clad::gradient(identity);
Result: Clad generates the derivative of double identity(double)
instead of reusing the custom derivative provided by the user.
The root cause of the issue: We only consider custom derivatives when we are differentiating function calls. This is done by finding if a custom derivative is available for the function being called in VisitCallExpr
. We should instead check for custom derivative availability when processing the differentiation request in CladPlugin::ProcessDiffRequest
.