我试过了:
import numpy as np
import numba
@numba.jit
class foo(object):
@numba.void(numba.int32)
def __init__(self, somenum):
self.somenumarray = np.arange(somenum)
@numba.jit('f8[:](f8[:])')
def somemethod1(self, a):
return self.somenumarray + a
使用@numba.double[:](numba.double[:])
方法装饰器会导致错误。
答案 0 :(得分:1)
import numpy as np import numba bar = numba.FunctionType(return_type=numba.f8[:], args=[numba.f8[:]]) @numba.jit class foo(object): @numba.FunctionType(return_type=numba.void, args=[numba.int32]) def __init__(self, somenum): self.somenumarray = np.arange(somenum) @bar def somemethod1(self, a): return self.somenumarray + a
您可以稍后执行此操作:
quux = foo(3) quux.somemethod1(np.arange(3))