Skip to content
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

BUG: Division overflow tracking issue #21506

Closed
3 tasks done
ganesh-k13 opened this issue May 14, 2022 · 1 comment
Closed
3 tasks done

BUG: Division overflow tracking issue #21506

ganesh-k13 opened this issue May 14, 2022 · 1 comment

Comments

@ganesh-k13
Copy link
Member

ganesh-k13 commented May 14, 2022

Describe the issue:

Currently, there are various cases where division leads to overflow/arithmetic exceptions. This happens when the dividend is the smallest possible value of the dtype and the divisor is -1.

Example:

np.iinfo(np.int32).min % np.int32(-1)

Reproduce the code example:

https://gist.github.com/ganesh-k13/6faaf65d418db13012bd403250cca70a

~ » python3 overflow.py                                                                                                                                                                                         ganesh@ganesh-MS-7B86 
1.22.3                                                                                                                                                                                                                                
Scalars: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 48/48 [00:04<00:00, 10.65it/s]
Arrays: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 48/48 [00:04<00:00, 10.26it/s]
Scalar Failures Observed:                                                                                                                                                                                                             
+--------------+------------------+-----------------+
| operation    | dividend_dtype   | divisor_dtype   |
+==============+==================+=================+
| np.remainder | np.int32         | np.int8         |
+--------------+------------------+-----------------+
| np.fmod      | np.int32         | np.int8         |
+--------------+------------------+-----------------+
| np.remainder | np.int32         | np.int16        |
+--------------+------------------+-----------------+
| np.fmod      | np.int32         | np.int16        |
+--------------+------------------+-----------------+
| np.remainder | np.int32         | np.int32        |
+--------------+------------------+-----------------+
| np.fmod      | np.int32         | np.int32        |                                                                                                                                                                                 
+--------------+------------------+-----------------+                                                                                                                                                                                 
| np.remainder | np.int64         | np.int8         |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int8         |
+--------------+------------------+-----------------+
| np.remainder | np.int64         | np.int16        |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int16        |
+--------------+------------------+-----------------+
| np.remainder | np.int64         | np.int32        |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int32        |
+--------------+------------------+-----------------+
| np.remainder | np.int64         | np.int64        |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int64        |
+--------------+------------------+-----------------+
Array Failures Observed:
+--------------+------------------+-----------------+
| operation    | dividend_dtype   | divisor_dtype   |
+==============+==================+=================+
| np.remainder | np.int32         | np.int8         |
+--------------+------------------+-----------------+
| np.fmod      | np.int32         | np.int8         |
+--------------+------------------+-----------------+
| np.remainder | np.int32         | np.int16        |
+--------------+------------------+-----------------+
| np.fmod      | np.int32         | np.int16        |
+--------------+------------------+-----------------+
| np.remainder | np.int32         | np.int32        |
+--------------+------------------+-----------------+
| np.fmod      | np.int32         | np.int32        |
+--------------+------------------+-----------------+
| np.remainder | np.int32         | np.int64        |
+--------------+------------------+-----------------+
| np.fmod      | np.int32         | np.int64        |
+--------------+------------------+-----------------+
| np.remainder | np.int64         | np.int8         |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int8         |
+--------------+------------------+-----------------+
| np.remainder | np.int64         | np.int16        |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int16        |
+--------------+------------------+-----------------+
| np.remainder | np.int64         | np.int32        |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int32        |
+--------------+------------------+-----------------+
| np.remainder | np.int64         | np.int64        |
+--------------+------------------+-----------------+
| np.fmod      | np.int64         | np.int64        |
+--------------+------------------+-----------------+

Error message:

>>> np.iinfo(np.int64).min % np.int64(-1)
[1]    61277 floating point exception (core dumped)  python3

NumPy/Python version information:

1.22.3 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0]

Relate Issues and PRs:

ToDo

seberg pushed a commit that referenced this issue Jul 17, 2022
…ication (#21793)

Remane `npy_mul_with_overflow_intp` to `npy_mul_sizes_with_overflow` as it only allows positive numbers.  Then introduce new versions for all integers (not intp) to use it for the integer scalar math with overflow detection.
(It is OK to use everywhere, just for sizes we know they will be positive normally.)

Related to #21506

Follow-up to #21648
@seberg
Copy link
Member

seberg commented Sep 8, 2022

All of these issues should now be fixed, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants