Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
fft.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 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 EnableLinOp<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 EnablePolymorphicObject<Fft, LinOp>;
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 
94  static std::unique_ptr<Fft> create(std::shared_ptr<const Executor> exec,
95  size_type size = 0,
96  bool inverse = false);
97 
98 protected:
99  Fft(std::shared_ptr<const Executor> exec, size_type size = 0,
100  bool inverse = false);
101 
102  void apply_impl(const LinOp* b, LinOp* x) const override;
103 
104  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
105  LinOp* x) const override;
106 
107 private:
108  mutable array<char> buffer_;
109  bool inverse_;
110 };
111 
112 
143 class Fft2 : public EnableLinOp<Fft2>,
144  public WritableToMatrixData<std::complex<float>, int32>,
145  public WritableToMatrixData<std::complex<float>, int64>,
146  public WritableToMatrixData<std::complex<double>, int32>,
147  public WritableToMatrixData<std::complex<double>, int64>,
148  public Transposable {
149  friend class EnablePolymorphicObject<Fft2, LinOp>;
150 
151 public:
154 
155  using value_type = std::complex<double>;
156  using index_type = int64;
157  using transposed_type = Fft2;
158 
159  std::unique_ptr<LinOp> transpose() const override;
160 
161  std::unique_ptr<LinOp> conj_transpose() const override;
162 
163  void write(matrix_data<std::complex<float>, int32>& data) const override;
164 
165  void write(matrix_data<std::complex<float>, int64>& data) const override;
166 
167  void write(matrix_data<std::complex<double>, int32>& data) const override;
168 
169  void write(matrix_data<std::complex<double>, int64>& data) const override;
170 
171  dim<2> get_fft_size() const;
172 
173  bool is_inverse() const;
174 
182  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec);
183 
191  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
192  size_type size);
193 
203  static std::unique_ptr<Fft2> create(std::shared_ptr<const Executor> exec,
204  size_type size1, size_type size2,
205  bool inverse = false);
206 
207 protected:
208  Fft2(std::shared_ptr<const Executor> exec, size_type size1 = 0,
209  size_type size2 = 0, bool inverse = false);
210 
211  void apply_impl(const LinOp* b, LinOp* x) const override;
212 
213  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
214  LinOp* x) const override;
215 
216 private:
217  mutable array<char> buffer_;
218  dim<2> fft_size_;
219  bool inverse_;
220 };
221 
222 
255 class Fft3 : public EnableLinOp<Fft3>,
256  public WritableToMatrixData<std::complex<float>, int32>,
257  public WritableToMatrixData<std::complex<float>, int64>,
258  public WritableToMatrixData<std::complex<double>, int32>,
259  public WritableToMatrixData<std::complex<double>, int64>,
260  public Transposable {
261  friend class EnablePolymorphicObject<Fft3, LinOp>;
262 
263 public:
266 
267  using value_type = std::complex<double>;
268  using index_type = int64;
269  using transposed_type = Fft3;
270 
271  std::unique_ptr<LinOp> transpose() const override;
272 
273  std::unique_ptr<LinOp> conj_transpose() const override;
274 
275  void write(matrix_data<std::complex<float>, int32>& data) const override;
276 
277  void write(matrix_data<std::complex<float>, int64>& data) const override;
278 
279  void write(matrix_data<std::complex<double>, int32>& data) const override;
280 
281  void write(matrix_data<std::complex<double>, int64>& data) const override;
282 
283  dim<3> get_fft_size() const;
284 
285  bool is_inverse() const;
286 
294  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec);
295 
303  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
304  size_type size);
305 
316  static std::unique_ptr<Fft3> create(std::shared_ptr<const Executor> exec,
317  size_type size1, size_type size2,
318  size_type size3, bool inverse = false);
319 
320 protected:
321  Fft3(std::shared_ptr<const Executor> exec, size_type size1 = 0,
322  size_type size2 = 0, size_type size3 = 0, bool inverse = false);
323 
324  void apply_impl(const LinOp* b, LinOp* x) const override;
325 
326  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
327  LinOp* x) const override;
328 
329 private:
330  mutable array<char> buffer_;
331  dim<3> fft_size_;
332  bool inverse_;
333 };
334 
335 
336 } // namespace matrix
337 } // namespace gko
338 
339 
340 #endif // GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
gko::LinOp
Definition: lin_op.hpp:118
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:434
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:108
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:255
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:27
gko::matrix_data
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:127
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:661
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::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:131
gko::int32
std::int32_t int32
32-bit signed integral type.
Definition: types.hpp:125
gko::matrix::Fft
This LinOp implements a 1D Fourier matrix using the FFT algorithm.
Definition: fft.hpp:45
gko::EnableLinOp
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:878
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:662
gko::matrix::Fft2
This LinOp implements a 2D Fourier matrix using the FFT algorithm.
Definition: fft.hpp:143