Added fast parallel interpolator. Some adjustment to BORG icgen

This commit is contained in:
Guilhem Lavaux 2015-08-28 11:56:35 +02:00
parent 21507e3013
commit 8d4ee1bfdd
6 changed files with 48 additions and 7 deletions

32
python/_fast_interp.pyx Normal file
View file

@ -0,0 +1,32 @@
from cpython cimport bool
from cython cimport view
from cython.parallel import prange, parallel
from libc.math cimport sin, cos, abs, floor, round, sqrt
import numpy as np
cimport numpy as npx
cimport cython
__all__=["fast_interp"]
@cython.boundscheck(False)
@cython.cdivision(True)
def fast_interp(npx.float64_t xmin, npx.float64_t dx, npx.float64_t[:] A, npx.float64_t[:] y, npx.float64_t[:] out, npx.float64_t beyond_val=npx.nan):
cdef double rq, q
cdef int iq
cdef long i, Asize, ysize
cdef npx.float64_t[:] out0
ysize = y.size
out0 = out
Asize = A.size
with nogil:
for i in prange(ysize):
q = (y[i] - xmin) / dx
iq = int(floor(q))
rq = (q-iq)
if iq+1 >= Asize or iq < 0:
out0[i] = beyond_val
else:
out0[i] = rq * A[iq+1] + (1-rq)*A[iq]