我是 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/