diff options
Diffstat (limited to 'unsupported/test/cxx11_tensor_fft.cpp')
-rw-r--r-- | unsupported/test/cxx11_tensor_fft.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/unsupported/test/cxx11_tensor_fft.cpp b/unsupported/test/cxx11_tensor_fft.cpp index 2f14ebc62..2e1008eca 100644 --- a/unsupported/test/cxx11_tensor_fft.cpp +++ b/unsupported/test/cxx11_tensor_fft.cpp @@ -224,7 +224,35 @@ static void test_fft_real_input_energy() { } } -void test_cxx11_tensor_fft() { +template <typename RealScalar> +static void test_fft_non_power_of_2_round_trip(int exponent) { + int n = (1 << exponent) + 1; + + Eigen::DSizes<ptrdiff_t, 1> dimensions; + dimensions[0] = n; + const DSizes<ptrdiff_t, 1> arr = dimensions; + Tensor<RealScalar, 1, ColMajor, ptrdiff_t> input; + + input.resize(arr); + input.setRandom(); + + array<int, 1> fft; + fft[0] = 0; + + Tensor<std::complex<RealScalar>, 1, ColMajor> forward = + input.template fft<BothParts, FFT_FORWARD>(fft); + + Tensor<RealScalar, 1, ColMajor, ptrdiff_t> output = + forward.template fft<RealPart, FFT_REVERSE>(fft); + + for (int i = 0; i < n; ++i) { + RealScalar tol = test_precision<RealScalar>() * + (std::abs(input[i]) + std::abs(output[i]) + 1); + VERIFY_IS_APPROX_OR_LESS_THAN(std::abs(input[i] - output[i]), tol); + } +} + +EIGEN_DECLARE_TEST(cxx11_tensor_fft) { test_fft_complex_input_golden(); test_fft_real_input_golden(); @@ -270,4 +298,7 @@ void test_cxx11_tensor_fft() { test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 4>(); test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 4>(); test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 4>(); + + test_fft_non_power_of_2_round_trip<float>(7); + test_fft_non_power_of_2_round_trip<double>(7); } |