KokkosFFT::fft

template<typename ExecutionSpace, typename InViewType, typename OutViewType>
void KokkosFFT::fft(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 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)

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

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

Note

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

Examples

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

Expected output:

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