gpt4 book ai didi

python - 遍历 3D 数组时 Numba 降低错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:40 26 4
gpt4 key购买 nike

我有一个 3D 数组 (n, 3,2) 用于保存三个 2D 向量的组,我正在像这样迭代它们:

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

最佳答案

看起来这只是没有实现。

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

关于python - 遍历 3D 数组时 Numba 降低错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39436719/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com