numba是一个提供以注解形式高性能编译的python库。
最基础的就是 @jit ,对for循环有明显的加速
from numba import jit
@jit
def f(x, y):
# A somewhat trivial example
return x + y
另外用到了 @jit(nopython=True)
在实际使用的过程中,注解对应的函数内部调用了其他函数或者对象会导致注解无法识别引起异常。
@njit
- this is an alias for@jit(nopython=True)
as it is so commonly used!@vectorize
- produces NumPyufunc
s (with all theufunc
methods supported).@guvectorize
- produces NumPy generalizedufunc
s.@stencil
- declare a function as a kernel for a stencil like operation.@jitclass
- for jit aware classes.@cfunc
- declare a function for use as a native call back (to be called from C/C++ etc).@overload
- register your own implementation of a function for use in nopython mode, e.g.@overload(scipy.special.j0)
.