如何使用numba将浮点数声明为float128

时间:2018-02-14 22:05:17

标签: numba

我担心模拟中的数值错误,并希望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

0 个答案:

没有答案