diff --git a/include/clad/Differentiator/BuiltinDerivatives.h b/include/clad/Differentiator/BuiltinDerivatives.h index a27373871..92b9094ea 100644 --- a/include/clad/Differentiator/BuiltinDerivatives.h +++ b/include/clad/Differentiator/BuiltinDerivatives.h @@ -72,6 +72,16 @@ ValueAndPushforward cudaDeviceSynchronize_pushforward() } #endif +CUDA_HOST_DEVICE inline ValueAndPushforward +__builtin_logf_pushforward(float x, float d_x) { + return {__builtin_logf(x), (1.F / x) * d_x}; +} + +CUDA_HOST_DEVICE inline ValueAndPushforward +__builtin_log_pushforward(double x, double d_x) { + return {__builtin_log(x), (1.0 / x) * d_x}; +} + CUDA_HOST_DEVICE inline ValueAndPushforward __builtin_pow_pushforward(double x, double exponent, double d_x, double d_exponent) { diff --git a/test/FirstDerivative/BuiltinDerivatives.C b/test/FirstDerivative/BuiltinDerivatives.C index 533192012..585ba95fb 100644 --- a/test/FirstDerivative/BuiltinDerivatives.C +++ b/test/FirstDerivative/BuiltinDerivatives.C @@ -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 @@ -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; }