SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Matrix.hh
1 #ifndef MATRIX_HH
2 #define MATRIX_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <cmath>
7 #include <vector>
8 
9 // Other includes
10 #include "DecompLU.hh"
11 #include "DecompQR.hh"
12 #include "Vector.hh"
13 #include "Pitch.hh"
14 #include "Assert.hh"
15 
21 template<typename T> class Matrix {
22  public:
24  Matrix();
25 
27  Matrix(const size_t n);
28 
30  Matrix(const size_t m, const size_t n);
31 
33  Matrix(const size_t m, const size_t n, const T& value);
34 
36  Matrix(const std::vector<T>& v);
37 
39  Matrix(const std::vector<std::vector<T>>& mat);
40 
42  Matrix(const Matrix& mat);
43 
45  ~Matrix();
46 
48  Matrix& operator=(const Matrix& mat);
49 
51  explicit operator bool() const;
52 
54  bool operator!() const;
55 
57  Matrix operator-() const;
58 
60  Matrix operator+(const Matrix& mat) const;
61 
63  void operator+=(const Matrix& mat);
64 
66  Matrix operator-(const Matrix& mat) const;
67 
69  void operator-=(const Matrix& mat);
70 
72  Matrix operator*(const Matrix& mat) const;
73 
75  void operator*=(const Matrix& mat);
76 
78  Matrix operator*(const T& factor) const;
79 
81  void operator*=(const T& factor);
82 
84  Vector<T> operator*(const Vector<T>& vec) const;
85 
87  Matrix operator/(const T& factor) const;
88 
90  void operator/=(const T& factor);
91 
93  const std::vector<T>& operator[](const size_t i) const;
94 
96  std::vector<T>& operator[](const size_t i);
97 
105  T Cofactor(const size_t i, const size_t j) const;
106 
111  Matrix<T> CofactorMatrix() const;
112 
117  T Determinant() const;
118 
123  std::vector<T> Column(const size_t i) const;
124 
132  Matrix<T> EigenVectors(std::vector<T>& lambdas, const double eps=1e-6) const;
133 
138  void Fill(const T& value);
139 
141  void Identity();
142 
147  Matrix<T> Inverse() const;
148 
150  void Invert();
151 
155  bool IsSymmetric() const;
156 
161  const size_t Nrows() const;
162 
167  const size_t Ncols() const;
168 
170  void Print() const;
171 
173  void RemoveColumn(const size_t i);
174 
176  void RemoveRow(const size_t i);
177 
183  void Resize(const size_t m, const size_t n);
184 
189  const std::vector<T>& Row(const size_t i) const;
190 
195  std::vector<T>& Row(const size_t i);
196 
201  std::vector<T> Solve(const std::vector<T>& b) const;
202 
207  const std::vector<std::vector<T>>& std() const;
208 
213  Matrix<T> Transpose() const;
214 
215  private:
216 
217  std::vector<std::vector<T>> _mat;
218 };
219 
220 #include "Matrix-inl.hh"
221 
222 #endif
const size_t Ncols() const
Returns the number of columns.
Definition: Matrix-inl.hh:486
Matrix & operator=(const Matrix &mat)
Equality operator.
Definition: Matrix-inl.hh:43
Matrix operator*(const Matrix &mat) const
Overload the matrix product.
Definition: Matrix-inl.hh:127
Matrix operator/(const T &factor) const
Overload the matrix ratio with a scalar.
Definition: Matrix-inl.hh:208
void RemoveColumn(const size_t i)
Removes the i^th column of the matrix.
Definition: Matrix-inl.hh:504
void operator-=(const Matrix &mat)
Overload the matrix substraction.
Definition: Matrix-inl.hh:115
bool operator!() const
Boolean not operator.
Definition: Matrix-inl.hh:56
Object that can host any type of data in a vector arrangement.
Definition: Vector.hh:17
std::vector< std::vector< T > > _mat
Underlying std::vector<std::vector>>
Definition: Matrix.hh:217
Matrix< T > Inverse() const
Returns the inverse of the matrix.
Definition: Matrix-inl.hh:401
void operator/=(const T &factor)
Overload the matrix ratio with a scalar.
Definition: Matrix-inl.hh:223
void Identity()
Sets the matrix to an identity matrix.
Definition: Matrix-inl.hh:392
const std::vector< T > & Row(const size_t i) const
Returns the i^th row of the matrix as a vector.
Definition: Matrix-inl.hh:526
void Resize(const size_t m, const size_t n)
Resizes the matrix to chosen dimension.
Definition: Matrix-inl.hh:518
Matrix operator-() const
Overload the unary minus for matrix algebra.
Definition: Matrix-inl.hh:61
bool IsSymmetric() const
Checks whether the matrix is symmetric or not.
Definition: Matrix-inl.hh:470
Matrix< T > CofactorMatrix() const
Returns the inverse of the matrix.
Definition: Matrix-inl.hh:283
std::vector< T > Column(const size_t i) const
Returns the i^th column of the matrix as a vector.
Definition: Matrix-inl.hh:301
const std::vector< T > & operator[](const size_t i) const
Overload the subscript operator, return an std::vector row.
Definition: Matrix-inl.hh:235
void Fill(const T &value)
Fills the matrix with a certain value.
Definition: Matrix-inl.hh:384
Matrix()
Default constructor, initilizes an empty matrix of dimension 0x0.
Definition: Matrix-inl.hh:1
const size_t Nrows() const
Returns the number of rows.
Definition: Matrix-inl.hh:482
Matrix operator+(const Matrix &mat) const
Overload the matrix sum.
Definition: Matrix-inl.hh:73
void Invert()
Inverts the matrix in place.
Definition: Matrix-inl.hh:409
Object that can host any type of data in an matrix arrangement.
Definition: Matrix.hh:21
const std::vector< std::vector< T > > & std() const
Returns the underlying std vector.
Definition: Matrix-inl.hh:583
T Determinant() const
Returns the deterimant of the matrix.
Definition: Matrix-inl.hh:312
void RemoveRow(const size_t i)
Removes the i^th row of the matrix.
Definition: Matrix-inl.hh:512
~Matrix()
Destructor.
Definition: Matrix-inl.hh:41
std::vector< T > Solve(const std::vector< T > &b) const
Solves A*x=b, provided with b.
Definition: Matrix-inl.hh:538
void Print() const
Print the matrix.
Definition: Matrix-inl.hh:494
Matrix< T > Transpose() const
Returns the matrix transpose.
Definition: Matrix-inl.hh:588
void operator*=(const Matrix &mat)
Overload the matrix product equality.
Definition: Matrix-inl.hh:143
T Cofactor(const size_t i, const size_t j) const
Returns the ith-jth cofactor of the matrix.
Definition: Matrix-inl.hh:266
Matrix< T > EigenVectors(std::vector< T > &lambdas, const double eps=1e-6) const
Returns the matrix of which the columns are the eigenvectors of the matrix.
Definition: Matrix-inl.hh:334
void operator+=(const Matrix &mat)
Overload the matrix sum.
Definition: Matrix-inl.hh:88