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 new custom derivatives for math functions #1237

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

a-elrawy
Copy link
Contributor

@a-elrawy a-elrawy commented Feb 5, 2025

Contributing to #871
Added support for the following functions:

  • tan
  • cosh
  • sinh
  • asin
  • atan
  • log10
  • log2
  • cbrt
  • hypot

Copy link
Contributor

github-actions bot commented Feb 5, 2025

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

github-actions bot commented Feb 5, 2025

clang-tidy review says "All clean, LGTM! 👍"

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.61%. Comparing base (220064e) to head (e6ac75e).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1237      +/-   ##
==========================================
- Coverage   94.64%   94.61%   -0.04%     
==========================================
  Files          51       51              
  Lines        8890     8890              
==========================================
- Hits         8414     8411       -3     
- Misses        476      479       +3     

see 1 file with indirect coverage changes

see 1 file with indirect coverage changes

@vgvassilev
Copy link
Owner

This looks quite good. What are the remaining functions from math.h and cmath that still need to be supported?

@a-elrawy
Copy link
Contributor Author

a-elrawy commented Feb 6, 2025

These are some funcitons from https://en.cppreference.com/w/c/numeric/math

Basic Functions:

  • abs, labs, llabs, imaxabs
  • fabs, fabsf, fabsl
  • fmod, fmodf, fmodl
  • remainder, remainderf, remainderl
  • remquo, remquof, remquol
  • fma, fmaf, fmal
  • fmax, fmaxf, fmaxl
  • fmin, fminf, fminl
  • fdim, fdimf, fdiml

Exponential Functions:

  • exp, expf, expl
  • exp2, exp2f, exp2l
  • expm1, expm1f, expm1l

Logarithmic Functions:

  • log, logf, logl
  • log10, log10f, log10l
  • log2, log2f, log2l
  • log1p, log1pf, log1pl

Power Functions:

  • pow, powf, powl
  • sqrt, sqrtf, sqrtl
  • cbrt, cbrtf, cbrtl
  • hypot, hypotf, hypotl

Trigonometric Functions:

  • sin, sinf, sinl
  • cos, cosf, cosl
  • tan, tanf, tanl
  • asin, asinf, asinl
  • acos, acosf, acosl
  • atan, atanf, atanl
  • atan2, atan2f, atan2l

Hyperbolic Functions:

  • sinh, sinhf, sinhl
  • cosh, coshf, coshl
  • tanh, tanhf, tanhl
  • asinh, asinhf, asinhl
  • acosh, acoshf, acoshl
  • atanh, atanhf, atanhl

Error and Gamma Functions:

  • erf, erff, erfl
  • erfc, erfcf, erfcl
  • tgamma, tgammaf, tgammal
  • lgamma, lgammaf, lgammal

I'm not sure if I should include the remaining functions if they don't have derivatives.
Also, do we've to make a separate custom functions for function like sin, sinf, sinl ?

@vgvassilev
Copy link
Owner

I'm not sure if I should include the remaining functions if they don't have derivatives.

Probably returning 0 is fine. @parth-07 what do you think?

Also, do we've to make a separate custom functions for function like sin, sinf, sinl ?

Yes. You can still fall back to a single templated implementation function.

@parth-07
Copy link
Collaborator

I'm not sure if I should include the remaining functions if they don't have derivatives.

Probably returning 0 is fine. @parth-07 what do you think?

@a-elrawy When you say a function does not have a derivative, do you mean the function is non-differentiable due to discontinuity and cusp/corner?

@a-elrawy
Copy link
Contributor Author

I'm not sure if I should include the remaining functions if they don't have derivatives.

Probably returning 0 is fine. @parth-07 what do you think?

@a-elrawy When you say a function does not have a derivative, do you mean the function is non-differentiable due to discontinuity and cusp/corner?

I mean functions like floor and ceil (they are implemented to return 0), and other functions after Nearest integer floating-point operations here: https://en.cppreference.com/w/c/numeric/math
 

@parth-07
Copy link
Collaborator

I mean functions like floor and ceil (they are implemented to return 0), and other functions after Nearest integer floating-point operations here: https://en.cppreference.com/w/c/numeric/math

Oh, I see. Yes, I think we should return 0 as the derivative for such functions.

}

template <typename T, typename dT>
CUDA_HOST_DEVICE void tan_pullback(T x, T d_y, T* d_x) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dT template type is not being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, sorry I fixed that in the pullback functions. I was waiting to finish adding the remaining functions before pushing it.

@vgvassilev
Copy link
Owner

@a-elrawy, is there anything else that needs to be done here?

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

Successfully merging this pull request may close these issues.

3 participants