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) {
184 dimensions[
i] = rand() % 20 + 1;
185 total_size *= dimensions[
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) {
231 test_fft_2D_golden<ColMajor>();
232 test_fft_2D_golden<RowMajor>();
234 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 1>();
235 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 1>();
236 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 1>();
237 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 1>();
239 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 2>();
240 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 2>();
241 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 2>();
242 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 2>();
244 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 3>();
245 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 3>();
246 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 3>();
247 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 3>();
249 test_fft_real_input_energy<ColMajor, float, true, Eigen::BothParts, FFT_FORWARD, 4>();
250 test_fft_real_input_energy<ColMajor, double, true, Eigen::BothParts, FFT_FORWARD, 4>();
251 test_fft_real_input_energy<ColMajor, float, false, Eigen::BothParts, FFT_FORWARD, 4>();
252 test_fft_real_input_energy<ColMajor, double, false, Eigen::BothParts, FFT_FORWARD, 4>();
254 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 1>();
255 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 1>();
256 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 1>();
257 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 1>();
259 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 2>();
260 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 2>();
261 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 2>();
262 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 2>();
264 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 3>();
265 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 3>();
266 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 3>();
267 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 3>();
269 test_fft_real_input_energy<RowMajor, float, true, Eigen::BothParts, FFT_FORWARD, 4>();
270 test_fft_real_input_energy<RowMajor, double, true, Eigen::BothParts, FFT_FORWARD, 4>();
271 test_fft_real_input_energy<RowMajor, float, false, Eigen::BothParts, FFT_FORWARD, 4>();
272 test_fft_real_input_energy<RowMajor, double, false, Eigen::BothParts, FFT_FORWARD, 4>();
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static void test_fft_real_input_energy()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
vector< size_t > dimensions(L.begin(), L.end())
#define VERIFY_IS_APPROX(a, b)
#define VERIFY_IS_EQUAL(a, b)
NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Abs2ReturnType abs2() const
EIGEN_DEVICE_FUNC void resize(const array< Index, NumIndices > &dimensions)
EIGEN_DEVICE_FUNC const ImagReturnType imag() const
static void test_fft_real_input_golden()
static void test_fft_complex_input_golden()
static void test_fft_2D_golden()
void test_cxx11_tensor_fft()