-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
ENH: issue overflow warning when using abs
on np.int8(-128)
#21648
Changes from 14 commits
511240f
1ef5d3d
756b852
84bbdc8
74e9aff
41aa046
08e2d33
d8925f5
ca8f199
5155f57
76e53ac
4c379d1
3eac1ac
19d84d7
c513aa7
42adc88
754062a
3e692d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,7 @@ static NPY_INLINE int | |
} | ||
#if @neg@ | ||
else if (b == -1 && a == NPY_MIN_@NAME@) { | ||
*out = a / b; | ||
*out = NPY_MIN_@NAME@; | ||
return NPY_FPE_OVERFLOW; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is suspicious: is this line really not hit during tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep #21507 has tests that covers this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think both PRs have tests for this, so suspect that it is just in-lining/optimization leading to coverage errors (that might be the first time I have seen coverage failing, but...). @ganesh-k13 if you prefer it to not be included here, maybe just push the change yourself? (We have to mark that one additional test as Yes, it would be nice to follow-up to expand the tests so that they raise the error, and there is still lots of little stuff to clear out in |
||
} | ||
#endif | ||
|
@@ -584,10 +584,15 @@ static NPY_INLINE int | |
/**begin repeat | ||
* #name = byte, short, int, long, longlong# | ||
* #type = npy_byte, npy_short, npy_int, npy_long, npy_longlong# | ||
* #NAME = BYTE, SHORT, INT, LONG, LONGLONG# | ||
*/ | ||
static NPY_INLINE int | ||
@name@_ctype_absolute(@type@ a, @type@ *out) | ||
{ | ||
if (a == NPY_MIN_@NAME@) { | ||
*out = a; | ||
return NPY_FPE_OVERFLOW; | ||
} | ||
Micky774 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*out = (a < 0 ? -a : a); | ||
return 0; | ||
} | ||
|
@@ -1564,8 +1569,23 @@ static PyObject * | |
|
||
|
||
val = PyArrayScalar_VAL(a, @Name@); | ||
int retstatus = @name@_ctype_@oper@(val, &out); | ||
|
||
@name@_ctype_@oper@(val, &out); | ||
if (retstatus) { | ||
int bufsize, errmask; | ||
PyObject *errobj; | ||
|
||
if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, | ||
&errobj) < 0) { | ||
return NULL; | ||
} | ||
int first = 1; | ||
if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first)) { | ||
Py_XDECREF(errobj); | ||
return NULL; | ||
} | ||
Py_XDECREF(errobj); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is suspicious that these new lines are not marked as being tested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, right. The first one is OK (I don't think it can be reasonably covered, it indicates an internal/critical error). To hit the second one, we should also check for:
|
||
|
||
/* | ||
* TODO: Complex absolute should check floating point flags. | ||
|
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.
I think #21507 will cover it so we can remove this here perhaps? All though I'm happy to rebase if it goes in first.