11 #include <Eigen/CXX11/Tensor>
15 template <
int DataLayout>
31 std::complex<float> output_golden[6];
32 output_golden[0] = std::complex<float>(21, 0);
33 output_golden[1] = std::complex<float>(-9, 0);
34 output_golden[2] = std::complex<float>(-3, 1.73205);
35 output_golden[3] = std::complex<float>( 0, 0);
36 output_golden[4] = std::complex<float>(-3, -1.73205);
37 output_golden[5] = std::complex<float>(0 ,0);
39 std::complex<float> c_offset = std::complex<float>(1.0, 1.0);
61 input(0) = std::complex<float>(1, 1);
62 input(1) = std::complex<float>(2, 2);
63 input(2) = std::complex<float>(3, 3);
64 input(3) = std::complex<float>(4, 4);
65 input(4) = std::complex<float>(5, 5);
88 std::complex<float> forward_golden_result[5];
89 std::complex<float> reverse_golden_result[5];
91 forward_golden_result[0] = std::complex<float>(15.000000000000000,+15.000000000000000);
92 forward_golden_result[1] = std::complex<float>(-5.940954801177935, +0.940954801177934);
93 forward_golden_result[2] = std::complex<float>(-3.312299240582266, -1.687700759417735);
94 forward_golden_result[3] = std::complex<float>(-1.687700759417735, -3.312299240582266);
95 forward_golden_result[4] = std::complex<float>( 0.940954801177934, -5.940954801177935);
97 reverse_golden_result[0] = std::complex<float>( 3.000000000000000, + 3.000000000000000);
98 reverse_golden_result[1] = std::complex<float>( 0.188190960235587, - 1.188190960235587);
99 reverse_golden_result[2] = std::complex<float>(-0.337540151883547, - 0.662459848116453);
100 reverse_golden_result[3] = std::complex<float>(-0.662459848116453, - 0.337540151883547);
101 reverse_golden_result[4] = std::complex<float>(-1.188190960235587, + 0.188190960235587);
103 for(
int i = 0;
i < 5; ++
i) {
109 for(
int i = 0;
i < 5; ++
i) {
145 std::complex<float> forward_golden_result[5];
146 std::complex<float> reverse_golden_result[5];
149 forward_golden_result[0] = std::complex<float>( 15, 0);
150 forward_golden_result[1] = std::complex<float>(-2.5, +3.44095480117793);
151 forward_golden_result[2] = std::complex<float>(-2.5, +0.81229924058227);
152 forward_golden_result[3] = std::complex<float>(-2.5, -0.81229924058227);
153 forward_golden_result[4] = std::complex<float>(-2.5, -3.44095480117793);
155 reverse_golden_result[0] = std::complex<float>( 3.0, 0);
156 reverse_golden_result[1] = std::complex<float>(-0.5, -0.688190960235587);
157 reverse_golden_result[2] = std::complex<float>(-0.5, -0.162459848116453);
158 reverse_golden_result[3] = std::complex<float>(-0.5, +0.162459848116453);
159 reverse_golden_result[4] = std::complex<float>(-0.5, +0.688190960235587);
161 std::complex<float> c_offset(1.0, 1.0);
162 float r_offset = 1.0;
164 for(
int i = 0;
i < 5; ++
i) {
165 VERIFY_IS_APPROX(forward_output_both_parts(
i) + c_offset, forward_golden_result[
i] + c_offset);
170 for(
int i = 0;
i < 5; ++
i) {
171 VERIFY_IS_APPROX(reverse_output_both_parts(
i) + c_offset, reverse_golden_result[
i] + c_offset);
178 template <
int DataLayout,
typename RealScalar,
bool isComplexInput,
int FFTResultType,
int FFTDirection,
int TensorRank>
182 ptrdiff_t total_size = 1;
183 for (
int i = 0;
i < TensorRank; ++
i) {
189 typedef typename internal::conditional<isComplexInput == true, std::complex<RealScalar>,
RealScalar>
::type InputScalar;
196 for (
int i = 0;
i < TensorRank; ++
i) {
200 typedef typename internal::conditional<FFTResultType == Eigen::BothParts, std::complex<RealScalar>,
RealScalar>
::type OutputScalar;
202 output = input.template fft<FFTResultType, FFTDirection>(fft);
204 for (
int i = 0;
i < TensorRank; ++
i) {
211 for (
int i = 0;
i < total_size; ++
i) {
215 for (
int i = 0;
i < total_size; ++
i) {
227 template <
typename RealScalar>
229 int n = (1 << exponent) + 1;
243 input.template fft<BothParts, FFT_FORWARD>(fft);
246 forward.template fft<RealPart, FFT_REVERSE>(fft);
248 for (
int i = 0;
i <
n; ++
i) {
259 test_fft_2D_golden<ColMajor>();
260 test_fft_2D_golden<RowMajor>();
262 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 1>();
263 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 1>();
264 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 1>();
265 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 1>();
267 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 2>();
268 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 2>();
269 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 2>();
270 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 2>();
272 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 3>();
273 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 3>();
274 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 3>();
275 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 3>();
277 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 4>();
278 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 4>();
279 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 4>();
280 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 4>();
282 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 1>();
283 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 1>();
284 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 1>();
285 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 1>();
287 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 2>();
288 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 2>();
289 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 2>();
290 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 2>();
292 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 3>();
293 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 3>();
294 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 3>();
295 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 3>();
297 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 4>();
298 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 4>();
299 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 4>();
300 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 4>();
302 test_fft_non_power_of_2_round_trip<float>(7);
303 test_fft_non_power_of_2_round_trip<double>(7);