8000 Merge pull request #19994 from charris/backport-19974 · numpy/numpy@c3de0e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit c3de0e6

Browse files
authored
Merge pull request #19994 from charris/backport-19974
BUG: np.tan(np.inf) test failure
2 parents 51b7c50 + d169a12 commit c3de0e6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

numpy/core/src/npymath/npy_math_internal.h.src

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,21 +483,40 @@ NPY_INPLACE @type@ npy_frexp@c@(@type@ x, int* exp)
483483
* #c = l,,f#
484484
* #C = L,,F#
485485
*/
486+
487+
/*
488+
* On arm64 macOS, there's a bug with sin, cos, and tan where they don't
489+
* raise "invalid" when given INFINITY as input.
490+
*/
491+
#if defined(__APPLE__) && defined(__arm64__)
492+
#define WORKAROUND_APPLE_TRIG_BUG 1
493+
#else
494+
#define WORKAROUND_APPLE_TRIG_BUG 0
495+
#endif
496+
486497
/**begin repeat1
487498
* #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
488499
* log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
489500
* #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,
490501
* LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2#
502+
* #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*22#
491503
*/
492504
#ifdef HAVE_@KIND@@C@
493505
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
494506
{
507+
#if @TRIG_WORKAROUND@
508+
if (!npy_isfinite(x)) {
509+
return (x - x);
510+
}
511+
#endif
495512
return @kind@@c@(x);
496513
}
497514
#endif
498515

499516
/**end repeat1**/
500517

518+
#undef WORKAROUND_APPLE_TRIG_BUG
519+
501520
/**begin repeat1
502521
* #kind = atan2,hypot,pow,copysign#
503522
* #KIND = ATAN2,HYPOT,POW,COPYSIGN#

0 commit comments

Comments
 (0)
0