Say we have this snippet that runs error-free:
@numba.njit()
def run(rows, columns):
for row_index, Re in enumerate(numpy.linspace(-2, 1, rows)):
for column_index, Im in enumerate(numpy.linspace(-1, 1, columns)):
value = mandelbrot(Re, Im, 200)
Where mandelbrot is a function that returns a value that we then want stored in a 2D numpy array:
@numba.njit()
def run(rows, columns):
result = numpy.zeros([rows, columns])
for row_index, Re in enumerate(numpy.linspace(-2, 1, rows)):
for column_index, Im in enumerate(numpy.linspace(-1, 1, columns)):
result[row_index, column_index] = mandelbrot(Re, Im, 200)
return result
This gives the following No implementation of function Function(<built-in function setitem>) found for signature: setitem(readonly array(float64, 2d, C), UniTuple(int64 x 2), int64)
It seems like numba does not enjoy assigning items. As suggested in this answer we can try using array.ravel()
. However it does not help the situation, error remains unchanged.
result.ravel()[row_index, column_index] = mandelbrot(Re, Im, 200)
That being said, I would like to know if there is a way for numba to ignore this line completely, and run in pure python.