KokkosFFT::rfft2
-
template<typename ExecutionSpace, typename InViewType, typename OutViewType>
void KokkosFFT::rfft2(const ExecutionSpace &exec_space, const InViewType &in, const OutViewType &out, KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward, axis_type<2> axes = {-2, -1}, shape_type<2> s = {}) Two dimensional FFT for real input.
- Template Parameters:
ExecutionSpace – The type of Kokkos execution space
InViewType – Input View type for the fft
OutViewType – Output View type for the fft
- Parameters:
exec_space – [in] Kokkos execution space
in – [in] Input data (real)
out – [out] Output data (complex)
norm – [in] How the normalization is applied (default, backward)
axes – [in] Axes over which FFT is performed (default, {-2, -1})
s – [in] Shape of the transformed axis of the output (default, {})
Note
The input must be a real-valued view, and the output must be a complex-valued view. The output length along the transform axis (axes[1]) is n/2 + 1, where n is the input length along that axis. If this condition is not met, the std::runtime_error exception will be thrown.
Examples
In this example, we use the 2D View with LayoutRight to avoid the internal transpose. This allows rfft2 to perform 2D FFT on the outermost dimension without transpose.
1#include <iostream>
2#include <Kokkos_Core.hpp>
3#include <Kokkos_Complex.hpp>
4#include <KokkosFFT.hpp>
5
6/// \brief Example of rfft2 usage in documentation
7/// x = [[1, 2, 3, 4],
8/// [5, 6, 7, 8],
9/// [9, 10, 11, 12]]
10/// x_hat = [[78, -6+6j, -6],
11/// [-24+13.8564j, 0, 0],
12/// [-24-13.8564j, 0, 0]]
13int main(int argc, char* argv[]) {
14 Kokkos::ScopeGuard guard(argc, argv);
15 using ExecutionSpace = Kokkos::DefaultExecutionSpace;
16 using View2D = Kokkos::View<double**, Kokkos::LayoutRight, ExecutionSpace>;
17 using ComplexView2D = Kokkos::View<Kokkos::complex<double>**,
18 Kokkos::LayoutRight, ExecutionSpace>;
19
20 const int n0 = 3, n1 = 4;
21
22 View2D x("x", n0, n1);
23 ComplexView2D x_hat("x_hat", n0, n1 / 2 + 1);
24 auto h_x = Kokkos::create_mirror_view(x);
25 for (int i = 0; i < n0; ++i) {
26 for (int j = 0; j < n1; ++j) {
27 h_x(i, j) = i * n1 + j + 1;
28 }
29 }
30 Kokkos::deep_copy(x, h_x);
31
32 ExecutionSpace exec;
33 KokkosFFT::rfft2(exec, x, x_hat);
34
35 auto h_x_hat =
36 Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, x_hat);
37 for (int i = 0; i < n0; ++i) {
38 for (int j = 0; j < n1 / 2 + 1; ++j) {
39 std::cout << " " << h_x_hat(i, j);
40 }
41 std::cout << std::endl;
42 }
43
44 return 0;
45}
Expected output:
(78,0) (-6,6) (-6,0)
(-24,13.8564) (0,0) (0,0)
(-24,-13.8564) (0,0) (0,0)