clad icon indicating copy to clipboard operation
clad copied to clipboard

Custom derivatives are not considered for direct differentiation request.

Open parth-07 opened this issue 3 years ago • 0 comments

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.

parth-07 avatar Jan 20 '22 19:01 parth-07