Numba中的Python列表的基本问题;这是怎么回事? [英] Basic trouble with Python lists in Numba; what's going on?
问题描述
我是Numba的初学者.对于我的生活,我无法获得Numba函数来操作简单的列表.
哎呀,我什至不知道如何指定签名.
I'm a beginner to Numba. For the life in me I can't get a Numba function to manipulate a simple list.
Heck, I can't even figure out how to specify the signature.
这里是例子.怎么了?(什么是反射列表"?)我该如何解决?
Here's the example. What's wrong? (What's a "reflected list"?) And how do I fix it?
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)
推荐答案
我没有找到关于该主题的任何文档,但是从我浏览源代码,反射"列表是在JITted函数之后必须在Python中可见(反映)列表更改的列表完成了.由于我不知道的原因,在Numba类型系统中,反射列表被视为与非反射列表不同的类型.这个概念可能特定于nopython模式.我不确定,也无法测试.
I haven't found any documentation on the subject, but from the things that came up when I Googled the topic and dug through the source code, a "reflected" list is one where changes to the list have to be visible (reflected) in Python after a JITted function is done with it. Reflected lists are treated as a different type from non-reflected lists in the Numba type system, for reasons I do not know. The concept may be specific to nopython mode; I'm not sure, and I can't test it.
您已经声明您的函数接受一个非反射列表,但是它需要一个反射列表.您需要将 reflected = True
添加到内部的 List(int64)
调用中,并且可能还要添加外部的调用.
You've declared that your function takes a non-reflected list, but it needs to take a reflected list. You need to add reflected=True
to the inner List(int64)
call, and possibly the outer one as well.
这篇关于Numba中的Python列表的基本问题;这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!