2017-02-18 48 views

回答

1

是的,没有。你可以简单地使用普通的Python语法来注释(jit修饰器将保留它们)。建立在你的简单的例子:

from numba import jit 

@jit 
def f(x: int, y: int) -> int: 
    # A somewhat trivial example 
    return x + y 

>>> f.__annotations__ 
{'return': int, 'x': int, 'y': int} 
>>> f.signatures # they are not recognized as signatures for jit 
[] 

但是明确(执行),则必须在jit -decorator给予签名:

from numba import int_ 

@jit(int_(int_, int_)) 
def f(x: int, y: int) -> int: 
    # A somewhat trivial example 
    return x + y 

>>> f.signatures 
[(int32, int32)] # may be different on other machines 

还有据我知道jit没有自动的方式了解注释并从这些注释中建立其签名。

1

既然是即时编译,则必须执行函数生成签名

In [119]: f(1.0,1.0) 
Out[119]: 2.0 

In [120]: f(1j,1) 
Out[120]: (1+1j) 

In [121]: f.signatures 
Out[121]: [(float64, float64), (complex128, int64)] 

每次以前不适合数据生成一个新的签名。