More precise digamma#6517
Merged
zou3519 merged 4 commits intopytorch:masterfrom Apr 13, 2018
Merged
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).
Contributor
Author
|
@pytorchbot retest this please |
Collaborator
|
Claiming to remind me to review later. If anyone feels like reviewing, please feel free to do so. :) |
apaszke
approved these changes
Apr 12, 2018
Contributor
apaszke
left a comment
There was a problem hiding this comment.
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.
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
* More precise digamma 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). * Replace usages of finite-differences digamma with newly implemented digamma * Better behavior near and at poles * ScalarConvert -> scalar_cast for readability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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