v923z / micropython-ulab

a numpy-like fast vector module for micropython, circuitpython, and their derivatives
https://micropython-ulab.readthedocs.io/en/latest
MIT License
403 stars 111 forks source link

[BUG] crash in (arg)min (and probably (arg)max) #586

Open jepler opened 1 year ago

jepler commented 1 year ago

Describe the bug A clear and concise description of what the bug is. Give the ulab version

MicroPython v1.19.1-837-g67fac4ebc on 2023-01-24; linux [GCC 4.2.1] version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> from lab import numpy as np
>>> a=np.array([range(200000)])
>>> np.min(a, axis=1)
Segmentation fault

Expected behavior python3 and numpy give:

>>> np.min(_, axis=1)
array([0])

Additional context Found by automated fuzzing

v923z commented 1 year ago

While this is still incorrect

>>> np.min(np.array([range(5)]), axis=1)
0.0

it, at least, doesn't segfault. So, are we dealing with a problem here that is much deeper than ulab? If I simply create the array from the range, then

>>> np.array([range(200000)])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 1600000 bytes