Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: Better report integer division overflow (backport) (#22230)
* BUG, SIMD: Handle overflow errors Overflows for remainder/divmod/fmod * If a types minimum value is divided by -1, an overflow will be raised and result will be set to minimum * Handle overflow and return 0 in case of mod related operations * TST: New tests for overflow in division operations * SIMD: Removed cvtozero Co-authored-by: Rafael Cardoso Fernandes Sousa <rafaelcfsousa@ibm.com> * TST: Removed eval | Fixed raises cases * TST: Changed `raise` to `warns` * Changed `raise` to `warns` and test for `RuntimeWarning` * Added results check back * TST: Add additional tests for division-by-zero and integer overflow This introduces a helper to iterate through "interesting" array cases that could maybe be used in other places. Keep the other test intact, it adds a check for mixed types (which is just casts currently, but cannot hurt) and is otherwise thorough. * MAINT: Remove nested NPY_UNLIKELY in division paths I am not certain the unlikely cases make much sense to begin with, but they are certainly not helpful within an unlikely block. * TST: Add unsigned integers to integer divide-by-zero test * BUG: Added missing `NAME` key to loop generator * BUG, SIMD: Handle division overflow errors * If a types minimum value is divided by -1, an overflow will be raised and result will be set to minimum * TST: Modified tests to reflect new overflow * Update numpy/core/src/umath/loops_arithmetic.dispatch.c.src Co-authored-by: Rafael Sousa <90851201+rafaelcfsousa@users.noreply.github.com> Co-authored-by: Rafael Cardoso Fernandes Sousa <rafaelcfsousa@ibm.com> Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net> Co-authored-by: Rafael Sousa <90851201+rafaelcfsousa@users.noreply.github.com>
- Loading branch information
1 parent
0f0d355
commit 9bf22bb
Showing
5 changed files
with
337 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.