-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbasic_interface_fft.cpp
More file actions
109 lines (91 loc) · 4.45 KB
/
Copy pathbasic_interface_fft.cpp
File metadata and controls
109 lines (91 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* xtensor-fftw
* Copyright (c) 2017, Patrick Bos
*
* Distributed under the terms of the BSD 3-Clause License.
*
* The full license is in the file LICENSE, distributed with this software.
*/
#include <xtensor-fftw/basic.hpp>
#include "basic_interface.hpp"
///////////////////////////////////////////////////////////////////////////////
// Setup
///////////////////////////////////////////////////////////////////////////////
// GoogleTest fixture class
template <typename T>
class TransformAndInvert_FFT : public ::testing::Test {};
TYPED_TEST_CASE(TransformAndInvert_FFT, MyTypes);
///////////////////////////////////////////////////////////////////////////////
// Regular FFT (complex to complex)
///////////////////////////////////////////////////////////////////////////////
////
// Regular FFT: xarray
////
TYPED_TEST(TransformAndInvert_FFT, FFT_1D_xarray) {
xt::xarray<std::complex<TypeParam>, xt::layout_type::row_major> a = generate_complex_data<TypeParam, 1>(4);
auto a_fourier = xt::fftw::fft(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifft(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
TYPED_TEST(TransformAndInvert_FFT, FFT_2D_xarray) {
xt::xarray<std::complex<TypeParam>, xt::layout_type::row_major> a = generate_complex_data<TypeParam, 2>(4);
auto a_fourier = xt::fftw::fft2(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifft2(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
TYPED_TEST(TransformAndInvert_FFT, FFT_3D_xarray) {
xt::xarray<std::complex<TypeParam>, xt::layout_type::row_major> a = generate_complex_data<TypeParam, 3>(4);
auto a_fourier = xt::fftw::fft3(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifft3(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
TYPED_TEST(TransformAndInvert_FFT, FFT_nD_n_equals_4_xarray) {
xt::xarray<std::complex<TypeParam>, xt::layout_type::row_major> a = generate_complex_data<TypeParam, 4>(4);
auto a_fourier = xt::fftw::fftn<4>(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifftn<4>(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
TYPED_TEST(TransformAndInvert_FFT, FFT_nD_n_equals_1_xarray) {
xt::xarray<std::complex<TypeParam>, xt::layout_type::row_major> a = generate_complex_data<TypeParam, 1>(4);
auto a_fourier = xt::fftw::fftn<1>(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifftn<1>(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
////
// Regular FFT: xtensor
////
/*
TYPED_TEST(TransformAndInvert_FFT, FFT_1D_xtensor) {
xt::xtensor<std::complex<TypeParam>, 1> a = generate_complex_data<TypeParam, 1>(4);
auto a_fourier = xt::fftw::fft(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifft(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
TYPED_TEST(TransformAndInvert_FFT, FFT_2D_xtensor) {
xt::xtensor<std::complex<TypeParam>, 2> a = generate_complex_data<TypeParam, 2>(4);
auto a_fourier = xt::fftw::fft2(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifft2(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
TYPED_TEST(TransformAndInvert_FFT, FFT_3D_xtensor) {
xt::xtensor<std::complex<TypeParam>, 3> a = generate_complex_data<TypeParam, 3>(4);
auto a_fourier = xt::fftw::fft3(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifft3(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
TYPED_TEST(TransformAndInvert_FFT, FFT_4D_xtensor) {
xt::xtensor<std::complex<TypeParam>, 4> a = generate_complex_data<TypeParam, 4>(4);
auto a_fourier = xt::fftw::fftn(a);
// std::cout << "fourier transform of input before ifft (which is destructive!): " << a_fourier << std::endl;
auto should_be_a = xt::fftw::ifftn(a_fourier);
assert_results_complex(a, a_fourier, should_be_a);
}
*/