Skip to content

Commit

Permalink
Add propagator for __builtin_log.
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvassilev committed Jul 28, 2024
1 parent d8374bb commit ad08e47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions include/clad/Differentiator/BuiltinDerivatives.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ ValueAndPushforward<int, int> cudaDeviceSynchronize_pushforward()
}
#endif

CUDA_HOST_DEVICE inline ValueAndPushforward<float, float>
__builtin_logf_pushforward(float x, float d_x) {
return {__builtin_logf(x), (1.F / x) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<double, double>
__builtin_log_pushforward(double x, double d_x) {
return {__builtin_log(x), (1.0 / x) * d_x};
}

CUDA_HOST_DEVICE inline ValueAndPushforward<double, double>
__builtin_pow_pushforward(double x, double exponent, double d_x,
double d_exponent) {
Expand Down
7 changes: 5 additions & 2 deletions test/FirstDerivative/BuiltinDerivatives.C
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ double f13(double x) {
//CHECK-NEXT: }

double f14(double x) {
return __builtin_pow(x, 2);
return __builtin_pow(x, 3);
}

int main () { //expected-no-diagnostics
Expand Down Expand Up @@ -324,7 +324,10 @@ int main () { //expected-no-diagnostics
printf("Result is = %.2f\n", f13_ddx.execute(1)); //CHECK-EXEC: Result is = 2.72

auto f14_darg0 = clad::differentiate(f14, 0);
printf("Result is = %f\n", f14_darg0.execute(1)); //CHECK-EXEC: Result is = 2.000000
printf("Result is = %f\n", f14_darg0.execute(1)); //CHECK-EXEC: Result is = 3.000000

auto f14_ddarg0 = clad::differentiate<2>(f14, 0);
printf("Result is = %f\n", f14_ddarg0.execute(1)); //CHECK-EXEC: Result is = 6.000000

return 0;
}

0 comments on commit ad08e47

Please sign in to comment.