numerics 0.1.0
Loading...
Searching...
No Matches
fft.hpp
Go to the documentation of this file.
1/// @file spectral/fft.hpp
2/// @brief FFT interface with backend dispatch.
3///
4/// Forward transform convention:
5/// \f[
6/// X_k=\sum_{j=0}^{n-1} x_j e^{-2\pi i jk/n}.
7/// \f]
8/// The inverse transform is unnormalized.
9#pragma once
10
11#include "core/types.hpp"
12#include "core/vector.hpp"
13
14namespace num {
15namespace spectral {
16
17enum class FFTBackend {
18 seq,
19 simd,
20 stdsimd,
21 fftw,
22};
23
24inline constexpr FFTBackend seq = FFTBackend::seq;
25inline constexpr FFTBackend fftw = FFTBackend::fftw;
28
29inline constexpr bool has_fftw =
30#ifdef NUMERICS_HAS_FFTW
31 true;
32#else
33 false;
34#endif
35
36inline constexpr bool has_fft_simd =
37#if defined(NUMERICS_HAS_AVX2) || defined(NUMERICS_HAS_NEON)
38 true;
39#else
40 false;
41#endif
42
43inline constexpr bool has_fft_stdsimd =
44#ifdef NUMERICS_HAS_STD_SIMD
45 true;
46#else
47 false;
48#endif
49
51#ifdef NUMERICS_HAS_FFTW
53#elif defined(NUMERICS_HAS_AVX2) || defined(NUMERICS_HAS_NEON)
55#else
57#endif
58
59void fft(const CVector& in, CVector& out, FFTBackend b = default_fft_backend);
60
61void ifft(const CVector& in, CVector& out, FFTBackend b = default_fft_backend);
62
63void rfft(const Vector& in, CVector& out, FFTBackend b = default_fft_backend);
64
65void irfft(const CVector& in, int n, Vector& out, FFTBackend b = default_fft_backend);
66
67/// @brief Precomputed complex transform plan.
68class FFTPlan {
69 public:
70 explicit FFTPlan(int n, bool forward = true, FFTBackend b = default_fft_backend);
71 ~FFTPlan();
72
73 FFTPlan(const FFTPlan&) = delete;
74 FFTPlan& operator=(const FFTPlan&) = delete;
75
76 void execute(const CVector& in, CVector& out) const;
77
78 int size() const { return n_; }
79 FFTBackend backend() const { return backend_; }
80
81 private:
82 int n_;
83 FFTBackend backend_;
84 void* impl_;
85};
86
87} // namespace spectral
88} // namespace num
Dense owning vector.
Definition vector.hpp:16
Precomputed complex transform plan.
Definition fft.hpp:68
FFTBackend backend() const
Definition fft.hpp:79
FFTPlan(const FFTPlan &)=delete
int size() const
Definition fft.hpp:78
void execute(const CVector &in, CVector &out) const
Definition fft.cpp:163
FFTPlan & operator=(const FFTPlan &)=delete
Core type definitions.
void ifft(const CVector &in, CVector &out, FFTBackend b=default_fft_backend)
Definition fft.cpp:40
void fft(const CVector &in, CVector &out, FFTBackend b=default_fft_backend)
Definition fft.cpp:15
void irfft(const CVector &in, int n, Vector &out, FFTBackend b=default_fft_backend)
Definition fft.cpp:89
constexpr bool has_fft_simd
Definition fft.hpp:36
constexpr FFTBackend fftw
Definition fft.hpp:25
constexpr FFTBackend fft_stdsimd
Definition fft.hpp:27
constexpr FFTBackend default_fft_backend
Definition fft.hpp:50
constexpr FFTBackend fft_simd
Definition fft.hpp:26
void rfft(const Vector &in, CVector &out, FFTBackend b=default_fft_backend)
Definition fft.cpp:65
constexpr bool has_fft_stdsimd
Definition fft.hpp:43
constexpr bool has_fftw
Definition fft.hpp:29
constexpr FFTBackend seq
Definition fft.hpp:24
Dense vector storage and operations.