KokkosFFT::fftshift
-
template<typename ExecutionSpace, typename ViewType>
void KokkosFFT::fftshift(const ExecutionSpace &exec_space, const ViewType &inout, std::optional<int> axes = std::nullopt) Shift the zero-frequency component to the center of the spectrum.
- Template Parameters:
ExecutionSpace – The type of Kokkos execution space
ViewType – Input/Output View type for the shift
- Parameters:
exec_space – [in] Kokkos execution space
inout – [in,out] Spectrum
axes – [in] Axes over which to shift (default: nullopt, shifting over all axes)
-
template<typename ExecutionSpace, typename ViewType, std::size_t DIM = 1>
void KokkosFFT::fftshift(const ExecutionSpace &exec_space, const ViewType &inout, axis_type<DIM> axes) Shift the zero-frequency component to the center of the spectrum.
- Template Parameters:
ExecutionSpace – The type of Kokkos execution space
ViewType – Input/Output View type for the shift
DIM – The dimensionality of the shift
- Parameters:
exec_space – [in] Kokkos execution space
inout – [in,out] Spectrum
axes – [in] Axes over which to shift
Examples
1#include <iostream>
2#include <Kokkos_Core.hpp>
3#include <Kokkos_Complex.hpp>
4#include <KokkosFFT.hpp>
5
6/// \brief Example of fftshift usage in documentation
7/// freqs = KokkosFFT::fftfreq(10, 0.1);
8/// freqs: [0 1 2 3 4 -5 -4 -3 -2 -1]
9/// KokkosFFT::fftshift(freqs);
10/// freqs_shifted: [-5 -4 -3 -2 -1 0 1 2 3 4]
11int main(int argc, char* argv[]) {
12 Kokkos::ScopeGuard guard(argc, argv);
13 using ExecutionSpace = Kokkos::DefaultExecutionSpace;
14
15 const int n0 = 10;
16 ExecutionSpace exec;
17 auto freq = KokkosFFT::fftfreq(exec, n0, 0.1);
18 KokkosFFT::fftshift(exec, freq);
19 auto h_freq = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, freq);
20 for (int i = 0; i < freq.extent_int(0); ++i) {
21 std::cout << " " << h_freq(i);
22 }
23 std::cout << std::endl;
24
25 return 0;
26}
Expected output:
-5 -4 -3 -2 -1 0 1 2 3 4