Ginkgo  Generated from pipelines/2897303314 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 
69 
70  void write(matrix_data<std::complex<float>, int32>& data) const override;
71 
72  void write(matrix_data<std::complex<float>, int64>& data) const override;
73 
74  void write(matrix_data<std::complex<double>, int32>& data) const override;
75 
76  void write(matrix_data<std::complex<double>, int64>& data) const override;
77 
78  dim<1> get_fft_size() const;
79 
80  bool is_inverse() const;
81 
89  static std::unique_ptr<Fft> create(std::shared_ptr<const Executor> exec);
90 
100  static std::unique_ptr<Fft> create(std::shared_ptr<const Executor> exec,
101  size_type size = 0,
102  bool inverse = false);
103 
104 protected:
105  Fft(std::shared_ptr<const Executor> exec, size_type size = 0,
106  bool inverse = false);
107 
108  void apply_impl(const LinOp* b, LinOp* x) const override;
109 
110  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
111  LinOp* x) const override;
112 
113 private:
114  mutable array<char> buffer_;
115  bool inverse_;
116 };
117 
118 
148 class Fft2 : public LinOp,
149  public EnableCloneable<Fft2>,
150  public WritableToMatrixData<std::complex<float>, int32>,
151  public WritableToMatrixData<std::complex<float>, int64>,
152  public WritableToMatrixData<std::complex<double>, int32>,
153  public WritableToMatrixData<std::complex<double>, int64>,
154  public Transposable {
155  friend class EnableCloneable<Fft2>;
156 
157 public:
160 
161  using value_type = std::complex<double>;
162  using index_type = int64;
163  using transposed_type = Fft2;
164 
165  std::unique_ptr<LinOp> transpose() const override;
166 
167  std::unique_ptr<LinOp> conj_transpose() const override;
168 
173 
174  void write(matrix_data<std::complex<float>, int32>& data) const override;
175 
176  void write(matrix_data<std::complex<float>, int64>& data) const override;
177 
178  void write(matrix_data<std::complex<double>, int32>& data) const override;
179 
180  void write(matrix_data<std::complex<double>, int64>& data) const override;
181 
182  dim<2> get_fft_size() const;
183 
184  bool is_inverse() const;
185 
193  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec);
194 
203  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
204  size_type size);
205 
216  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
217  size_type size1, size_type size2,
218  bool inverse = false);
219 
220 protected:
221  Fft2(std::shared_ptr<const Executor> exec, size_type size1 = 0,
222  size_type size2 = 0, bool inverse = false);
223 
224  void apply_impl(const LinOp* b, LinOp* x) const override;
225 
226  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
227  LinOp* x) const override;
228 
229 private:
230  mutable array<char> buffer_;
231  dim<2> fft_size_;
232  bool inverse_;
233 };
234 
235 
267 class Fft3 : public LinOp,
268  public EnableCloneable<Fft3>,
269  public WritableToMatrixData<std::complex<float>, int32>,
270  public WritableToMatrixData<std::complex<float>, int64>,
271  public WritableToMatrixData<std::complex<double>, int32>,
272  public WritableToMatrixData<std::complex<double>, int64>,
273  public Transposable {
274  friend class EnableCloneable<Fft3>;
275 
276 public:
279 
280  using value_type = std::complex<double>;
281  using index_type = int64;
282  using transposed_type = Fft3;
283 
284  std::unique_ptr<LinOp> transpose() const override;
285 
286  std::unique_ptr<LinOp> conj_transpose() const override;
287 
292 
293  void write(matrix_data<std::complex<float>, int32>& data) const override;
294 
295  void write(matrix_data<std::complex<float>, int64>& data) const override;
296 
297  void write(matrix_data<std::complex<double>, int32>& data) const override;
298 
299  void write(matrix_data<std::complex<double>, int64>& data) const override;
300 
301  dim<3> get_fft_size() const;
302 
303  bool is_inverse() const;
304 
312  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec);
313 
322  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
323  size_type size);
324 
336  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
337  size_type size1, size_type size2,
338  size_type size3, bool inverse = false);
339 
340 protected:
341  Fft3(std::shared_ptr<const Executor> exec, size_type size1 = 0,
342  size_type size2 = 0, size_type size3 = 0, bool inverse = false);
343 
344  void apply_impl(const LinOp* b, LinOp* x) const override;
345 
346  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
347  LinOp* x) const override;
348 
349 private:
350  mutable array<char> buffer_;
351  dim<3> fft_size_;
352  bool inverse_;
353 };
354 
355 
356 } // namespace matrix
357 } // namespace gko
358 
359 
360 #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:267
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:148