KokkosFFT::rfftn

template<typename ExecutionSpace, typename InViewType, typename OutViewType, std::size_t DIM>
void KokkosFFT::rfftn(const ExecutionSpace &exec_space, const InViewType &in, const OutViewType &out, axis_type<DIM> axes = KokkosFFT::Impl::index_sequence<int, DIM, -static_cast<int>(DIM)>(), KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward, shape_type<DIM> s = {})

N-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

  • DIM – The dimensionality of the fft

Parameters:
  • exec_space – [in] Kokkos execution space

  • in – [in] Input data (real)

  • out – [out] Output data (complex)

  • axes – [in] Axes over which FFT is performed (default, all axes)

  • norm – [in] How the normalization is applied (default, backward)

  • 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[DIM-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 3D View with LayoutRight to avoid the internal transpose. This allows rfftn to perform 3-dimensional 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 rfftn usage in documentation
 7/// x = [[[1, 2],
 8///       [3, 4]],
 9///      [[5, 6],
10///       [7, 8]],
11///      [[9, 10],
12///       [11, 12]]]
13/// x_hat = [[[78, -6],
14///           [-12, 0]],
15///          [[-24+13.8564j, 0],
16///           [0, 0]],
17///          [[-24-13.8564j, 0],
18///           [0, 0]]]
19int main(int argc, char* argv[]) {
20  Kokkos::ScopeGuard guard(argc, argv);
21  using ExecutionSpace = Kokkos::DefaultExecutionSpace;
22  using View3D = Kokkos::View<double***, Kokkos::LayoutRight, ExecutionSpace>;
23  using ComplexView3D = Kokkos::View<Kokkos::complex<double>***,
24                                     Kokkos::LayoutRight, ExecutionSpace>;
25
26  const int n0 = 3, n1 = 2, n2 = 2;
27
28  View3D x("x", n0, n1, n2);
29  ComplexView3D x_hat("x_hat", n0, n1, n2 / 2 + 1);
30  auto h_x = Kokkos::create_mirror_view(x);
31  for (int i = 0; i < n0; ++i) {
32    for (int j = 0; j < n1; ++j) {
33      for (int k = 0; k < n2; ++k) {
34        h_x(i, j, k) = i * n1 * n2 + j * n2 + k + 1;
35      }
36    }
37  }
38  Kokkos::deep_copy(x, h_x);
39
40  ExecutionSpace exec;
41  KokkosFFT::rfftn(exec, x, x_hat);
42
43  auto h_x_hat =
44      Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, x_hat);
45  for (int i = 0; i < n0; ++i) {
46    for (int j = 0; j < n1; ++j) {
47      for (int k = 0; k < n2 / 2 + 1; ++k) {
48        std::cout << " " << h_x_hat(i, j, k);
49      }
50      std::cout << std::endl;
51    }
52    std::cout << std::endl;
53  }
54
55  return 0;
56}

Expected output:

(78,0) (-6,0)
(-12,0) (0,0)

(-24,13.8564) (0,0)
(0,0) (0,0)

(-24,-13.8564) (0,0)
(0,0) (0,0)