Branch selection for Δ_n in Ewald sum
[qpms.git] / qpms / cyewaldtest.pyx
blob4d545b1301ca4b36865c96763ec55d36c7a1eac2
1 from .qpms_cdefs cimport *
2 from libc.stdlib cimport malloc, free, calloc
3 import numpy as np
5 cdef extern from "ewald.h":
6 void ewald3_2_sigma_long_Delta(cdouble *target, double *err, int maxn, cdouble x, int xbranch, cdouble z)
7 void ewald3_2_sigma_long_Delta_series(cdouble *target, double *err, int maxn, cdouble x, int xbranch, cdouble z)
8 void ewald3_2_sigma_long_Delta_recurrent(cdouble *target, double *err, int maxn, cdouble x, int xbranch, cdouble z)
9 int complex_gamma_inc_e(double a, cdouble x, int xbranch, qpms_csf_result *result)
11 def e32_Delta(int maxn, cdouble x, cdouble z, int xbranch = 0, get_err=True, method='auto'):
12 cdef np.ndarray[double, ndim=1] err_np
13 cdef double[::1] err_view
14 cdef np.ndarray[np.complex_t, ndim=1] target_np = np.empty((maxn+1,), dtype=complex, order='C')
15 cdef cdouble[::1] target_view = target_np
16 if get_err:
17 err_np = np.empty((maxn+1,), order='C')
18 err_view = err_np
19 if method == 'recurrent':
20 ewald3_2_sigma_long_Delta_recurrent(&target_view[0], &err_view[0] if get_err else NULL, maxn, x, xbranch, z)
21 elif method == 'series':
22 ewald3_2_sigma_long_Delta_series(&target_view[0], &err_view[0] if get_err else NULL, maxn, x, xbranch, z)
23 else:
24 ewald3_2_sigma_long_Delta(&target_view[0], &err_view[0] if get_err else NULL, maxn, x, xbranch, z)
25 if get_err:
26 return target_np, err_np
27 else:
28 return target_np
30 def gamma_inc(double a, cdouble x, int xbranch=0):
31 cdef qpms_csf_result res
32 complex_gamma_inc_e(a, x, xbranch, &res)
33 return res.val