Phoebe developer's documentation  1.1.0
Phonon and Electron Boltzmann Equations
Matrix< T > Class Template Reference

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).
 
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.
 

Detailed Description

template<typename T>
class Matrix< T >

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.

Constructor & Destructor Documentation

◆ Matrix()

template<typename T >
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.

Parameters
numRowsnumber of rows of the matrix
numColsnumber of columns of the matrix.
numBlocksRows,numBlocksColsthese parameters are ignored and are put here for mirroring the interface of ParallelMatrix.

Member Function Documentation

◆ diagonalize() [1/2]

template<typename T >
std::tuple<std::vector<double>, Matrix<T> > Matrix< T >::diagonalize ( )

Nota bene: we don't check if it's hermitian/symmetric.

◆ diagonalize() [2/2]

template<typename T >
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.

◆ dot()

template<typename T >
T Matrix< T >::dot ( const Matrix< T > &  that)

For vectors, this reduces to the standard scalar product.

◆ outputToHDF5()

template<typename T >
void Matrix< T >::outputToHDF5

Only for debugging, and only written for PMatrix.

◆ prod()

template<typename T >
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)

Parameters
thatthe matrix to multiply "this" with
trans2controls transposition of "this" matrix
trans1controls transposition of "that" matrix
Returns
result: a ParallelMatrix object.