Commit 27e8e9fe authored by Martin Reinecke's avatar Martin Reinecke

de-cythonize

parent a07ff248
Pipeline #11560 passed with stage
in 21 minutes and 25 seconds
import numpy as np
cimport numpy as np
def buildLm(inp, **kwargs):
if inp.dtype == np.dtype('float32'):
......@@ -14,40 +12,36 @@ def buildIdx(inp, **kwargs):
else:
return _buildIdx(inp, **kwargs)
cpdef np.ndarray[np.float32_t, ndim=1] _buildIdx_f(np.ndarray[np.complex64_t,
ndim=1] nr, np.int_t lmax):
cdef np.int size = (lmax+1)*(lmax+1)
def _buildIdx_f(nr, lmax):
size = (lmax+1)*(lmax+1)
cdef np.ndarray final=np.zeros([size], dtype=np.float32)
final=np.zeros([size], dtype=np.float32)
final[0:lmax+1] = nr[0:lmax+1].real
final[lmax+1::2] = np.sqrt(2)*nr[lmax+1:].real
final[lmax+2::2] = np.sqrt(2)*nr[lmax+1:].imag
return final
cpdef np.ndarray[np.float64_t, ndim=1] _buildIdx(np.ndarray[np.complex128_t,
ndim=1] nr, np.int_t lmax):
cdef np.int size = (lmax+1)*(lmax+1)
def _buildIdx(nr, lmax):
size = (lmax+1)*(lmax+1)
cdef np.ndarray final=np.zeros([size], dtype=np.float64)
final=np.zeros([size], dtype=np.float64)
final[0:lmax+1] = nr[0:lmax+1].real
final[lmax+1::2] = np.sqrt(2)*nr[lmax+1:].real
final[lmax+2::2] = np.sqrt(2)*nr[lmax+1:].imag
return final
cpdef np.ndarray[np.complex64_t, ndim=1] _buildLm_f(np.ndarray[np.float32_t,
ndim=1] nr, np.int_t lmax):
cdef np.int size = (len(nr)-lmax-1)/2+lmax+1
def _buildLm_f(nr, lmax):
size = (len(nr)-lmax-1)/2+lmax+1
cdef np.ndarray res=np.zeros([size], dtype=np.complex64)
res=np.zeros([size], dtype=np.complex64)
res[0:lmax+1] = nr[0:lmax+1]
res[lmax+1:] = np.sqrt(0.5)*(nr[lmax+1::2] + 1j*nr[lmax+2::2])
return res
cpdef np.ndarray[np.complex128_t, ndim=1] _buildLm(np.ndarray[np.float64_t,
ndim=1] nr, np.int_t lmax):
cdef np.int size = (len(nr)-lmax-1)/2+lmax+1
def _buildLm(nr, lmax):
size = (len(nr)-lmax-1)/2+lmax+1
cdef np.ndarray res=np.zeros([size], dtype=np.complex128)
res=np.zeros([size], dtype=np.complex128)
res[0:lmax+1] = nr[0:lmax+1]
res[lmax+1:] = np.sqrt(0.5)*(nr[lmax+1::2] + 1j*nr[lmax+2::2])
return res
import numpy as np
cimport numpy as np
cpdef _distance_array_helper(np.ndarray[np.int_t] index_array, np.int_t lmax):
cdef np.int size = (lmax + 1) * (lmax + 1)
cdef np.ndarray res = np.zeros([len(index_array)], dtype=np.float128)
for idx, index_full in enumerate(index_array):
if index_full <= lmax:
index_half = index_full
else:
if (index_full - lmax) % 2 == 0:
index_half = (index_full + lmax) / 2;
else:
index_half = (index_full + lmax + 1) / 2;
m = (np.ceil(((2 * lmax + 1) -
np.sqrt((2 * lmax + 1)**2 -
8 * (index_half - lmax))) / 2)).astype(int)
res[idx] = index_half - m * (2 * lmax + 1 - m) // 2
return res
......@@ -25,13 +25,18 @@ from nifty.spaces.space import Space
from nifty.config import nifty_configuration as gc,\
dependency_injector as gdi
from lm_helper import _distance_array_helper
from d2o import arange
gl = gdi.get('libsharp_wrapper_gl')
hp = gdi.get('healpy')
def _distance_array_helper(index_array, lmax):
u=2*lmax+1
index_half=(index_array+np.minimum(lmax,index_array)+1)//2
m = (np.ceil((u - np.sqrt(u*u - 8 * (index_half - lmax))) / 2)).astype(int)
res = (index_half - m * (u - m) // 2).astype(np.float64)
return res
class LMSpace(Space):
"""
......
......@@ -35,9 +35,6 @@ setup(name="ift_nifty",
package_dir={"nifty": "nifty"},
zip_safe=False,
ext_modules=cythonize([
"nifty/operators/fft_operator/transformations/"
"lm_transformation_factory.pyx",
"nifty/spaces/lm_space/lm_helper.pyx",
"nifty/operators/smoothing_operator/smooth_util.pyx"
]),
include_dirs=[numpy.get_include()],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment