lm_transformation_factory.pyx 1.73 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1

csongor's avatar
csongor committed
2
import numpy as np
Martin Reinecke's avatar
Martin Reinecke committed
3
cimport numpy as np
csongor's avatar
csongor committed
4

csongor's avatar
csongor committed
5
6
7
8
9
10
11
12
13
14
15
16
def buildLm(inp, **kwargs):
    if inp.dtype == np.dtype('float32'):
        return _buildLm_f(inp, **kwargs)
    else:
        return _buildLm(inp, **kwargs)

def buildIdx(inp, **kwargs):
    if inp.dtype == np.dtype('complex64'):
        return _buildIdx_f(inp, **kwargs)
    else:
        return _buildIdx(inp, **kwargs)

Martin Reinecke's avatar
Martin Reinecke committed
17
18
19
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)
csongor's avatar
csongor committed
20

Martin Reinecke's avatar
Martin Reinecke committed
21
    cdef np.ndarray final=np.zeros([size], dtype=np.float32)
22
23
24
    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
csongor's avatar
csongor committed
25
26
    return final

Martin Reinecke's avatar
Martin Reinecke committed
27
28
29
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)
csongor's avatar
csongor committed
30

Martin Reinecke's avatar
Martin Reinecke committed
31
    cdef np.ndarray final=np.zeros([size], dtype=np.float64)
32
33
34
    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
35
36
    return final

Martin Reinecke's avatar
Martin Reinecke committed
37
38
39
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
csongor's avatar
csongor committed
40

Martin Reinecke's avatar
Martin Reinecke committed
41
    cdef np.ndarray res=np.zeros([size], dtype=np.complex64)
csongor's avatar
csongor committed
42
    res[0:lmax+1] = nr[0:lmax+1]
43
    res[lmax+1:] = np.sqrt(0.5)*(nr[lmax+1::2] + 1j*nr[lmax+2::2])
csongor's avatar
csongor committed
44
45
    return res

Martin Reinecke's avatar
Martin Reinecke committed
46
47
48
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
csongor's avatar
csongor committed
49

Martin Reinecke's avatar
Martin Reinecke committed
50
    cdef np.ndarray res=np.zeros([size], dtype=np.complex128)
csongor's avatar
csongor committed
51
    res[0:lmax+1] = nr[0:lmax+1]
52
    res[lmax+1:] = np.sqrt(0.5)*(nr[lmax+1::2] + 1j*nr[lmax+2::2])
53
    return res