-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Simplified fix, Overflow in tan and tanh for large complex values. #5518
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
Conversation
Set the HAVE_XXXX macros for all of the following functions. csin, ccos, ctan casin, cacos, catan csinh, ccosh, ctanh casinh, cacosh, catanh cexp, clog, cpow cabs, csqrt, carg cimag, creal, conj, cproj The macros do not need to be used, but it is good to have all of them available.
This PR needs some style cleanups, but I've put those into a separate PR to keep this easier to review. Except for some cleanups that were already made. Same with creating new files and moving functions around. The As far as testing the numpy fallback functions, I'm inclined to add a macro that will force the numpy versions to be used, so they can be tested with the python tests. Suggestions for alternatives are welcome. Small changes in function values are likely to result, so this should probably be mentioned in the release notes if accepted. |
Looks like configuration testing is needed. Bummer. |
cd0feca
to
2010c30
Compare
Still playing with this. |
e52b8d9
to
8ba4098
Compare
@@ -258,8 +261,11 @@ float npy_copysignf(float x, float y); | |||
float npy_nextafterf(float x, float y); | |||
float npy_spacingf(float x); | |||
|
|||
float npy_ldexpf(float x, int exp); |
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.
These are already in master.
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.
Fixed, thanks.
This looks good to me. Thanks for taking the time to clean this up. I allowed my pull request to get way out of hand, but I think parts of this are still good improvements. |
The new functions added: npy_ctan, npy_cacos, npy_casin, npy_catan npy_ccosh, npy_csinh, npy_ctanh npy_cacosh, npy_casinh, npy_catanh
This should clear up such things as >>> np.tanh(372 + 1j) (nan+nan*j)
The test for precision needed to have difference changed from 2*eps to 2.1*eps for the system supplied sinh.
Numpy computes small integer powers by multiplication, this leads to different results than the system cpow for such integers. In particular, cpow((0 + inf*1j), 2) returns (-inf + 0j) rather than (-inf + nanj). The system version probably makes more sense, but better to keep compatibility at this point. We could fix our results using cproj.
The library functions casin, casinh, catan, catanh are inaccurate in glibc version < 2.16, so use the numpy fallback functions for those.
Document the increased use of the system library for C99 complex functions and the addition of improved fallback functions for * npy_ctan, * npy_cacos, npy_casin, npy_catan * npy_ccosh, npy_csinh, npy_ctanh, * npy_cacosh, npy_casinh, npy_catanh
8ba4098
to
f9c3776
Compare
BUG: Simplified fix, Overflow in tan and tanh for large complex values.
Simplified and rebased version of #3010.
np.tanh(1000+0j) gives nan+nan_j instead of 1.0+0j.
np.tan(0+1000j) gives nan+nan_j instead of 1j.
I've imported the implementation for ctanh from FreeBSD's math library
which handles large arguments correctly and fixes this bug and the
equivalent bug in np.tan.
The problem here is that importing the function into npy_math_complex.c
and adding a config check causes us to use the implementation from glibc
on Linux, which also has this bug. Although it seems to have been fixed
in glibc last April
(http://sourceware.org/bugzilla/show_bug.cgi?id=11521).
I see several things that could be done here, the easiest is probably to
use our version of ctanh unconditionally. Although there are a multitude
of ways to go about that, for instance should I remove the
implementation from npy_math_complex.c and just place it directly in
umath/funcs.inc, where the buggy version was? Or should I just remove
the config check and add a note about it somewhere?
This PR also uses more of the system complex functions if they are available.
Closes #2321.