charlieb charlieb - 2 months ago 92
Python Question

Numba Lowering error when iterating over 3D array

I have a 3D array (n, 3,2) for holding groups of three 2D vectors and I'm iterating over them something like this:

import numpy as np
for x in np.zeros((n,2,3), dtype=np.float64):
print(x) # for example


With normal numpy this works fine but when I wrap the function in question in a

@numba.jit(nopython=True)


I get an error like the one below.

numba.errors.LoweringError: Failed at nopython (nopython mode backend)
iterating over 3D array
File "paint.py", line 111
[1] During: lowering "$77.2 = iternext(value=$phi77.1)" at paint.py (111)


For reference the actual code is here

Answer

It looks like this is just not implemented.

In [13]: @numba.njit
    ...: def f(v):
    ...:     for x in v:
    ...:         y = x
    ...:     return y

In [14]: f(np.zeros((2,2,2)))
NotImplementedError                       Traceback (most recent call last)
<snip>
LoweringError: Failed at nopython (nopython mode backend)
iterating over 3D array
File "<ipython-input-13-788b4772d1d9>", line 3
[1] During: lowering "$7.2 = iternext(value=$phi7.1)" at <ipython-input-13-788b4772d1d9> (3)

Seem to works ok if you loop using the index.

In [15]: @numba.njit
    ...: def f(v):
    ...:     for i in range(len(v)):
    ...:         y = v[i]
    ...:     return y

In [16]: f(np.zeros((2,2,2)))
Out[16]: 
array([[ 0.,  0.],
       [ 0.,  0.]])