我担心模拟中的数值错误,并希望numba使用float128
变量。当我在nb.jit('f8()')
上指定func_nb
时,我告诉numba该函数不带参数并返回float128
个数字,对吧?如何告诉numba制作所有浮点数float128
?
@nb.jit()
def f_big_nb(A, k, std_A, std_k, mean_A=10, mean_k=0.2, hh=100):
return ( 1 / (std_A * std_k * 2 * np.pi) ) * A * (hh/50) ** k * np.exp( -1*(k - mean_k)**2 / (2 * std_k **2 ) - (A - mean_A)**2 / (2 * std_A**2))
@nb.jit('f8()')
def func_nb():
outer_sum = 0
dk = 0.01 #0.000001
X = np.arange(dk, 0.4, dk)
Y = np.arange(dk, 20, dk)
for i in xrange(X.shape[0]):
k = X[i] # faster to do lookup than iterate over an array directly
inner_sum = 0
for j in xrange(Y.shape[0]):
A = Y[j]
inner_sum += dk * f_big_nb(A, k, 1e-5, 1e-5)
outer_sum += inner_sum * dk
return outer_sum