как использовать ручку numba cfunc scipy.integrate.dblquad - PullRequest
0 голосов
/ 27 сентября 2018

Я прочитал Как передать дополнительные параметры в numba cfunc, переданный как LowLevelCallable в scipy.integrate.quad

Честно говоря, я все еще чувствую беспорядок.

Теперь я хочу обернуть функцию dblquad, упомянутую в https://gist.github.com/Vindaar/aab2926425400fc57274b521e80398dd

, вот код

def get_integrand(*args):
    delta_y, sigma = args
    def integrand2(r, theta):
        # integrand is the integrand of the function which will be 2D integrated
        r_prime_2      = r**2 + delta_y**2 - 2*r*delta_y*np.cos(3.0/2.0*np.pi - theta)
        value          = 1/(2*np.pi*sigma**2)*np.exp(-r_prime_2/(2*sigma**2))*r
        return value

    return integrand2

nb_integrand = numba.cfunc("float64(float64, float64)")(get_integrand(delta_y, sigma)).ctypes


a = 1.0 # some constant
delta_y = 0.5 # some shift
sigma = 2.0 # and our gaussians sigma

t0 = time.clock()
for i in range(1000):
    res = dblquad(
                #~ scipy.LowLevelCallable(nb_integrand), # some python function
                nb_integrand, # some python function
                  0.0,       # outer integral lower
                  2.0*np.pi, # outer integral upper
                  lambda theta: 0.0, # inner integral lower
                  lambda theta: a,   # inner integral upper
                  args=(delta_y, sigma) # additional arguments
    )

t1 = time.clock()
print(res)

, но я получаю

            Traceback (most recent call last):
              File "test.py", line 59, in <module>
                args=(delta_y, sigma) # additional arguments
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 581, in dblquad
                opts={"epsabs": epsabs, "epsrel": epsrel})
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 805, in nquad
                return _NQuad(func, ranges, opts, full_output).integrate(*args)
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 860, in integrate
                **opt)
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 341, in quad
                points)
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 448, in _quad
                return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 860, in integrate
                **opt)
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 341, in quad
                points)
              File "E:\prg\py\Anaconda3_64\lib\site-packages\scipy\integrate\quadpack.py", line 448, in _quad
                return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
            ValueError: Invalid scipy.LowLevelCallable signature "double (double, double)". Expected one of: ['double (double)', 'double (int, double)', 'double (long, double)']

так какой-нибудь намек?Спасибо

...