cha*_*ieb 3 python numpy numba
我有一个3D数组(n,3,2)用于保存三个2D向量的组,并且正在像这样迭代它们:
import numpy as np
for x in np.zeros((n,2,3), dtype=np.float64):
print(x) # for example
Run Code Online (Sandbox Code Playgroud)
使用普通的numpy可以正常工作,但是当我将有问题的功能包装在一个
@numba.jit(nopython=True)
Run Code Online (Sandbox Code Playgroud)
我收到类似下面的错误。
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)
Run Code Online (Sandbox Code Playgroud)
供参考,实际代码在这里
看来这只是未实现。
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)
Run Code Online (Sandbox Code Playgroud)
如果循环使用索引,似乎可以正常工作。
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.]])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1789 次 |
| 最近记录: |