Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
fft.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
34#define GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
35
36
37#include <ginkgo/core/base/array.hpp>
38#include <ginkgo/core/base/lin_op.hpp>
39
40
41namespace gko {
42namespace matrix {
43
44
73class Fft : public EnableLinOp<Fft>,
74 public EnableCreateMethod<Fft>,
75 public WritableToMatrixData<std::complex<float>, int32>,
76 public WritableToMatrixData<std::complex<float>, int64>,
77 public WritableToMatrixData<std::complex<double>, int32>,
78 public WritableToMatrixData<std::complex<double>, int64>,
79 public Transposable {
80 friend class EnablePolymorphicObject<Fft, LinOp>;
81 friend class EnableCreateMethod<Fft>;
82
83public:
86
87 using value_type = std::complex<double>;
88 using index_type = int64;
89 using transposed_type = Fft;
90
91 std::unique_ptr<LinOp> transpose() const override;
92
93 std::unique_ptr<LinOp> conj_transpose() const override;
94
95 void write(matrix_data<std::complex<float>, int32>& data) const override;
96
97 void write(matrix_data<std::complex<float>, int64>& data) const override;
98
99 void write(matrix_data<std::complex<double>, int32>& data) const override;
100
101 void write(matrix_data<std::complex<double>, int64>& data) const override;
102
103 dim<1> get_fft_size() const;
104
105 bool is_inverse() const;
106
107protected:
113 explicit Fft(std::shared_ptr<const Executor> exec)
114 : EnableLinOp<Fft>(exec), buffer_{exec}, inverse_{}
115 {}
116
123 Fft(std::shared_ptr<const Executor> exec, size_type size,
124 bool inverse = false)
125 : EnableLinOp<Fft>(exec, dim<2>{size}), buffer_{exec}, inverse_{inverse}
126 {}
127
128 void apply_impl(const LinOp* b, LinOp* x) const override;
129
130 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
131 LinOp* x) const override;
132
133private:
134 mutable array<char> buffer_;
135 bool inverse_;
136};
137
138
169class Fft2 : public EnableLinOp<Fft2>,
170 public EnableCreateMethod<Fft2>,
171 public WritableToMatrixData<std::complex<float>, int32>,
172 public WritableToMatrixData<std::complex<float>, int64>,
173 public WritableToMatrixData<std::complex<double>, int32>,
174 public WritableToMatrixData<std::complex<double>, int64>,
175 public Transposable {
176 friend class EnablePolymorphicObject<Fft2, LinOp>;
177 friend class EnableCreateMethod<Fft2>;
178
179public:
182
183 using value_type = std::complex<double>;
184 using index_type = int64;
185 using transposed_type = Fft2;
186
187 std::unique_ptr<LinOp> transpose() const override;
188
189 std::unique_ptr<LinOp> conj_transpose() const override;
190
191 void write(matrix_data<std::complex<float>, int32>& data) const override;
192
193 void write(matrix_data<std::complex<float>, int64>& data) const override;
194
195 void write(matrix_data<std::complex<double>, int32>& data) const override;
196
197 void write(matrix_data<std::complex<double>, int64>& data) const override;
198
199 dim<2> get_fft_size() const;
200
201 bool is_inverse() const;
202
203protected:
209 explicit Fft2(std::shared_ptr<const Executor> exec)
210 : EnableLinOp<Fft2>(exec), buffer_{exec}, fft_size_{}, inverse_{}
211 {}
212
218 Fft2(std::shared_ptr<const Executor> exec, size_type size)
219 : Fft2{exec, size, size}
220 {}
221
229 Fft2(std::shared_ptr<const Executor> exec, size_type size1, size_type size2,
230 bool inverse = false)
231 : EnableLinOp<Fft2>(exec, dim<2>{size1 * size2}),
232 buffer_{exec},
233 fft_size_{size1, size2},
234 inverse_{inverse}
235 {}
236
237 void apply_impl(const LinOp* b, LinOp* x) const override;
238
239 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
240 LinOp* x) const override;
241
242private:
243 mutable array<char> buffer_;
244 dim<2> fft_size_;
245 bool inverse_;
246};
247
248
281class Fft3 : public EnableLinOp<Fft3>,
282 public EnableCreateMethod<Fft3>,
283 public WritableToMatrixData<std::complex<float>, int32>,
284 public WritableToMatrixData<std::complex<float>, int64>,
285 public WritableToMatrixData<std::complex<double>, int32>,
286 public WritableToMatrixData<std::complex<double>, int64>,
287 public Transposable {
288 friend class EnablePolymorphicObject<Fft3, LinOp>;
289 friend class EnableCreateMethod<Fft3>;
290
291public:
294
295 using value_type = std::complex<double>;
296 using index_type = int64;
297 using transposed_type = Fft3;
298
299 std::unique_ptr<LinOp> transpose() const override;
300
301 std::unique_ptr<LinOp> conj_transpose() const override;
302
303 void write(matrix_data<std::complex<float>, int32>& data) const override;
304
305 void write(matrix_data<std::complex<float>, int64>& data) const override;
306
307 void write(matrix_data<std::complex<double>, int32>& data) const override;
308
309 void write(matrix_data<std::complex<double>, int64>& data) const override;
310
311 dim<3> get_fft_size() const;
312
313 bool is_inverse() const;
314
315protected:
321 explicit Fft3(std::shared_ptr<const Executor> exec)
322 : EnableLinOp<Fft3>(exec), buffer_{exec}, fft_size_{}, inverse_{}
323 {}
324
330 Fft3(std::shared_ptr<const Executor> exec, size_type size)
331 : Fft3{exec, size, size, size}
332 {}
333
342 Fft3(std::shared_ptr<const Executor> exec, size_type size1, size_type size2,
343 size_type size3, bool inverse = false)
344 : EnableLinOp<Fft3>(exec, dim<2>{size1 * size2 * size3}),
345 buffer_{exec},
346 fft_size_{size1, size2, size3},
347 inverse_{inverse}
348 {}
349
350 void apply_impl(const LinOp* b, LinOp* x) const override;
351
352 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
353 LinOp* x) const override;
354
355private:
356 mutable array<char> buffer_;
357 dim<3> fft_size_;
358 bool inverse_;
359};
360
361
362} // namespace matrix
363} // namespace gko
364
365
366#endif // GKO_PUBLIC_CORE_MATRIX_FFT_HPP_
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory,...
Definition polymorphic_object.hpp:776
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:908
void move_to(result_type *result) override
Converts the implementer to an object of type result_type by moving data from this object.
Definition polymorphic_object.hpp:760
void convert_to(result_type *result) const override
Converts the implementer to an object of type result_type.
Definition polymorphic_object.hpp:758
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
Definition lin_op.hpp:146
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:462
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition lin_op.hpp:689
This LinOp implements a 2D Fourier matrix using the FFT algorithm.
Definition fft.hpp:175
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
This LinOp implements a 3D Fourier matrix using the FFT algorithm.
Definition fft.hpp:287
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
This LinOp implements a 1D Fourier matrix using the FFT algorithm.
Definition fft.hpp:79
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
@ inverse
The permutation will be inverted before being applied.
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:137
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:143
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:55
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:155