KokkosFFT::rfft

template<typename ExecutionSpace, typename InViewType, typename OutViewType>
void KokkosFFT::rfft(const ExecutionSpace &exec_space, const InViewType &in, const OutViewType &out, KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward, int axis = -1, std::optional<std::size_t> n = std::nullopt)

One 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)

  • axis – [in] Axis over which FFT is performed (default, -1)

  • n – [in] Length of the transformed axis of the output (default, nullopt)

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

 1#include <iostream>
 2#include <Kokkos_Core.hpp>
 3#include <Kokkos_Complex.hpp>
 4#include <KokkosFFT.hpp>
 5
 6/// \brief Example of rfft usage in documentation
 7/// x = [1, 2, 3, 4]
 8/// x_hat = [10, -2+2j, -2]
 9int main(int argc, char* argv[]) {
10  Kokkos::ScopeGuard guard(argc, argv);
11  using ExecutionSpace = Kokkos::DefaultExecutionSpace;
12  using View1D         = Kokkos::View<double*, ExecutionSpace>;
13  using ComplexView1D  = Kokkos::View<Kokkos::complex<double>*, ExecutionSpace>;
14
15  const int n0 = 4;
16
17  View1D x("x", n0);
18  ComplexView1D x_hat("x_hat", n0 / 2 + 1);
19  auto h_x = Kokkos::create_mirror_view(x);
20  for (int i = 0; i < n0; ++i) {
21    h_x(i) = i + 1;
22  }
23  Kokkos::deep_copy(x, h_x);
24
25  ExecutionSpace exec;
26  KokkosFFT::rfft(exec, x, x_hat);
27
28  auto h_x_hat =
29      Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, x_hat);
30  for (int i = 0; i < n0 / 2 + 1; ++i) {
31    std::cout << " " << h_x_hat(i);
32  }
33  std::cout << std::endl;
34
35  return 0;
36}

Expected output:

(10,0) (-2,2) (-2,0)