Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当包含JIT函数时,如何指定numba JIT类的字段?_Python_Class_Types_Numba - Fatal编程技术网

Python 当包含JIT函数时,如何指定numba JIT类的字段?

Python 当包含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

我想创建一个具有包含任何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(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函数的方法吗!