Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clearer indication for results of differentiation of functions for which no derivative in custom_derivatives exist #90

Closed
efremale opened this issue Aug 20, 2018 · 1 comment
Assignees
Milestone

Comments

@efremale
Copy link
Contributor

Currently, if differentiation process meets a function which has no defined derivative in custom_derivatives namespace, its derivative is set to be 0.

Example:

double f(double x) {
  printf("%d", x);
  return x;
}

->

double f_darg0(double x) {
  0;
  printf("%d", x);
  return 1;
}

Since there exist no custom_derivatives::printf_darg0, we set the derivative of printf to be zero.
In principle, we could detect it and return null instead, but this would break cases when printf is used in expressions, e.g. int i = x + printf(...); -> int _d_i = _d_x + 0;. This is an obscure case, but it makes sense to use 0 in such expressions (say, if it is not printf, but some non-differentiable math function, we cannot determine that).

Should we indicate more clearly where does this 0 come from? E.g.

double f_darg0(double x) {
  int printf_darg0_non_differentiable = 0;
  printf_darg0_non_differentiable;
  printf("%d", x);
  return 1;
}
@PetroZarytskyi
Copy link
Collaborator

Currently, when Clad fails to generate a derivative or find a custom one, it attempts to use numerical differentiation. And then a warning is produced, which either says that num diff was used or that the function was not differentiated at all. I believe the issue is fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants