-
Notifications
You must be signed in to change notification settings - Fork 26.3k
More precise digamma #6517
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
More precise digamma #6517
Conversation
Fixes pytorch#6190. This is a rebase of pytorch#3955 with some tweaks for better performance around poles. The code is ported over from cephes with permission. By itself, the cephes code returns inf for the poles. For better performance around the poles with float32, one intermediate step is always computed with double precision, regardless of dtype. This step does `PI / tan(PI * input)`. This is necessary because small (1e-6) rounding errors for the inputs to tan have strong effects on the output (ie, the derivative of tan is very large at some points).
|
@pytorchbot retest this please |
|
Claiming to remind me to review later. If anyone feels like reviewing, please feel free to do so. :) |
apaszke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't reviewed the math (I assume it just comes from Cephes). Two minor things, but LGTM.
| return result; | ||
| } | ||
|
|
||
| static inline float TH_polevlf(float x, float *A, size_t len) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
|
||
| compute_type x = ScalarConvert<real, compute_type>::to(*in); | ||
| if (x == 0) { | ||
| *out = ScalarConvert<float, real>::to(INFINITY); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Fixes #6190.
This is a rebase of #3955 with some tweaks for better performance around
poles. The code is ported over from cephes with permission.
By itself, the cephes code returns inf for the poles.
For better performance around the poles with float32, one intermediate
step is always computed with double precision, regardless of dtype.
This step does
PI / tan(PI * input). This is necessary because small (1e-6)rounding errors for the inputs to tan have strong effects on the output
(ie, the derivative of tan is very large at some points).
cc @colesbury @apaszke