Beispiel #1
0
 def test_simple_multi_fft(self, **kwargs):
     shift = kwargs.get('shift', 0)        
     c = np.outer(np.ones(64), self.ref_1D_32hz).astype(self.dt)
     c2 = np.outer(np.ones(64), self.ref_1D_32hz).astype(self.dt)
     ct = c.copy().T
     ct2 = c.copy().T
     _fftn(c, axes=(-1,), inplace=True, shift=shift)
     _fftn(ct, axes=(0,), inplace=True, shift=shift)
     c_np = reference_fftn(c2, axes=(-1,), shift=shift)
     ct_np = reference_fftn(ct2, axes=(0,), shift=shift)
     self.nrg_comp(c, c_np, err_msg='dtype = %s'%self.dt.char)
     self.nrg_comp(ct, ct_np, err_msg='transpose dtype=%s'%self.dt.char)
Beispiel #2
0
 def test_simple_multi_fft(self, **kwargs):
     shift = kwargs.get('shift', 0)
     c = np.outer(np.ones(64), self.ref_1D_32hz).astype(self.dt)
     c2 = np.outer(np.ones(64), self.ref_1D_32hz).astype(self.dt)
     ct = c.copy().T
     ct2 = c.copy().T
     _fftn(c, axes=(-1, ), inplace=True, shift=shift)
     _fftn(ct, axes=(0, ), inplace=True, shift=shift)
     c_np = reference_fftn(c2, axes=(-1, ), shift=shift)
     ct_np = reference_fftn(ct2, axes=(0, ), shift=shift)
     self.nrg_comp(c, c_np, err_msg='dtype = %s' % self.dt.char)
     self.nrg_comp(ct, ct_np, err_msg='transpose dtype=%s' % self.dt.char)
Beispiel #3
0
 def test_simple_1D_fft(self, **kwargs):
     shift = kwargs.get('shift', 0)
     c = self.ref_1D_32hz.astype(self.dt)
     c2 = self.ref_1D_32hz.astype(self.dt)
     _fftn(c, axes=(0, ), shift=shift, inplace=True)
     c_np = reference_fftn(c2, axes=(0, ), shift=shift)
     self.comp(np.dot(c, c.conj()).real, np.dot(c_np, c_np.conj()).real)
     self.nrg_comp(c, c_np)
     # analytically, the DFT indexed from 0,127 of s
     # is a weighted delta at k=32
     C_a = np.zeros_like(c)
     C_a[32 + shift * 64] = 128.
     self.comp(c, C_a, err_msg='dtype = %s' % self.dt.char)
     self.nrg_comp(c, C_a)
Beispiel #4
0
 def test_simple_2D_fft(self, **kwargs):
     shift = kwargs.get('shift', 0)
     c = self.ref_2D_grating.astype(self.dt)
     c2 = self.ref_2D_grating.astype(self.dt)
     _fftn(c, axes=(0, 1), shift=shift, inplace=True)
     c_np = reference_fftn(c2, axes=(0, 1), shift=shift)
     ##         self.comp(np.dot(c.flat[:],c.flat[:].conj()).real,
     ##                   np.dot(c_np.flat[:], c_np.flat[:].conj()).real)
     self.nrg_comp(c, c_np)
     # analytically, the DFT indexed from 0,127 of s
     # is a weighted delta at i=13, j=4
     C_a = np.zeros_like(c)
     C_a[13 + shift * 64, 4 + shift * 64] = 128**2
     self.comp(c, C_a, err_msg='dtype = %s' % self.dt.char)
     self.nrg_comp(c, C_a)
Beispiel #5
0
    def test_simple_2D_fft(self, **kwargs):
        shift = kwargs.get('shift', 0)
        c = self.ref_2D_grating.astype(self.dt)
        c2 = self.ref_2D_grating.astype(self.dt)
        _fftn(c, axes=(0,1), shift=shift, inplace=True)
        c_np = reference_fftn(c2, axes=(0,1), shift=shift)
##         self.comp(np.dot(c.flat[:],c.flat[:].conj()).real,
##                   np.dot(c_np.flat[:], c_np.flat[:].conj()).real)
        self.nrg_comp(c, c_np)
        # analytically, the DFT indexed from 0,127 of s
        # is a weighted delta at i=13, j=4
        C_a = np.zeros_like(c)
        C_a[13 + shift*64, 4 + shift*64] = 128**2
        self.comp(c, C_a, err_msg='dtype = %s'%self.dt.char)
        self.nrg_comp(c, C_a)
Beispiel #6
0
 def test_simple_1D_fft(self, **kwargs):
     shift = kwargs.get('shift', 0)
     c = self.ref_1D_32hz.astype(self.dt)
     c2 = self.ref_1D_32hz.astype(self.dt)
     _fftn(c, axes=(0,), shift=shift, inplace=True)
     c_np = reference_fftn(c2, axes=(0,), shift=shift)
     self.comp(np.dot(c,c.conj()).real,
               np.dot(c_np, c_np.conj()).real)
     self.nrg_comp(c, c_np)
     # analytically, the DFT indexed from 0,127 of s
     # is a weighted delta at k=32
     C_a = np.zeros_like(c)
     C_a[32 + shift*64] = 128.
     self.comp(c, C_a, err_msg='dtype = %s'%self.dt.char)
     self.nrg_comp(c, C_a)        
Beispiel #7
0
    def test_roundtrip_outofplace(self, **kwargs):
        shift = kwargs.get('shift', 0)

        grid = np.arange(128)
        mu = 43.
        stdv = 3.
        g = (np.exp(-(grid - mu)**2 / (2 * stdv**2)) /
             (2 * np.pi * stdv**2)).astype(self.dt)
        g2 = g.copy()
        g_bkp = g.copy()
        ##         gw = np.empty_like(g)
        ##         grt = np.empty_like(g)

        gw = _fftn(g, inplace=False, shift=shift)
        gw_np = reference_fftn(g2, axes=(0, ), shift=shift)
        grt = _ifftn(gw, inplace=False, shift=shift)
        grt_np = reference_ifftn(gw, axes=(0, ), shift=shift)

        # strong assertion that g is not altered at all
        assert (g == g_bkp).all(), 'out of place xform error, shift=%d' % shift
        self.comp(gw,
                  gw_np,
                  err_msg='differs from numpy fft ref, shift=%d' % shift)
        self.nrg_comp(gw, gw_np)
        self.comp(g,
                  grt,
                  err_msg='roundtrip transforms diverge, shift=%d' % shift)
        self.nrg_comp(g, grt)
Beispiel #8
0
    def test_roundtrip_outofplace(self, **kwargs):
        shift = kwargs.get('shift', 0)

        grid = np.arange(128)
        mu = 43.
        stdv = 3.
        g = (np.exp(-(grid-mu)**2 / (2*stdv**2)) / (2*np.pi*stdv**2)).astype(self.dt)
        g2 = g.copy()
        g_bkp = g.copy()
##         gw = np.empty_like(g)
##         grt = np.empty_like(g)

        gw = _fftn(g, inplace=False, shift=shift)
        gw_np = reference_fftn(g2, axes=(0,), shift=shift)
        grt = _ifftn(gw, inplace=False, shift=shift)
        grt_np = reference_ifftn(gw, axes=(0,), shift=shift)


        # strong assertion that g is not altered at all
        assert (g==g_bkp).all(), 'out of place xform error, shift=%d'%shift
        self.comp(gw, gw_np,
                  err_msg='differs from numpy fft ref, shift=%d'%shift)
        self.nrg_comp(gw, gw_np)
        self.comp(g, grt,
                  err_msg='roundtrip transforms diverge, shift=%d'%shift)
        self.nrg_comp(g, grt)        
Beispiel #9
0
    def test_strided_1d_fft(self, **kwargs):
        shift = kwargs.get('shift', 0)
        r1 = self.rand_3d.copy().transpose(0, 2, 1).astype(self.dt)
        r1_2 = self.rand_3d.copy().transpose(0, 2, 1).astype(self.dt)
        r2 = self.rand_3d.copy().transpose(1, 0, 2).astype(self.dt)
        r2_2 = self.rand_3d.copy().transpose(1, 0, 2).astype(self.dt)

        _fftn(r1, axes=(0, ), inplace=True, shift=shift)
        _fftn(r2, axes=(1, ), inplace=True, shift=shift)
        r1_np = reference_fftn(r1_2, axes=(0, ), shift=shift)
        r2_np = reference_fftn(r2_2, axes=(1, ), shift=shift)

        self.nrg_comp(r1, r1_np, err_msg='axis0 dtype = %s' % self.dt.char)
        ##         self.comp( (r1*r1.conj()).real.sum(),
        ##                    (r1_np*r1_np.conj()).real.sum(),
        ##                    err_msg='axis0 dtype = %s'%self.dt.char)
        self.nrg_comp(r2, r2_np, err_msg='axis1 dtype = %s' % self.dt.char)
Beispiel #10
0
 def test_roundtrip_inplace(self, **kwargs):
     shift = kwargs.get('shift', 0)
     grid = np.arange(128)
     mu = 43.
     stdv = 3.
     g = (np.exp(-(grid-mu)**2 / (2*stdv**2)) / (2*np.pi*stdv**2)).astype(self.dt)
     g2 = g.copy()
     g_bkp = g.copy()
     _fftn(g, inplace=True, shift=shift)
     gw_np = reference_fftn(g2, shift=shift, axes=(0,))
     
     self.comp(g, gw_np,
               err_msg='differs from numpy fft ref, shift=%d'%shift)
     self.nrg_comp(g, gw_np)
     _ifftn(g, inplace=True, shift=shift)
     self.comp(g_bkp, g,
               err_msg='roundtrip transforms diverge, shift=%d'%shift)
     self.nrg_comp(g_bkp, g)        
Beispiel #11
0
    def test_strided_1d_fft(self, **kwargs):
        shift = kwargs.get('shift', 0)        
        r1 = self.rand_3d.copy().transpose(0,2,1).astype(self.dt)
        r1_2 = self.rand_3d.copy().transpose(0,2,1).astype(self.dt)
        r2 = self.rand_3d.copy().transpose(1,0,2).astype(self.dt)
        r2_2 = self.rand_3d.copy().transpose(1,0,2).astype(self.dt)        

        _fftn(r1, axes=(0,), inplace=True, shift=shift)
        _fftn(r2, axes=(1,), inplace=True, shift=shift)
        r1_np = reference_fftn(r1_2, axes=(0,), shift=shift)
        r2_np = reference_fftn(r2_2, axes=(1,), shift=shift)

        self.nrg_comp(r1, r1_np,
                      err_msg='axis0 dtype = %s'%self.dt.char)
##         self.comp( (r1*r1.conj()).real.sum(),
##                    (r1_np*r1_np.conj()).real.sum(),
##                    err_msg='axis0 dtype = %s'%self.dt.char)
        self.nrg_comp(r2, r2_np,
                      err_msg='axis1 dtype = %s'%self.dt.char)
Beispiel #12
0
    def test_roundtrip_inplace(self, **kwargs):
        shift = kwargs.get('shift', 0)
        grid = np.arange(128)
        mu = 43.
        stdv = 3.
        g = (np.exp(-(grid - mu)**2 / (2 * stdv**2)) /
             (2 * np.pi * stdv**2)).astype(self.dt)
        g2 = g.copy()
        g_bkp = g.copy()
        _fftn(g, inplace=True, shift=shift)
        gw_np = reference_fftn(g2, shift=shift, axes=(0, ))

        self.comp(g,
                  gw_np,
                  err_msg='differs from numpy fft ref, shift=%d' % shift)
        self.nrg_comp(g, gw_np)
        _ifftn(g, inplace=True, shift=shift)
        self.comp(g_bkp,
                  g,
                  err_msg='roundtrip transforms diverge, shift=%d' % shift)
        self.nrg_comp(g_bkp, g)