问题
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