python - Numba 中 Python 列表的基本问题;这是怎么回事?

标签 python list numba

我是 Numba 的初学者。对于我的生活,我无法使用 Numba 函数来操作简单的列表。
哎呀,我什至不知道如何指定签名。

这是示例。怎么了? (什么是“反射(reflect)列表”?)如何修复它?

from numba import *
from numba.types import *

@jit(List(int64)(List(int64)), nopython=True)
def foo(a): a[0] += a[0]; return a

foo([1])

给出

Traceback (most recent call last):
  File "<pyshell#5>", in <module>
    foo([1])
  File "numba\dispatcher.py", line 219, in _explain_matching_error
    raise TypeError(msg)
TypeError: No matching definition for argument type(s) reflected list(int64)

最佳答案

我还没有找到任何关于这个主题的文档,但是从我 Googled the topic 时出现的事情来看和 dug through the source code ,“反射(reflect)”列表是指在 JITted 函数完成后,列表的更改必须在 Python 中可见(反射(reflect))。在 Numba 类型系统中,反射列表被视为与非反射列表不同的类型,原因我不知道。该概念可能特定于 nopython 模式;我不确定,也无法测试。

您已声明您的函数采用非反射列表,但它需要采用反射列表。您需要将 reflected=True 添加到内部 List(int64) 调用,也可能添加到外部调用。

关于python - Numba 中 Python 列表的基本问题;这是怎么回事?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43166418/

相关文章:

python - 在使用python将数据从csv复制到postgres之前如何检查一行是否已经存在

python - pip 安装后无法运行 rodeo

python - 有没有一种简单的方法可以按值删除列表元素?

python - 有条件地从数组中删除一个元素

r - 将 sf 对象列表转换为一个 sf

python - nopython 模式下 Numba 递归函数出错

python - njit numba 函数的高级索引替代方案

python - 如何将数学风格(如 Latex)的单位添加到 Plotly 图表中而不侵 eclipse 标签的其余部分?

python - 合并具有共享 x 轴的 matplotlib 子图

python - 同时使用 python3 和 python 2.7 时出现 numba 类型错误