Python 当包含JIT函数时,如何指定numba JIT类的字段?
我想创建一个具有包含任何jitted函数的属性的numba jitclassPython 当包含JIT函数时,如何指定numba JIT类的字段?,python,class,types,numba,Python,Class,Types,Numba,我想创建一个具有包含任何jitted函数的属性的numba jitclass # simple jitted functions defined in another file @njit def my_function(x): x = x + 1 return x @njit def another_function(x): x = x * 2 return x 当我用numba.typeof(my_函数)替换?,并用an_object=Myclass(f
# simple jitted functions defined in another file
@njit
def my_function(x):
x = x + 1
return x
@njit
def another_function(x):
x = x * 2
return x
当我用numba.typeof(my_函数)
替换?
,并用an_object=Myclass(fun=my_函数)
创建Myclass实例时,一切正常。但是,这样我只能传递确切的函数my_函数
。当我用另一个jitted函数创建Myclass对象时
new_object = Myclass(fun=another_function)
new_object.class_fun(2)
我得到以下错误:
Failed in nopython mode pipeline (step: nopython mode backend)
Cannot cast type(CPUDispatcher(<function another_function at 0x7fb1e3d8ce50>))
to type(CPUDispatcher(<function my_function at 0x7fb1e404de50>))
在nopython模式管道中失败(步骤:nopython模式后端)
无法强制转换类型(CPUDispatcher())
要键入(CPUDispatcher())
这对我来说很有意义,因为我为我的函数定义了字段类型。我不知道如何以通用方式定义字段类型属性
,以便传递任何函数
# simple jitted functions defined in another file
@njit
def my_function(x):
x = x + 1
return x
@njit
def another_function(x):
x = x * 2
return x
有人知道在创建jitclass的对象时传递jitted函数的方法吗!