13 #include <Eigen/CXX11/Tensor> 17 template <
int DataLayout>
28 tensor_after_fft = tensor.template fft<Eigen::BothParts, Eigen::FFT_FORWARD>(fft);
29 tensor_after_fft_ifft = tensor_after_fft.template fft<Eigen::BothParts, Eigen::FFT_REVERSE>(fft);
31 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(0), sequence_length);
32 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(0), sequence_length);
34 for (
int i = 0; i < sequence_length; ++i) {
35 VERIFY_IS_APPROX(static_cast<float>(tensor(i)), static_cast<float>(
std::real(tensor_after_fft_ifft(i))));
39 template <
int DataLayout>
51 tensor_after_fft = tensor.template fft<Eigen::BothParts, Eigen::FFT_FORWARD>(fft);
52 tensor_after_fft_ifft = tensor_after_fft.template fft<Eigen::BothParts, Eigen::FFT_REVERSE>(fft);
54 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(0), dim0);
55 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(1), dim1);
56 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(0), dim0);
57 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(1), dim1);
59 for (
int i = 0; i < dim0; ++i) {
60 for (
int j = 0; j < dim1; ++j) {
62 VERIFY_IS_APPROX(static_cast<float>(tensor(i,j)), static_cast<float>(
std::real(tensor_after_fft_ifft(i,j))));
67 template <
int DataLayout>
80 tensor_after_fft = tensor.template fft<Eigen::BothParts, Eigen::FFT_FORWARD>(fft);
81 tensor_after_fft_ifft = tensor_after_fft.template fft<Eigen::BothParts, Eigen::FFT_REVERSE>(fft);
83 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(0), dim0);
84 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(1), dim1);
85 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(2), dim2);
86 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(0), dim0);
87 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(1), dim1);
88 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(2), dim2);
90 for (
int i = 0; i < dim0; ++i) {
91 for (
int j = 0; j < dim1; ++j) {
92 for (
int k = 0; k < dim2; ++k) {
93 VERIFY_IS_APPROX(static_cast<float>(tensor(i,j,k)), static_cast<float>(
std::real(tensor_after_fft_ifft(i,j,k))));
99 template <
int DataLayout>
111 tensor_after_fft = tensor.template fft<Eigen::BothParts, Eigen::FFT_FORWARD>(fft);
112 tensor_after_fft_ifft = tensor_after_fft.template fft<Eigen::RealPart, Eigen::FFT_REVERSE>(fft);
114 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(0), dim0);
115 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(1), dim1);
116 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(2), dim2);
117 VERIFY_IS_EQUAL(tensor_after_fft.
dimension(3), dim3);
118 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(0), dim0);
119 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(1), dim1);
120 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(2), dim2);
121 VERIFY_IS_EQUAL(tensor_after_fft_ifft.dimension(3), dim3);
123 for (
int i = 0; i < dim0; ++i) {
124 for (
int j = 0; j < dim1; ++j) {
125 for (
int k = 0; k < dim2; ++k) {
126 for (
int l = 0; l < dim3; ++l) {
127 VERIFY_IS_APPROX(static_cast<float>(tensor(i,j,k,l)), static_cast<float>(tensor_after_fft_ifft(i,j,k,l)));
135 CALL_SUBTEST(test_1D_fft_ifft_invariant<ColMajor>(4));
136 CALL_SUBTEST(test_1D_fft_ifft_invariant<ColMajor>(16));
137 CALL_SUBTEST(test_1D_fft_ifft_invariant<ColMajor>(32));
138 CALL_SUBTEST(test_1D_fft_ifft_invariant<ColMajor>(1024*1024));
140 CALL_SUBTEST(test_2D_fft_ifft_invariant<ColMajor>(4,4));
141 CALL_SUBTEST(test_2D_fft_ifft_invariant<ColMajor>(8,16));
142 CALL_SUBTEST(test_2D_fft_ifft_invariant<ColMajor>(16,32));
143 CALL_SUBTEST(test_2D_fft_ifft_invariant<ColMajor>(1024,1024));
145 CALL_SUBTEST(test_3D_fft_ifft_invariant<ColMajor>(4,4,4));
146 CALL_SUBTEST(test_3D_fft_ifft_invariant<ColMajor>(8,16,32));
147 CALL_SUBTEST(test_3D_fft_ifft_invariant<ColMajor>(16,4,8));
148 CALL_SUBTEST(test_3D_fft_ifft_invariant<ColMajor>(256,256,256));
150 CALL_SUBTEST(test_sub_fft_ifft_invariant<ColMajor>(4,4,4,4));
151 CALL_SUBTEST(test_sub_fft_ifft_invariant<ColMajor>(8,16,32,64));
152 CALL_SUBTEST(test_sub_fft_ifft_invariant<ColMajor>(16,4,8,12));
153 CALL_SUBTEST(test_sub_fft_ifft_invariant<ColMajor>(64,64,64,64));
EIGEN_DEVICE_FUNC RealReturnType real() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static void test_sub_fft_ifft_invariant(int dim0, int dim1, int dim2, int dim3)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
static void test_3D_fft_ifft_invariant(int dim0, int dim1, int dim2)
static void test_2D_fft_ifft_invariant(int dim0, int dim1)
static void test_1D_fft_ifft_invariant(int sequence_length)
void test_cxx11_tensor_ifft()