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 NumPyufuncs (with all theufuncmethods supported).@guvectorize- produces NumPy generalizedufuncs.@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).
Numba是一个用于Python的高性能编译库,通过注解方式加速代码执行,特别是对for循环有显著效果。提供了多种注解,如@jit、@njit、@vectorize等,适用于不同场景,实现从简单算术运算到复杂科学计算的加速。官网:http://numba.pydata.org。
1158

被折叠的 条评论
为什么被折叠?



