Ginkgo  Generated from pipelines/3136675824 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 AbstractMultiVector* b,
109  AbstractMultiVector* x) const override;
110 
111  void apply_impl(const AbstractMultiVector* alpha,
112  const AbstractMultiVector* b,
113  const AbstractMultiVector* beta,
114  AbstractMultiVector* x) const override;
115 
116 private:
117  mutable array<char> buffer_;
118  bool inverse_;
119 };
120 
121 
151 class Fft2 : public LinOp,
152  public EnableCloneable<Fft2>,
153  public WritableToMatrixData<std::complex<float>, int32>,
154  public WritableToMatrixData<std::complex<float>, int64>,
155  public WritableToMatrixData<std::complex<double>, int32>,
156  public WritableToMatrixData<std::complex<double>, int64>,
157  public Transposable {
158  friend class EnableCloneable<Fft2>;
159 
160 public:
163 
164  using value_type = std::complex<double>;
165  using index_type = int64;
166  using transposed_type = Fft2;
167 
168  std::unique_ptr<LinOp> transpose() const override;
169 
170  std::unique_ptr<LinOp> conj_transpose() const override;
171 
176 
177  void write(matrix_data<std::complex<float>, int32>& data) const override;
178 
179  void write(matrix_data<std::complex<float>, int64>& data) const override;
180 
181  void write(matrix_data<std::complex<double>, int32>& data) const override;
182 
183  void write(matrix_data<std::complex<double>, int64>& data) const override;
184 
185  dim<2> get_fft_size() const;
186 
187  bool is_inverse() const;
188 
196  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec);
197 
206  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
207  size_type size);
208 
219  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
220  size_type size1, size_type size2,
221  bool inverse = false);
222 
223 protected:
224  Fft2(std::shared_ptr<const Executor> exec, size_type size1 = 0,
225  size_type size2 = 0, bool inverse = false);
226 
227  void apply_impl(const AbstractMultiVector* b,
228  AbstractMultiVector* x) const override;
229 
230  void apply_impl(const AbstractMultiVector* alpha,
231  const AbstractMultiVector* b,
232  const AbstractMultiVector* beta,
233  AbstractMultiVector* x) const override;
234 
235 private:
236  mutable array<char> buffer_;
237  dim<2> fft_size_;
238  bool inverse_;
239 };
240 
241 
273 class Fft3 : public LinOp,
274  public EnableCloneable<Fft3>,
275  public WritableToMatrixData<std::complex<float>, int32>,
276  public WritableToMatrixData<std::complex<float>, int64>,
277  public WritableToMatrixData<std::complex<double>, int32>,
278  public WritableToMatrixData<std::complex<double>, int64>,
279  public Transposable {
280  friend class EnableCloneable<Fft3>;
281 
282 public:
285 
286  using value_type = std::complex<double>;
287  using index_type = int64;
288  using transposed_type = Fft3;
289 
290  std::unique_ptr<LinOp> transpose() const override;
291 
292  std::unique_ptr<LinOp> conj_transpose() const override;
293 
298 
299  void write(matrix_data<std::complex<float>, int32>& data) const override;
300 
301  void write(matrix_data<std::complex<float>, int64>& data) const override;
302 
303  void write(matrix_data<std::complex<double>, int32>& data) const override;
304 
305  void write(matrix_data<std::complex<double>, int64>& data) const override;
306 
307  dim<3> get_fft_size() const;
308 
309  bool is_inverse() const;
310 
318  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec);
319 
328  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
329  size_type size);
330 
342  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
343  size_type size1, size_type size2,
344  size_type size3, bool inverse = false);
345 
346 protected:
347  Fft3(std::shared_ptr<const Executor> exec, size_type size1 = 0,
348  size_type size2 = 0, size_type size3 = 0, bool inverse = false);
349 
350  void apply_impl(const AbstractMultiVector* b,
351  AbstractMultiVector* x) const override;
352 
353  void apply_impl(const AbstractMultiVector* alpha,
354  const AbstractMultiVector* b,
355  const AbstractMultiVector* beta,
356  AbstractMultiVector* x) const override;
357 
358 private:
359  mutable array<char> buffer_;
360  dim<3> fft_size_;
361  bool inverse_;
362 };
363 
364 
365 } // namespace matrix
366 } // namespace gko
367 
368 
369 #endif // GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
gko::LinOp
Definition: lin_op.hpp:163
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:596
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:102
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:273
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:823
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:372
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:125
gko::int32
std::int32_t int32
32-bit signed integral type.
Definition: types.hpp:119
gko::AbstractMultiVector
Abstract interface class for (multi-)vector types.
Definition: multivector.hpp:81
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:151