clad icon indicating copy to clipboard operation
clad copied to clipboard

Missing num-diff fallback warnings in nested function calls

Open guitargeek opened this issue 1 year ago • 0 comments

Reproducer:

// Compile with clang++ -std=c++20 -fplugin=/usr/lib/clad.so missing_warning.cxx -o missing_warning

#include "clad/Differentiator/Differentiator.h"

#include <cmath>

inline double innerWrapper(double x)
{
   return std::lgamma(x); // call any function that needs num. diff.
}

double wrapper(double *params)
{
   // When calling the num-diffed function directly, you get the correct
   // warning:
   // return std::lgamma(params[0]);
   return innerWrapper(params[0]);
}

int main()
{
   auto grad = clad::gradient(wrapper, "params");
}

When calling std::lgamma directly, you get this correct warning when compiling:

warning: Falling back to numerical differentiation for 'lgamma' since no suitable overload was found and clad could not derive it. To disable this feature, compile your programs with -DCLAD_NO_NUM_DIFF.
1 warning generated.

However, the warning is absent in the reproducer with the nested function call.

It would be nice if you also get the warning in that situation, because these warnings are very useful to spot residual num. diffs in the gradients.

guitargeek avatar Dec 13 '23 00:12 guitargeek