forked from AMSC-24-25/amsc-24-25-classroom-20-fft-FFT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabstract-fourier-transform-solver.hpp
51 lines (46 loc) · 1.49 KB
/
abstract-fourier-transform-solver.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef ABSTRACT_FOURIER_TRANSFORM_SOLVER_HPP
#define ABSTRACT_FOURIER_TRANSFORM_SOLVER_HPP
#include <complex>
#include <optional>
#include <vector>
/**
* Abstract class for Fourier Transform solvers.
*/
class AbstractFourierTransformSolver {
bool isComputed = false;
protected:
/**
* Input vector to be transformed.
*/
std::vector<std::complex<double>> input;
/**
* Solution vector after transformation.
*/
std::optional<std::vector<std::complex<double>>> solution = std::nullopt;
public:
// AbstractFourierTransformSolver() = default;
virtual ~AbstractFourierTransformSolver() = default;
/**
* Initialize the solver with the complex input vector.
* @param inputVector The input vector to be transformed.
*/
explicit AbstractFourierTransformSolver(
const std::vector<std::complex<double>> &inputVector
) : input(inputVector) {}
/**
* Get the output vector after transformation if it exists.
* @return The output vector after transformation.
* @throw std::runtime_error If the solution does not exist.
*/
[[nodiscard]] const std::vector<std::complex<double>> &getSolution() const {
if (!solution.has_value()) {
throw std::runtime_error("Solution does not exist. Run the solver first.");
}
return solution.value();
}
/**
* Run the solver to compute the Fourier Transform.
*/
virtual void compute() = 0;
};
#endif //ABSTRACT_FOURIER_TRANSFORM_SOLVER_HPP