2016-09-11 81 views
1

我有一個3D陣列(N,3,2),用於保持的三個二維矢量組和我遍歷它們是這樣的:迭代3D陣列時Numba降低錯誤

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

與正常numpy這工作正常,但是當我把有問題的功能包裝在一個

@numba.jit(nopython=True) 

我得到一個像下面的錯誤。

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) 

僅供參考實際的代碼是here

+0

原來,使用上述@jit而是直接指定類型@jit((float64 [:,:,:] ))所描述的(nopython =真)不起作用工作得很好。也許這是Numba類型推斷中的一個錯誤? – charlieb

回答

2

看起來這只是沒有實現。

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) 

如果循環使用索引,看起來工作正常。

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.]])