-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
BUG: numpy.ma.put(a, indices, values, mode='wrap') runs for a very long time even when a, values are invalid #28630
Description
Describe the issue:
When indices is a very large number and mode='wrap' , numpy.ma.core.put still takes a very long time to calculate the result even if a and values are invalid types.
When I tried to run numpy.ma.core.put('', 8259655103995416119, '', 'wrap'), it hadn't completed even after running for four hours, even though it wouldn't perform any operations on a. I understand that when mode='wrap', the strategy is to use the modulo operation to keep the indices within the valid range of the array. When the first parameter is a valid MaskedArray type and the second parameter is a very large number(8259655103995416119, for example) while the third parameter is an empty string(invalid), the following result will be produced:
Traceback (most recent call last):
File "/root/experiment/seeds/numpy.ma.core.put/1#numpy#ma#core#put.py", line 66, in <module>
ret = numpy.ma.put(a, indices, values, mode)
File "/root/anaconda3/lib/python3.9/site-packages/numpy/ma/core.py", line 7397, in put
return a.put(indices, values, mode=mode)
File "/root/anaconda3/lib/python3.9/site-packages/numpy/ma/core.py", line 4889, in put
self._data.put(indices, values, mode=mode)
ValueError: invalid literal for int() with base 10: ''
and the program finishes running quickly.
However, when the first parameter is changed to an invalid string type, the program takes an extremely long time to run, even though no operations need to be performed due to the invalidity of these parameters.
Reproduce the code example:
import numpy
import numpy.ma
import traceback
print("----- running ('',1, '', 'wrap')")
(a, indices, values, mode) = ('',1, '', 'wrap')
ret = numpy.ma.put(a, indices, values, mode)
print("a: " + a) # a is still '', not changed, reasonable
print("----- running (numpy.ma.array([1, 2, 3, 4], mask=[False, True, False, False]) , 8259655103995416119, '', 'wrap')")
try:
a = numpy.ma.array([1, 2, 3, 4], mask=[False, True, False, False])
(indices, values, mode) = (8259655103995416119, '', 'wrap')
ret = numpy.ma.put(a, indices, values, mode) # ValueError: invalid literal for int() with base 10: ''. Reasonable
except Exception as e:
traceback.print_exc()
print("----- running ('' , 8259655103995416119, '', 'wrap')")
(a, indices, values, mode) = ('' , 8259655103995416119, '', 'wrap')
ret = numpy.ma.put(a, indices, values, mode)
print("a: " + a) # expected: a is still '', not changed. Actually runs long time, haven't got value after running 4 hours.Error message:
----- running ('',1, '', 'wrap')
a:
----- running (numpy.ma.array([1, 2, 3, 4], mask=[False, True, False, False]) , 8259655103995416119, '', 'wrap')
Traceback (most recent call last):
File "/root/PyRTFuzz/experiment/seeds/numpy.ma.core.put/1#numpy#ma#core#put.py", line 65, in <module>
ret = numpy.ma.put(a, indices, values, mode) # ValueError: invalid literal for int() with base 10: ''. Reasonable
File "/root/anaconda3/lib/python3.9/site-packages/numpy/ma/core.py", line 7397, in put
return a.put(indices, values, mode=mode)
File "/root/anaconda3/lib/python3.9/site-packages/numpy/ma/core.py", line 4889, in put
self._data.put(indices, values, mode=mode)
ValueError: invalid literal for int() with base 10: ''
----- running ('' , 8259655103995416119, '', 'wrap')Python and NumPy Versions:
Python: 3.9.0
Numpy: 2.0.1
Runtime Environment:
No response
Context for the issue:
When the first parameter is a valid array, the program will very quickly report an error because the third parameter is ''. When both a and values are of invalid data types, the function should do nothing to a, regardless of whether indices is a large number or not. But when indices is large, the code will run for a very long time.