Basic trouble with Python lists in Numba; what's going on?

空扰寡人 提交于 2019-12-11 06:37:34

问题


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

gives

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)

回答1:


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.

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.



来源:https://stackoverflow.com/questions/43166418/basic-trouble-with-python-lists-in-numba-whats-going-on

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!