示例#1
0
def test_unnormalized_1D():
    x = np.random.randn(128) + 1j * np.random.randn(128)
    z = _fftn(x, axes=(0, ), shift=0, inplace=False)
    x2 = _ifftn(z, axes=(0, ), shift=0, inplace=False, normalize=False)
    yield npt.assert_almost_equal(np.linalg.norm(x2),
                                  np.linalg.norm(x) * len(x))
    z = _fftn(x, axes=(0, ), shift=1, inplace=False, normalize=False)
    x2 = _ifftn(z, axes=(0, ), shift=1, inplace=False, normalize=False)
    yield npt.assert_almost_equal(np.linalg.norm(x2),
                                  np.linalg.norm(x) * len(x))
示例#2
0
def test_unnormalized_1D():
    x = np.random.randn(128) + 1j*np.random.randn(128)
    z = _fftn(x, axes=(0,), shift=0, inplace=False)
    x2 = _ifftn(z, axes=(0,), shift=0, inplace=False, normalize=False)
    yield npt.assert_almost_equal(
        np.linalg.norm(x2), np.linalg.norm(x)*len(x)
        )
    z = _fftn(x, axes=(0,), shift=1, inplace=False, normalize=False)
    x2 = _ifftn(z, axes=(0,), shift=1, inplace=False, normalize=False)
    yield npt.assert_almost_equal(
        np.linalg.norm(x2), np.linalg.norm(x)*len(x)
        )
示例#3
0
def test_simple_multi_fft_1_D():
    shift = 1
    dt = 'D'
    c = np.outer(np.ones(64), ref_1D_32hz(shift, dt))
    c2 = c.copy()
    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)
    yield sum_of_sqr_comp(c, c_np, 'total energy not equal')
    yield sum_of_sqr_comp(ct, ct_np, 'total energy not equal')
示例#4
0
def test_simple_multi_fft_1_D():
    shift = 1
    dt = 'D'
    c = np.outer(np.ones(64), ref_1D_32hz(shift, dt))
    c2 = c.copy()
    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)
    yield sum_of_sqr_comp(c, c_np, 'total energy not equal')
    yield sum_of_sqr_comp(ct, ct_np, 'total energy not equal')
示例#5
0
def test_strided_1d_fft_1_D():
    shift = 1
    dt = 'D'
    rand_3d = (np.random.randn(40, 50, 60) + \
               1j*np.random.randn(40, 50, 60)).astype(dt)

    r1 = rand_3d.copy().transpose(0, 2, 1)
    r1_2 = rand_3d.copy().transpose(0, 2, 1)
    r2 = rand_3d.copy().transpose(1, 0, 2)
    r2_2 = rand_3d.copy().transpose(1, 0, 2)

    _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)

    yield sum_of_sqr_comp(r1, r1_np, 'axis0 dtype=' + dt)
    yield sum_of_sqr_comp(r2, r2_np, 'axis1 dtype=' + dt)
示例#6
0
def test_strided_1d_fft_1_D():
    shift = 1
    dt = 'D'
    rand_3d = (np.random.randn(40, 50, 60) + \
               1j*np.random.randn(40, 50, 60)).astype(dt)
    
    r1 = rand_3d.copy().transpose(0,2,1)
    r1_2 = rand_3d.copy().transpose(0,2,1)
    r2 = rand_3d.copy().transpose(1,0,2)
    r2_2 = rand_3d.copy().transpose(1,0,2)

    _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)

    yield sum_of_sqr_comp(r1, r1_np, 'axis0 dtype='+dt)
    yield sum_of_sqr_comp(r2, r2_np, 'axis1 dtype='+dt)
示例#7
0
def test_roundtrip_inplace_1_D():
    shift = 1
    dt = 'D'
    grid = np.arange(128)
    mu = 43.
    stdv = 3.
    g = (np.exp(-(grid - mu)**2 / (2 * stdv**2)) /
         (2 * np.pi * stdv**2)).astype(dt)
    g2 = g.copy()
    g_bkp = g.copy()
    _fftn(g, inplace=True, shift=shift)
    gw_np = reference_fftn(g2, shift=shift, axes=(0, ))
    yield npt.assert_array_almost_equal(
        g, gw_np, err_msg='differs from numpy fft ref, shift=%d' % shift)
    yield sum_of_sqr_comp(g, gw_np)

    _ifftn(g, inplace=True, shift=shift)
    yield npt.assert_array_almost_equal(
        g_bkp, g, err_msg='roundtrip transforms diverge, shift=%d' % shift)
    yield sum_of_sqr_comp(g_bkp, g)
示例#8
0
def test_roundtrip_inplace_1_D():
    shift = 1
    dt = 'D'
    grid = np.arange(128)
    mu = 43.
    stdv = 3.
    g = (np.exp(-(grid-mu)**2 / (2*stdv**2)) / (2*np.pi*stdv**2)).astype(dt)
    g2 = g.copy()
    g_bkp = g.copy()
    _fftn(g, inplace=True, shift=shift)
    gw_np = reference_fftn(g2, shift=shift, axes=(0,))
    yield npt.assert_array_almost_equal(
        g, gw_np, err_msg='differs from numpy fft ref, shift=%d'%shift
        )
    yield sum_of_sqr_comp(g, gw_np)

    _ifftn(g, inplace=True, shift=shift)
    yield npt.assert_array_almost_equal(
        g_bkp, g, err_msg='roundtrip transforms diverge, shift=%d'%shift
        )
    yield sum_of_sqr_comp(g_bkp, g)
示例#9
0
def _get_2D_fft(shift, dt):
    c = ref_2D_grating(shift, dt)
    c2 = c.copy()
    _fftn(c, axes=(0, 1), shift=shift, inplace=True)
    c_np = reference_fftn(c2, axes=(0, 1), shift=shift)
    return c, c_np
示例#10
0
def _get_1D_fft(shift, dt):
    c = ref_1D_32hz(shift, dt)
    c2 = c.copy()
    _fftn(c, axes=(0, ), shift=shift, inplace=True)
    c_np = reference_fftn(c2, axes=(0, ), shift=shift)
    return c, c_np
示例#11
0
def _get_2D_fft(shift, dt):
    c = ref_2D_grating(shift, dt)
    c2 = c.copy()
    _fftn(c, axes=(0,1), shift=shift, inplace=True)
    c_np = reference_fftn(c2, axes=(0,1), shift=shift)
    return c, c_np
示例#12
0
def _get_1D_fft(shift, dt):
    c = ref_1D_32hz(shift, dt)
    c2 = c.copy()
    _fftn(c, axes=(0,), shift=shift, inplace=True)
    c_np = reference_fftn(c2, axes=(0,), shift=shift)
    return c, c_np