让我们说我正在做大型矩阵的事情:
from numba import jit
import numpy as np
@jit
def dostuff(mat):
'''
Do stuff with the matrix
'''
return np.exp(-1j*mat)
这样做实际上比调用我的自定义指数函数cexp:
慢@jit
def dostuff_fast(mat):
'''
Do stuff with the matrix
'''
return cexp(-1j*mat)
@jit
def cexp(mat):
return np.exp(mat)
为什么这样?有任何想法吗?由于创建自定义函数并且之前调用@jit似乎比使用numpy函数更快,我想知道是否有办法强制将jit应用于我想要优化的函数内部调用的每个函数和操作。