def test_idft_init(impl):
    # Just check if the code runs at all; this uses the init function of
    # DiscreteFourierTransform, so we don't need exhaustive tests here
    shape = (4, 5)
    ran = _dft_space(shape, dtype='complex128')
    ran_hc = _dft_space(shape, dtype='float64')
    dom = _dft_space(shape, dtype='complex128')
    dom_hc = _dft_space((3, 5), dtype='complex128')

    # Implicit range
    DiscreteFourierTransformInverse(dom, impl=impl)

    # Explicit range
    DiscreteFourierTransformInverse(ran, domain=dom, impl=impl)
    DiscreteFourierTransformInverse(ran_hc, domain=dom_hc, axes=(0,),
                                    impl=impl, halfcomplex=True)
Esempio n. 2
0
def test_dft_call(impl):

    # 2d, complex, all ones and random back & forth
    shape = (4, 5)
    dft_dom = odl.discr_sequence_space(shape, dtype='complex64')
    dft = DiscreteFourierTransform(domain=dft_dom, impl=impl)
    idft = DiscreteFourierTransformInverse(range=dft_dom, impl=impl)

    assert dft.domain == idft.range
    assert dft.range == idft.domain

    one = dft.domain.one()
    one_dft1 = dft(one, flags=('FFTW_ESTIMATE', ))
    one_dft2 = dft.inverse.inverse(one, flags=('FFTW_ESTIMATE', ))
    one_dft3 = dft.adjoint.adjoint(one, flags=('FFTW_ESTIMATE', ))
    true_dft = [
        [20, 0, 0, 0, 0],  # along all axes by default
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0]
    ]
    assert np.allclose(one_dft1, true_dft)
    assert np.allclose(one_dft2, true_dft)
    assert np.allclose(one_dft3, true_dft)

    one_idft1 = idft(one_dft1, flags=('FFTW_ESTIMATE', ))
    one_idft2 = dft.inverse(one_dft1, flags=('FFTW_ESTIMATE', ))
    one_idft3 = dft.adjoint(one_dft1, flags=('FFTW_ESTIMATE', ))
    assert np.allclose(one_idft1, one)
    assert np.allclose(one_idft2, one)
    assert np.allclose(one_idft3, one)

    rand_arr = noise_element(dft_dom)
    rand_arr_dft = dft(rand_arr, flags=('FFTW_ESTIMATE', ))
    rand_arr_idft = idft(rand_arr_dft, flags=('FFTW_ESTIMATE', ))
    assert (rand_arr_idft - rand_arr).norm() < 1e-6

    # 2d, halfcomplex, first axis
    shape = (4, 5)
    axes = 0
    dft_dom = odl.discr_sequence_space(shape, dtype='float32')
    dft = DiscreteFourierTransform(domain=dft_dom,
                                   impl=impl,
                                   halfcomplex=True,
                                   axes=axes)
    idft = DiscreteFourierTransformInverse(range=dft_dom,
                                           impl=impl,
                                           halfcomplex=True,
                                           axes=axes)

    assert dft.domain == idft.range
    assert dft.range == idft.domain

    one = dft.domain.one()
    one_dft = dft(one, flags=('FFTW_ESTIMATE', ))
    true_dft = [
        [4, 4, 4, 4, 4],  # transform axis shortened
        [0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0]
    ]
    assert np.allclose(one_dft, true_dft)

    one_idft1 = idft(one_dft, flags=('FFTW_ESTIMATE', ))
    one_idft2 = dft.inverse(one_dft, flags=('FFTW_ESTIMATE', ))
    assert np.allclose(one_idft1, one)
    assert np.allclose(one_idft2, one)

    rand_arr = noise_element(dft_dom)
    rand_arr_dft = dft(rand_arr, flags=('FFTW_ESTIMATE', ))
    rand_arr_idft = idft(rand_arr_dft, flags=('FFTW_ESTIMATE', ))
    assert (rand_arr_idft - rand_arr).norm() < 1e-6