调用numba.vectorize生成的numpy.ufunc时发生Numba TypingError

问题描述

我正在f(x,a)内部调用函数F(x,a),如下所示

import numpy as np
import numba
from numba import vectorize


@vectorize('float64(float64,float64)',nopython = True,target = 'parallel')
def f(x,a):
    out = np.sign(x)* np.exp(-1* (np.absolute(x/a) - 0.5)**2)
                
    return out
    
    

@numba.jit(nopython = True)
def F(x,a):
    out = np.zeros(10)
    for i in range(10):
        f(x,a)
    
    return out
        
a = 1.
x = np.random.rand(5*5).reshape((5,5))

#Then this works fine
f(x,a)

#But this does not work
F(x,a)

调用f(x,a)可以正常工作,但是不能F(x,a)时出现以下错误消息:

TypingError: cannot determine Numba type of <class'numpy.ufunc'>

令我惊讶的是,如果我在target = 'cpu'的装饰器中设置了f(x,a),一切都会正常运行。我注意到在这种情况下:

type(f)
>>> numba.npyufunc.dufunc.DUFunc

而当我在target = 'cpu'的修饰符中设置f(x,a)(破损的情况)时,我得到:

type(f)
>>> numpy.ufunc

任何人都可以帮助我了解发生了什么事吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)