Skip to content

Conversation

@zou3519
Copy link
Contributor

@zou3519 zou3519 commented Apr 11, 2018

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

zou3519 added 3 commits April 11, 2018 13:20
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).
@zou3519
Copy link
Contributor Author

zou3519 commented Apr 11, 2018

@pytorchbot retest this please

@ssnl ssnl self-assigned this Apr 12, 2018
@ssnl
Copy link
Collaborator

ssnl commented Apr 12, 2018

Claiming to remind me to review later. If anyone feels like reviewing, please feel free to do so. :)

Copy link
Contributor

@apaszke apaszke left a 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.

This comment was marked as off-topic.

This comment was marked as off-topic.


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.

@zou3519 zou3519 merged commit 6c0f740 into pytorch:master Apr 13, 2018
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