Ginkgo  Generated from pipelines/2662685947 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 
45 class Fft : public LinOp,
46  public EnableCloneable<Fft>,
47  public WritableToMatrixData<std::complex<float>, int32>,
48  public WritableToMatrixData<std::complex<float>, int64>,
49  public WritableToMatrixData<std::complex<double>, int32>,
50  public WritableToMatrixData<std::complex<double>, int64>,
51  public Transposable {
52  friend class EnableCloneable<Fft>;
53 
54 public:
57 
58  using value_type = std::complex<double>;
59  using index_type = int64;
60  using transposed_type = Fft;
61 
62  std::unique_ptr<LinOp> transpose() const override;
63 
64  std::unique_ptr<LinOp> conj_transpose() const override;
65 
66  void write(matrix_data<std::complex<float>, int32>& data) const override;
67 
68  void write(matrix_data<std::complex<float>, int64>& data) const override;
69 
70  void write(matrix_data<std::complex<double>, int32>& data) const override;
71 
72  void write(matrix_data<std::complex<double>, int64>& data) const override;
73 
74  dim<1> get_fft_size() const;
75 
76  bool is_inverse() const;
77 
85  static std::unique_ptr<Fft> create(std::shared_ptr<const Executor> exec);
86 
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 
144 class Fft2 : public LinOp,
145  public EnableCloneable<Fft2>,
146  public WritableToMatrixData<std::complex<float>, int32>,
147  public WritableToMatrixData<std::complex<float>, int64>,
148  public WritableToMatrixData<std::complex<double>, int32>,
149  public WritableToMatrixData<std::complex<double>, int64>,
150  public Transposable {
151  friend class EnableCloneable<Fft2>;
152 
153 public:
156 
157  using value_type = std::complex<double>;
158  using index_type = int64;
159  using transposed_type = Fft2;
160 
161  std::unique_ptr<LinOp> transpose() const override;
162 
163  std::unique_ptr<LinOp> conj_transpose() const override;
164 
165  void write(matrix_data<std::complex<float>, int32>& data) const override;
166 
167  void write(matrix_data<std::complex<float>, int64>& data) const override;
168 
169  void write(matrix_data<std::complex<double>, int32>& data) const override;
170 
171  void write(matrix_data<std::complex<double>, int64>& data) const override;
172 
173  dim<2> get_fft_size() const;
174 
175  bool is_inverse() const;
176 
184  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec);
185 
193  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
194  size_type size);
195 
205  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
206  size_type size1, size_type size2,
207  bool inverse = false);
208 
209 protected:
210  Fft2(std::shared_ptr<const Executor> exec, size_type size1 = 0,
211  size_type size2 = 0, bool inverse = false);
212 
213  void apply_impl(const LinOp* b, LinOp* x) const override;
214 
215  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
216  LinOp* x) const override;
217 
218 private:
219  mutable array<char> buffer_;
220  dim<2> fft_size_;
221  bool inverse_;
222 };
223 
224 
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 
306  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
307  size_type size);
308 
319  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
320  size_type size1, size_type size2,
321  size_type size3, bool inverse = false);
322 
323 protected:
324  Fft3(std::shared_ptr<const Executor> exec, size_type size1 = 0,
325  size_type size2 = 0, size_type size3 = 0, bool inverse = false);
326 
327  void apply_impl(const LinOp* b, LinOp* x) const override;
328 
329  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
330  LinOp* x) const override;
331 
332 private:
333  mutable array<char> buffer_;
334  dim<3> fft_size_;
335  bool inverse_;
336 };
337 
338 
339 } // namespace matrix
340 } // namespace gko
341 
342 
343 #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:90
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:20
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:26
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:369
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:113
gko::int32
std::int32_t int32
32-bit signed integral type.
Definition: types.hpp:107
gko::matrix::Fft
This LinOp implements a 1D Fourier matrix using the FFT algorithm.
Definition: fft.hpp:45
gko::matrix::Fft2
This LinOp implements a 2D Fourier matrix using the FFT algorithm.
Definition: fft.hpp:144