实际上,我认为如果不深入了解数组的属性,就无法加速numba函数(是否有一些数学技巧可以更快地完成一些计算)。在
但我注意到了一个错误:例如,在numba版本中,您没有对数组进行共轭,我编辑了一些行使其更加流线型(其中一些可能只是味道)。我在适当的地方写了一些评论:@nb.njit
def twoFreq(z, source_z, num, den, matrix, e):
#Replace z with conjugate of z (otherwise the result is wrong!)
z = np.conj(z)
# Size instead of len() don't know if it actually makes a difference but it's cleaner
N1, N2 = z.size, source_z.size
# Must be zeros_like otherwise you create a float array where you want a complex one
out = np.zeros_like(z)
# I'm using python 3 so you need to replace this by xrange later
for r in range(N1):
for c in range(N2):
n, d = num[r, c], den[r, c] - 1
z1 = source_z[c] ** n
z2 = z[r] ** d
# Multiply with 0.5 instead of dividing by 2
# Work on the out ar