| 46 | #define MATRIX_VERY_LARGE_VALUE 1.0e213 |
| 47 | |
| 48 | class Matrix |
| 49 | { |
| 50 | public: |
| 51 | // constructors and destructor |
| 52 | Matrix(); |
| 53 | Matrix(int nrows, int ncols); |
| 54 | Matrix(double *data, int nrows, int ncols); |
| 55 | Matrix(const Matrix &M); |
| 56 | #ifdef USE_CXX11 |
| 57 | Matrix( Matrix &&M); |
| 58 | #endif |
| 59 | ~Matrix(); |
| 60 | |
| 61 | // utility methods |
| 62 | int setData(double *newData, int nRows, int nCols); |
| 63 | inline int noRows() const; |
| 64 | inline int noCols() const; |
| 65 | void Zero(void); |
| 66 | int resize(int numRow, int numCol); |
| 67 | Vector diagonal() const; |
| 68 | |
| 69 | int Assemble(const Matrix &,const ID &rows, const ID &cols, |
| 70 | double fact = 1.0); |
| 71 | |
| 72 | int Solve(const Vector &V, Vector &res) const; |
| 73 | int Solve(const Matrix &M, Matrix &res) const; |
| 74 | int Invert(Matrix &res) const; |
| 75 | |
| 76 | int addMatrix(double factThis, const Matrix &other, double factOther); |
| 77 | int addMatrixTranspose(double factThis, const Matrix &other, double factOther); |
| 78 | int addMatrixProduct(double factThis, const Matrix &A, const Matrix &B, double factOther); // AB |
| 79 | int addMatrixTransposeProduct(double factThis, const Matrix &A, const Matrix &B, double factOther); // A'B |
| 80 | int addMatrixTripleProduct(double factThis, const Matrix &A, const Matrix &B, double factOther); // A'BA |
| 81 | int addMatrixTripleProduct(double factThis, const Matrix &A, const Matrix &B, const Matrix &C, double otherFact); //A'BC |
| 82 | |
| 83 | // overloaded operators |
| 84 | inline double &operator()(int row, int col); |
| 85 | inline double operator()(int row, int col) const; |
| 86 | Matrix operator()(const ID &rows, const ID & cols) const; |
| 87 | |
| 88 | Matrix &operator=(const Matrix &M); |
| 89 | |
| 90 | #ifdef USE_CXX11 |
| 91 | Matrix &operator=(Matrix &&M); |
| 92 | #endif |
| 93 | |
| 94 | // matrix operations which will preserve the derived type and |
| 95 | // which can be implemented efficiently without many constructor calls. |
| 96 | |
| 97 | // matrix-scalar operations |
| 98 | Matrix &operator+=(double fact); |
| 99 | Matrix &operator-=(double fact); |
| 100 | Matrix &operator*=(double fact); |
| 101 | Matrix &operator/=(double fact); |
| 102 | |
| 103 | // matrix operations which generate a new Matrix. They are not the |
| 104 | // most efficient to use, as constructors must be called twice. They |
| 105 | // however are useful for matlab like expressions involving Matrices. |