我要用numba增强我的代码。但是,并联模式下的功率函数不能正常工作,即对于以下功能:
import numpy as np
import numba
@numba.njit(parallel=True, fastmath = True)
def decay_rate(mV, mp):
drate=(np.power(mp,-3))
return drate
上面写着:
The keyword argument 'parallel=True' was specified but no transformation for parallel execution was possible.
这个函数比上面演示的更复杂(numba开销值得!)。另外,我以前也尝试过**
来获得能量,但结果是一样的。在
我怎样才能修好它?在
该消息只是声明您指定了
parallel
,但是没有发现要并行化的内容。这是因为np.power
(这同样适用于数组幂运算符**
)是一个在其他地方定义的函数,并且不能并行化正在调用的函数。但是,您可以并行化正在编写的函数或并行调用函数。在如果要并行计算幂,可以使用
numba.prange
(另请参见Explicit Parallel Loops (numba documentation)):prange
显式地告诉numba并行化循环。在相关问题 更多 >
编程相关推荐