cosmotool/python/_fast_interp.pyx

33 lines
812 B
Cython
Raw Normal View History

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]