Container class which wraps an underlying serial or parallel matrix. More...
#include <Matrix.h>
Public Member Functions | |
| Matrix (const int &numRows, const int &numCols, const int &numBlocksRows=0, const int &numBlocksCols=0, bool isDistributed_=false) | |
| Default Matrix constructor. More... | |
| Matrix () | |
| Default constructor. | |
| ~Matrix () | |
| Destructor, to delete raw buffer. | |
| Matrix (const Matrix< T > &that) | |
| Copy constructor. | |
| Matrix< T > & | operator= (const Matrix< T > &that) |
| Copy constructor. | |
| std::vector< std::tuple< int, int > > | getAllLocalStates () |
| Find the global indices of the matrix elements that are stored locally by the current MPI process. | |
| bool | indicesAreLocal (const int &row, const int &col) |
| Returns true if the global indices (row,col) identify a matrix element stored by the MPI process. | |
| int | rows () const |
| Find global number of rows. | |
| int | localRows () const |
| Return local number of rows. | |
| int | cols () const |
| Find global number of columns. | |
| int | localCols () const |
| Return local number of rows. | |
| int | size () const |
| Find global number of matrix elements. | |
| double | getMemory () const |
| Return the size of the matrix in GB. | |
| T & | operator() (const int &row, const int &col) |
| Get and set operator. | |
| const T & | operator() (const int &row, const int &col) const |
| Const get and set operator. | |
| Matrix< T > | prod (const Matrix< T > &that, const char &trans1, const char &trans2) |
| Matrix-matrix multiplication. More... | |
| Matrix< T > | operator+= (const Matrix< T > &m1) |
| Matrix-matrix addition. | |
| Matrix< T > | operator-= (const Matrix< T > &m1) |
| Matrix-matrix subtraction. | |
| Matrix< T > | operator*= (const T &that) |
| Matrix-scalar multiplication. | |
| Matrix< T > | operator/= (const T &that) |
| Matrix-scalar division. | |
| void | eye () |
| Sets this matrix as the identity. | |
| std::tuple< std::vector< double >, Matrix< T > > | diagonalize () |
| Diagonalize a complex-hermitian / real-symmetric matrix. More... | |
| std::tuple< std::vector< double >, Matrix< T > > | diagonalize (int numEigenvalues, bool checkNegativeEigenvalues=true) |
| Diagonalize a complex-hermitian / real-symmetric matrix for only some of it's eigenvalues. More... | |
| double | squaredNorm () |
| Computes the squared Frobenius norm of the matrix (or Euclidean norm, or L2 norm of the matrix) | |
| double | norm () |
| Computes the Frobenius norm of the matrix (or Euclidean norm, or L2 norm of the matrix). | |
| T | dot (const Matrix< T > &that) |
| Computes a "scalar product" between two matrices A and B, defined as \sum_ij A_ij * B_ij. More... | |
| Matrix< T > | operator- () const |
| Unary negation. | |
| void | outputToHDF5 () |
| A function to write the matrix to HDF5. More... | |
| void | symmetrize () |
| Symmetrize the matrix. | |
The class hierarchy is set up using this container rather than an inheritance structure with specific intent. These objects cannot be set up using an abstract Matrix parent class because because cpp does not allow for virtual operators, as it's not possible to overload something like +=, for which the virtual base class function would have to return an instance of the abstract base class (not possible), and which cannot be overloaded with a covariant return type by the child classes. c++ does this intentionally – otherwise, it would be possible to write things like SMatrix + PMatrix in the code! Similar issues with () and the assignment operator make a inheritance structure impractical.
| Matrix< T >::Matrix | ( | const int & | numRows, |
| const int & | numCols, | ||
| const int & | numBlocksRows = 0, |
||
| const int & | numBlocksCols = 0, |
||
| bool | isDistributed_ = false |
||
| ) |
Matrix elements are set to zero upon initialization.
| numRows | number of rows of the matrix |
| numCols | number of columns of the matrix. |
| numBlocksRows,numBlocksCols | these parameters are ignored and are put here for mirroring the interface of ParallelMatrix. |
Nota bene: we don't check if it's hermitian/symmetric.
| std::tuple<std::vector<double>, Matrix<T> > Matrix< T >::diagonalize | ( | int | numEigenvalues, |
| bool | checkNegativeEigenvalues = true |
||
| ) |
Nota bene: we don't check if it's hermitian/symmetric.
For vectors, this reduces to the standard scalar product.
| void Matrix< T >::outputToHDF5 |
Only for debugging, and only written for PMatrix.
| Matrix<T> Matrix< T >::prod | ( | const Matrix< T > & | that, |
| const char & | trans1, | ||
| const char & | trans2 | ||
| ) |
Computes result = trans1(*this) * trans2(that) where trans(1/2( can be "N" (matrix as is), "T" (transpose) or "C" adjoint (these flags are used so that the transposition/adjoint operation is never directly operated on the stored values)
| that | the matrix to multiply "this" with |
| trans2 | controls transposition of "this" matrix |
| trans1 | controls transposition of "that" matrix |