KokkosFFT::fft2

template<typename ExecutionSpace, typename InViewType, typename OutViewType>
void KokkosFFT::fft2(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 in forward direction.

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 or complex)

  • 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

For the real input, we internally convert it to complex and perform fft2 on it.

Examples

In this example, we use the 2D View with LayoutRight to avoid the internal transpose. This allows fft2 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 fft2 usage in documentation
 7/// x = [[1, 2, 3],
 8///      [4, 5, 6],
 9///      [7, 8, 9],
10///      [10, 11, 12]]
11/// x_hat = [[78, -6+3.4641j, -6-3.4641j],
12///          [-18+18j, 0, 0],
13///          [-18, 0, 0],
14///          [-18-18j, 0, 0]]
15int main(int argc, char* argv[]) {
16  Kokkos::ScopeGuard guard(argc, argv);
17  using ExecutionSpace = Kokkos::DefaultExecutionSpace;
18  using View2D = Kokkos::View<Kokkos::complex<double>**, Kokkos::LayoutRight,
19                              ExecutionSpace>;
20
21  const int n0 = 4, n1 = 3;
22
23  View2D x("x", n0, n1), x_hat("x_hat", n0, n1);
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) = Kokkos::complex<double>(i * n1 + j + 1);
28    }
29  }
30  Kokkos::deep_copy(x, h_x);
31
32  ExecutionSpace exec;
33  KokkosFFT::fft2(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; ++j) {
39      std::cout << " " << h_x_hat(i, j);
40    }
41    if (i < n0 - 1) std::cout << "\n";
42  }
43  std::cout << std::endl;
44
45  return 0;
46}

Expected output:

(78,0) (-6,3.4641) (-6,-3.4641)
(-18,18) (0,0) (0,0)
(-18,0) (0,0) (0,0)
(-18,-18) (0,0) (0,0)