Ginkgo  Generated from pipelines/2837190956 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
fft.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
7 
8 
9 #include <ginkgo/core/base/array.hpp>
10 #include <ginkgo/core/base/lin_op.hpp>
11 
12 
13 namespace gko {
14 namespace matrix {
15 
16 
44 class Fft : public LinOp,
45  public EnableCloneable<Fft>,
46  public WritableToMatrixData<std::complex<float>, int32>,
47  public WritableToMatrixData<std::complex<float>, int64>,
48  public WritableToMatrixData<std::complex<double>, int32>,
49  public WritableToMatrixData<std::complex<double>, int64>,
50  public Transposable {
51  friend class EnableCloneable<Fft>;
52 
53 public:
56 
57  using value_type = std::complex<double>;
58  using index_type = int64;
59  using transposed_type = Fft;
60 
61  std::unique_ptr<LinOp> transpose() const override;
62 
63  std::unique_ptr<LinOp> conj_transpose() const override;
64 
65  void write(matrix_data<std::complex<float>, int32>& data) const override;
66 
67  void write(matrix_data<std::complex<float>, int64>& data) const override;
68 
69  void write(matrix_data<std::complex<double>, int32>& data) const override;
70 
71  void write(matrix_data<std::complex<double>, int64>& data) const override;
72 
73  dim<1> get_fft_size() const;
74 
75  bool is_inverse() const;
76 
84  static std::unique_ptr<Fft> create(std::shared_ptr<const Executor> exec);
85 
95  static std::unique_ptr<Fft> create(std::shared_ptr<const Executor> exec,
96  size_type size = 0,
97  bool inverse = false);
98 
99 protected:
100  Fft(std::shared_ptr<const Executor> exec, size_type size = 0,
101  bool inverse = false);
102 
103  void apply_impl(const LinOp* b, LinOp* x) const override;
104 
105  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
106  LinOp* x) const override;
107 
108 private:
109  mutable array<char> buffer_;
110  bool inverse_;
111 };
112 
113 
143 class Fft2 : public LinOp,
144  public EnableCloneable<Fft2>,
145  public WritableToMatrixData<std::complex<float>, int32>,
146  public WritableToMatrixData<std::complex<float>, int64>,
147  public WritableToMatrixData<std::complex<double>, int32>,
148  public WritableToMatrixData<std::complex<double>, int64>,
149  public Transposable {
150  friend class EnableCloneable<Fft2>;
151 
152 public:
155 
156  using value_type = std::complex<double>;
157  using index_type = int64;
158  using transposed_type = Fft2;
159 
160  std::unique_ptr<LinOp> transpose() const override;
161 
162  std::unique_ptr<LinOp> conj_transpose() const override;
163 
164  void write(matrix_data<std::complex<float>, int32>& data) const override;
165 
166  void write(matrix_data<std::complex<float>, int64>& data) const override;
167 
168  void write(matrix_data<std::complex<double>, int32>& data) const override;
169 
170  void write(matrix_data<std::complex<double>, int64>& data) const override;
171 
172  dim<2> get_fft_size() const;
173 
174  bool is_inverse() const;
175 
183  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec);
184 
193  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
194  size_type size);
195 
206  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
207  size_type size1, size_type size2,
208  bool inverse = false);
209 
210 protected:
211  Fft2(std::shared_ptr<const Executor> exec, size_type size1 = 0,
212  size_type size2 = 0, bool inverse = false);
213 
214  void apply_impl(const LinOp* b, LinOp* x) const override;
215 
216  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
217  LinOp* x) const override;
218 
219 private:
220  mutable array<char> buffer_;
221  dim<2> fft_size_;
222  bool inverse_;
223 };
224 
225 
257 class Fft3 : public LinOp,
258  public EnableCloneable<Fft3>,
259  public WritableToMatrixData<std::complex<float>, int32>,
260  public WritableToMatrixData<std::complex<float>, int64>,
261  public WritableToMatrixData<std::complex<double>, int32>,
262  public WritableToMatrixData<std::complex<double>, int64>,
263  public Transposable {
264  friend class EnableCloneable<Fft3>;
265 
266 public:
269 
270  using value_type = std::complex<double>;
271  using index_type = int64;
272  using transposed_type = Fft3;
273 
274  std::unique_ptr<LinOp> transpose() const override;
275 
276  std::unique_ptr<LinOp> conj_transpose() const override;
277 
278  void write(matrix_data<std::complex<float>, int32>& data) const override;
279 
280  void write(matrix_data<std::complex<float>, int64>& data) const override;
281 
282  void write(matrix_data<std::complex<double>, int32>& data) const override;
283 
284  void write(matrix_data<std::complex<double>, int64>& data) const override;
285 
286  dim<3> get_fft_size() const;
287 
288  bool is_inverse() const;
289 
297  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec);
298 
307  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
308  size_type size);
309 
321  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
322  size_type size1, size_type size2,
323  size_type size3, bool inverse = false);
324 
325 protected:
326  Fft3(std::shared_ptr<const Executor> exec, size_type size1 = 0,
327  size_type size2 = 0, size_type size3 = 0, bool inverse = false);
328 
329  void apply_impl(const LinOp* b, LinOp* x) const override;
330 
331  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
332  LinOp* x) const override;
333 
334 private:
335  mutable array<char> buffer_;
336  dim<3> fft_size_;
337  bool inverse_;
338 };
339 
340 
341 } // namespace matrix
342 } // namespace gko
343 
344 
345 #endif // GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
gko::LinOp
Definition: lin_op.hpp:117
gko::matrix::Fft2::create
static std::unique_ptr< Fft2 > create(std::shared_ptr< const Executor > exec)
Creates an empty Fourier matrix.
gko::matrix::Fft3::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko::Transposable
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:392
gko::matrix::Fft3::create
static std::unique_ptr< Fft3 > create(std::shared_ptr< const Executor > exec)
Creates an empty Fourier matrix.
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:101
gko::matrix::Fft2::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko::matrix::Fft3
This LinOp implements a 3D Fourier matrix using the FFT algorithm.
Definition: fft.hpp:257
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::array< char >
gko::matrix::Fft3::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::matrix::Fft::write
void write(matrix_data< std::complex< float >, int32 > &data) const override
Writes a matrix to a matrix_data structure.
gko::dim
A type representing the dimensions of a multidimensional object.
Definition: dim.hpp:25
gko::matrix_data
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:126
gko::matrix::Fft2::write
void write(matrix_data< std::complex< float >, int32 > &data) const override
Writes a matrix to a matrix_data structure.
gko::matrix::Fft3::write
void write(matrix_data< std::complex< float >, int32 > &data) const override
Writes a matrix to a matrix_data structure.
gko::matrix::permute_mode::inverse
The permutation will be inverted before being applied.
gko::matrix::Fft::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko::WritableToMatrixData
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:619
gko::matrix::Fft2::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::matrix::Fft::create
static std::unique_ptr< Fft > create(std::shared_ptr< const Executor > exec)
Creates an empty Fourier matrix.
gko::matrix::Fft::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:376
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:124
gko::int32
std::int32_t int32
32-bit signed integral type.
Definition: types.hpp:118
gko::matrix::Fft
This LinOp implements a 1D Fourier matrix using the FFT algorithm.
Definition: fft.hpp:44
gko::matrix::Fft2
This LinOp implements a 2D Fourier matrix using the FFT algorithm.
Definition: fft.hpp:143