libROM
v1.0
Datadriven physical simulation library

#include <Matrix.h>
Public Member Functions  
Matrix ()  
Matrix (int num_rows, int num_cols, bool distributed, bool randomized=false)  
Matrix (double *mat, int num_rows, int num_cols, bool distributed, bool copy_data=true)  
Matrix (const Matrix &other)  
Copy constructor. More...  
~Matrix ()  
Destructor.  
Matrix &  operator= (const Matrix &rhs) 
Assignment operator. More...  
Matrix &  operator= (const double a) 
Assignment operator. More...  
Matrix &  operator+= (const Matrix &rhs) 
Addition operator. More...  
Matrix &  operator= (const Matrix &rhs) 
Subtraction operator. More...  
void  setSize (int num_rows, int num_cols) 
Sets the number of rows and columns of the matrix and reallocates storage if needed. All values are initialized to zero. More...  
bool  distributed () const 
Returns true if the Matrix is distributed. More...  
bool  balanced () const 
Returns true if rows of matrix are loadbalanced.  
int  numRows () const 
Returns the number of rows of the Matrix on this processor. More...  
int  numDistributedRows () const 
Returns the number of rows of the Matrix across all processors. More...  
int  numColumns () const 
Returns the number of columns in the Matrix. This method will return the same value from each processor. More...  
Matrix *  getFirstNColumns (int n) const 
Get the first N columns of a matrix. More...  
void  getFirstNColumns (int n, Matrix *&result) const 
Get the first N columns of a matrix. More...  
void  getFirstNColumns (int n, Matrix &result) const 
Get the first N columns of a matrix. More...  
Matrix *  mult (const Matrix &other) const 
Multiplies this Matrix with other and returns the product, reference version. More...  
Matrix *  mult (const Matrix *other) const 
Multiplies this Matrix with other and returns the product, pointer version. More...  
void  mult (const Matrix &other, Matrix *&result) const 
Multiplies this Matrix with other and fills result with the answer. More...  
void  mult (const Matrix &other, Matrix &result) const 
Multiplies this Matrix with other and fills result with the answer. More...  
Vector *  mult (const Vector &other) const 
Multiplies this Matrix with other and returns the product, reference version. More...  
Vector *  mult (const Vector *other) const 
Multiplies this Matrix with other and returns the product, pointer version. More...  
void  mult (const Vector &other, Vector *&result) const 
Multiplies this Matrix with other and fills result with the answer. More...  
void  mult (const Vector &other, Vector &result) const 
Multiplies this Matrix with other and fills result with the answer. More...  
void  pointwise_mult (int this_row, const Vector &other, Vector &result) const 
Multiplies a specified row of this Matrix with other pointwise. More...  
void  pointwise_mult (int this_row, Vector &other) const 
Multiplies a specified row of this Matrix with other pointwise. This modifies other. More...  
Matrix *  elementwise_mult (const Matrix &other) const 
Multiplies two matrices elementwise. More...  
Matrix *  elementwise_mult (const Matrix *other) const 
Multiplies two matrices elementwise and returns the product, pointer version. More...  
void  elementwise_mult (const Matrix &other, Matrix *&result) const 
Multiplies two matrices elementwise and fills result with the answer. More...  
void  elementwise_mult (const Matrix &other, Matrix &result) const 
Multiplies two matrices elementwise and fills result with the answer. More...  
Matrix *  elementwise_square () const 
Square every element in the matrix. More...  
void  elementwise_square (Matrix *&result) const 
Square every element in the matrix. More...  
void  elementwise_square (Matrix &result) const 
Square every element in the matrix. More...  
void  multPlus (Vector &a, const Vector &b, double c) const 
Computes a += this*b*c. More...  
Matrix *  transposeMult (const Matrix &other) const 
Multiplies the transpose of this Matrix with other and returns the product, reference version. More...  
Matrix *  transposeMult (const Matrix *other) const 
Multiplies the transpose of this Matrix with other and returns the product, pointer version. More...  
void  transposeMult (const Matrix &other, Matrix *&result) const 
Multiplies the transpose of this Matrix with other and fills result with the answer. More...  
void  transposeMult (const Matrix &other, Matrix &result) const 
Multiplies the transpose of this Matrix with other and fills result with the answer. More...  
Vector *  transposeMult (const Vector &other) const 
Multiplies the transpose of this Matrix with other and returns the product, reference version. More...  
Vector *  transposeMult (const Vector *other) const 
Multiplies the transpose of this Matrix with other and returns the product, pointer version. More...  
void  transposeMult (const Vector &other, Vector *&result) const 
Multiplies the transpose of this Matrix with other and fills result with the answer. More...  
void  transposeMult (const Vector &other, Vector &result) const 
Multiplies the transpose of this Matrix with other and fills result with the answer. More...  
Matrix *  inverse () const 
Computes and returns the inverse of this. More...  
void  inverse (Matrix *&result) const 
Computes and returns the inverse of this. More...  
void  inverse (Matrix &result) const 
Computes and returns the inverse of this. More...  
void  inverse () 
Computes the inverse of this and stores result in this. More...  
Vector *  getColumn (int column) const 
Returns a column of the matrix (not owned by Matrix). More...  
void  getColumn (int column, Vector *&result) const 
Returns a column of the matrix (not owned by Matrix). More...  
void  getColumn (int column, Vector &result) const 
Returns a column of the matrix (not owned by Matrix). More...  
void  transpose () 
Replaces this Matrix with its transpose (in place), in the serial square case only. More...  
void  transposePseudoinverse () 
Computes the transposePseudoinverse of this. More...  
Matrix *  qr_factorize () const 
Computes and returns the Q of the QR factorization of this. More...  
void  qrcp_pivots_transpose (int *row_pivot, int *row_pivot_owner, int pivots_requested) const 
Compute the leading numColumns() column pivots from a QR decomposition with column pivots (QRCP) of the transpose of this. More...  
void  orthogonalize (bool double_pass=false, double zero_tol=1.0e15) 
Orthonormalizes the matrix. More...  
void  orthogonalize_last (int ncols=1, bool double_pass=false, double zero_tol=1.0e15) 
Orthonormalizes the matrix's last column, assuming the previous columns are already orthonormal. More...  
void  rescale_rows_max () 
Rescale every matrix row by its maximum absolute value.  
void  rescale_cols_max () 
Rescale every matrix column by its maximum absolute value.  
const double &  item (int row, int col) const 
Const Matrix member access. Matrix data is stored in rowmajor format. More...  
double &  item (int row, int col) 
Nonconst Matrix member access. Matrix data is stored in rowmajor format. More...  
const double &  operator() (int row, int col) const 
Const Matrix member access. More...  
double &  operator() (int row, int col) 
Nonconst Matrix member access. More...  
void  print (const char *prefix) const 
print Matrix into (a) ascii file(s). More...  
void  write (const std::string &base_file_name) const 
write Matrix into (a) HDF file(s). More...  
void  read (const std::string &base_file_name) 
read Matrix into (a) HDF file(s). More...  
void  local_read (const std::string &base_file_name, int rank) 
read a single rank of a distributed Matrix into (a) HDF file(s). More...  
double *  getData () const 
Get the matrix data as a pointer.  
void  distribute (const int &local_num_rows) 
Distribute this matrix rows among MPI processes, based on the specified local number of rows. This becomes distributed after this function is executed. More...  
void  gather () 
Gather all the distributed rows among MPI processes. This becomes not distributed after this function is executed. More...  
Class Matrix is a simple matrix class in which the rows may be distributed across multiple processes. This class supports only the basic operations that are needed by the SVD library.
CAROM::Matrix::Matrix  (  ) 
Empty Constructor
Definition at line 63 of file Matrix.cpp.
CAROM::Matrix::Matrix  (  int  num_rows, 
int  num_cols,  
bool  distributed,  
bool  randomized = false 

) 
Constructor creating a Matrix with uninitialized values.
[in]  num_rows  When undistributed, the total number of rows of the Matrix. When distributed, the part of the total number of rows of the Matrix on this processor. 
[in]  num_cols  The total number of columns of the Matrix. 
[in]  distributed  If true the rows of the Matrix are spread over all processors. 
[in]  randomized  If true the matrix will be a standard normally distributed random matrix. 
Definition at line 70 of file Matrix.cpp.
CAROM::Matrix::Matrix  (  double *  mat, 
int  num_rows,  
int  num_cols,  
bool  distributed,  
bool  copy_data = true 

) 
Constructor creating a Matrix with uninitialized values.
[in]  mat  The initial values of the Matrix. 
[in]  num_rows  When undistributed, the total number of rows of the Matrix. When distributed, the part of the total number of rows of the Matrix on this processor. 
[in]  num_cols  The total number of columns of the Matrix. 
[in]  distributed  If true the rows of the Matrix are spread over all processors. 
[in]  copy_data  If true the matrix allocates its own storage and copies the contents of mat into its own storage. Otherwise it uses mat as its storage. 
Definition at line 104 of file Matrix.cpp.
CAROM::Matrix::Matrix  (  const Matrix &  other  ) 
Copy constructor.
[in]  other  The Matrix to copy. 
Definition at line 143 of file Matrix.cpp.
void CAROM::Matrix::distribute  (  const int &  local_num_rows  ) 
Distribute this matrix rows among MPI processes, based on the specified local number of rows. This becomes distributed after this function is executed.
[in]  local_num_rows  number of rows for local MPI rank. 
Definition at line 1046 of file Matrix.cpp.

inline 
Multiplies two matrices elementwise.
[in]  other  The Matrix to multiply with this. 
Multiplies two matrices elementwise and fills result with the answer.
Definition at line 479 of file Matrix.cpp.
Multiplies two matrices elementwise and fills result with the answer.
Definition at line 451 of file Matrix.cpp.
Multiplies two matrices elementwise and returns the product, pointer version.
[in]  other  The Matrix to multiply with this. 

inline 
void CAROM::Matrix::elementwise_square  (  Matrix &  result  )  const 
Square every element in the matrix.
[out]  result  The product Matrix. 
Definition at line 523 of file Matrix.cpp.
void CAROM::Matrix::elementwise_square  (  Matrix *&  result  )  const 
Square every element in the matrix.
[out]  result  The product Matrix. 
Definition at line 501 of file Matrix.cpp.
void CAROM::Matrix::gather  (  ) 
Gather all the distributed rows among MPI processes. This becomes not distributed after this function is executed.
Definition at line 1073 of file Matrix.cpp.

inline 
void CAROM::Matrix::getColumn  (  int  column, 
Vector &  result  
)  const 
Returns a column of the matrix (not owned by Matrix).
Definition at line 713 of file Matrix.cpp.
void CAROM::Matrix::getColumn  (  int  column, 
Vector *&  result  
)  const 
Returns a column of the matrix (not owned by Matrix).
Definition at line 698 of file Matrix.cpp.
Matrix * CAROM::Matrix::getFirstNColumns  (  int  n  )  const 
Get the first N columns of a matrix.
[in]  n  The number of columns to return. 
Definition at line 256 of file Matrix.cpp.
void CAROM::Matrix::getFirstNColumns  (  int  n, 
Matrix &  result  
)  const 
Get the first N columns of a matrix.
[in]  n  The number of columns to return. 
[out]  result  The truncated Matrix. 
Definition at line 294 of file Matrix.cpp.
void CAROM::Matrix::getFirstNColumns  (  int  n, 
Matrix *&  result  
)  const 
Get the first N columns of a matrix.
[in]  n  The number of columns to return. 
[out]  result  The truncated Matrix. 
Definition at line 266 of file Matrix.cpp.
void CAROM::Matrix::inverse  (  ) 
Computes the inverse of this and stores result in this.
Definition at line 840 of file Matrix.cpp.

inline 
Computes and returns the inverse of this.
void CAROM::Matrix::inverse  (  Matrix &  result  )  const 
Computes and returns the inverse of this.
Result will be sized accordingly.
[out]  result  The inverse of this. 
Definition at line 778 of file Matrix.cpp.
void CAROM::Matrix::inverse  (  Matrix *&  result  )  const 
Computes and returns the inverse of this.
If result has not been allocated it will be, otherwise it will be sized accordingly.
[out]  result  The inverse of this. 
Definition at line 723 of file Matrix.cpp.

inline 
Nonconst Matrix member access. Matrix data is stored in rowmajor format.
Allows constructs of the form mat[i, j] = val;

inline 
void CAROM::Matrix::local_read  (  const std::string &  base_file_name, 
int  rank  
) 
read a single rank of a distributed Matrix into (a) HDF file(s).
[in]  base_file_name  The base part of the file name. 
[in]  rank  The rank to read from. 
Definition at line 1009 of file Matrix.cpp.
Multiplies this Matrix with other and returns the product, reference version.
Supports multiplication of two undistributed matrices returning an undistributed Matrix, and multiplication of a distributed Matrix with an undistributed Matrix returning a distributed Matrix.
[in]  other  The Matrix to multiply with this. 
Multiplies this Matrix with other and fills result with the answer.
Supports multiplication of two undistributed matrices resulting in an undistributed Matrix, and multiplication of a distributed Matrix with an undistributed Matrix resulting in a distributed Matrix. Result will be sized accordingly.
Definition at line 344 of file Matrix.cpp.
Multiplies this Matrix with other and fills result with the answer.
Supports multiplication of two undistributed matrices resulting in an undistributed Matrix, and multiplication of a distributed Matrix with an undistributed Matrix resulting in a distributed Matrix. If result has not been allocated it will be, otherwise it will be sized accordingly.
Definition at line 314 of file Matrix.cpp.
Multiplies this Matrix with other and returns the product, pointer version.
Supports multiplication of two undistributed matrices returning an undistributed Matrix, and multiplication of a distributed Matrix with an undistributed Matrix returning a distributed Matrix.
[in]  other  The Matrix to multiply with this. 
Multiplies this Matrix with other and returns the product, reference version.
Supports multiplication of an undistributed Matrix and Vector returning an undistributed Vector, and multiplication of a distributed Matrix and an undistributed Vector returning a distributed Vector.
[in]  other  The Vector to multiply with this. 
Multiplies this Matrix with other and fills result with the answer.
Supports multiplication of an undistributed Matrix and Vector resulting in an undistributed Vector, and multiplication of a distributed Matrix and an undistributed Vector resulting in a distributed Vector. Result will be sized accordingly.
Definition at line 396 of file Matrix.cpp.
Multiplies this Matrix with other and fills result with the answer.
Supports multiplication of an undistributed Matrix and Vector resulting in an undistributed Vector, and multiplication of a distributed Matrix and an undistributed Vector resulting in a distributed Vector. If result has not been allocated it will be, otherwise it will be sized accordingly.
Definition at line 368 of file Matrix.cpp.
Multiplies this Matrix with other and returns the product, pointer version.
Supports multiplication of an undistributed Matrix and Vector returning an undistributed Vector, and multiplication of a distributed Matrix and an undistributed Vector returning a distributed Vector.
[in]  other  The Vector to multiply with this. 
Computes a += this*b*c.
Supports accumulation of the multiplication of an undistributed Matrix and Vector into an undistributed Vector, and accumulation of the multiplication of a distributed Matrix and an undistributed Vector into a distributed Vector.
[in,out]  a  The Vector to accumulate this*b into. 
[in]  b  The Vector multiplied by this. 
[in]  c  Scalar multiplication factor. 
Definition at line 539 of file Matrix.cpp.

inline 

inline 

inline 

inline 
Nonconst Matrix member access.
Allows constructs of the form mat[i, j] = val;

inline 
Addition operator.
[in]  rhs  The Matrix to add to this. 
Definition at line 183 of file Matrix.cpp.
Subtraction operator.
[in]  rhs  The Matrix to subtract to this. 
Definition at line 193 of file Matrix.cpp.
Matrix & CAROM::Matrix::operator=  (  const double  a  ) 
Assignment operator.
[in]  a  constant value 
Definition at line 246 of file Matrix.cpp.
Assignment operator.
[in]  rhs  The Matrix to assign to this. 
Definition at line 172 of file Matrix.cpp.
void CAROM::Matrix::orthogonalize  (  bool  double_pass = false , 
double  zero_tol = 1.0e15 

) 
Orthonormalizes the matrix.
The method uses the modified GramSchmidt algorithm.
If double_pass == true, then each column is orthogonalized twice to limit loss of orthogonality due to numerical errors. By default, double_pass == false.
If the norm of a matrix column is below the value of zero_tol then it is considered to be zero, and we do not divide by it. Therefore, that column is considered to be zero and is not normalized. By default, zero_tol == 1.0e15.
Definition at line 1803 of file Matrix.cpp.
void CAROM::Matrix::orthogonalize_last  (  int  ncols = 1 , 
bool  double_pass = false , 

double  zero_tol = 1.0e15 

) 
Orthonormalizes the matrix's last column, assuming the previous columns are already orthonormal.
By default, ncols == 1, and the function considers the whole matrix. If ncols != 1 and ncols < d_num_cols, then a subset of the matrix is considered. This allows one to reorthonormalize the matrix every time a new column is added, assuming the previous columns have remained unchanged.
If double_pass == true, then the column is orthogonalized twice to limit loss of orthogonality due to numerical errors. By default, double_pass == false.
If the norm of a matrix column is below the value of zero_tol then it is considered to be zero, and we do not divide by it. Therefore, that column is considered to be zero and is not normalized. By default, zero_tol == 1.0e15.
Definition at line 1853 of file Matrix.cpp.
Multiplies a specified row of this Matrix with other pointwise.
Only supports multiplication of an undistributed Matrix and Vector resulting in an undistributed Vector. Result will be sized accordingly.
[in]  this_row  The row of the matrix to multiple with other. 
[in]  other  The Vector to multiply with this_row of the matrix. 
[out]  result  The product Vector. 
Definition at line 418 of file Matrix.cpp.
void CAROM::Matrix::pointwise_mult  (  int  this_row, 
Vector &  other  
)  const 
Multiplies a specified row of this Matrix with other pointwise. This modifies other.
Only supports multiplication of an undistributed Matrix and Vector resulting in an undistributed Vector. Result will be sized accordingly.
[in]  this_row  The row of the matrix to multiple with other. 
[in]  other  The Vector to multiply with this_row of the matrix. 
[out]  other  The product Vector. 
Definition at line 436 of file Matrix.cpp.
void CAROM::Matrix::print  (  const char *  prefix  )  const 
print Matrix into (a) ascii file(s).
[in]  prefix  The name of the prefix of the file name. 
Definition at line 918 of file Matrix.cpp.
Matrix * CAROM::Matrix::qr_factorize  (  )  const 
Computes and returns the Q of the QR factorization of this.
Definition at line 1125 of file Matrix.cpp.
void CAROM::Matrix::qrcp_pivots_transpose  (  int *  row_pivot, 
int *  row_pivot_owner,  
int  pivots_requested  
)  const 
Compute the leading numColumns() column pivots from a QR decomposition with column pivots (QRCP) of the transpose of this.
[out]  row_pivot  Array of leading column pivots from QRCP of transpose of this Matrix, has length pivots_requested 
[out]  row_pivot_owner  Array of process rank that owns each pivot on the communicator owned by this Matrix. 
[in]  pivots_requested  The number of pivots requested, must be less than or equal to the number of rows of this Matrix. 
Definition at line 1198 of file Matrix.cpp.
void CAROM::Matrix::read  (  const std::string &  base_file_name  ) 
read Matrix into (a) HDF file(s).
[in]  base_file_name  The base part of the file name. 
Definition at line 969 of file Matrix.cpp.

inline 
void CAROM::Matrix::transpose  (  ) 
Replaces this Matrix with its transpose (in place), in the serial square case only.
Definition at line 824 of file Matrix.cpp.
Multiplies the transpose of this Matrix with other and returns the product, reference version.
Supports multiplication of two undistributed matrices returning an undistributed Matrix or two distributed matrices returning an undistributed Matrix.
[in]  other  The Matrix to multiply with this. 
Multiplies the transpose of this Matrix with other and fills result with the answer.
Supports multiplication of two undistributed matrices or two distributed matrices resulting in an undistributed Matrix. Result will be sized accordingly.
Definition at line 598 of file Matrix.cpp.
Multiplies the transpose of this Matrix with other and fills result with the answer.
Supports multiplication of two undistributed matrices or two distributed matrices resulting in an undistributed Matrix. If result has not been allocated it will be, otherwise it will be sized accordingly.
Definition at line 559 of file Matrix.cpp.
Multiplies the transpose of this Matrix with other and returns the product, pointer version.
Supports multiplication of two undistributed matrices returning an undistributed Matrix or two distributed matrices returning an undistributed Matrix.
[in]  other  The Matrix to multiply with this. 
Multiplies the transpose of this Matrix with other and returns the product, reference version.
Supports multiplication of an undistributed Matrix and an undistributed Vector or a distributed Matrix and a distributed Vector returning an undistributed Vector.
[in]  other  The Vector to multiply with this. 
Multiplies the transpose of this Matrix with other and fills result with the answer.
Supports multiplication of an undistributed Matrix and an undistributed Vector or a distributed Matrix and a distributed Vector resulting in an undistributed Vector. Result will be sized accordingly.
Definition at line 667 of file Matrix.cpp.
Multiplies the transpose of this Matrix with other and fills result with the answer.
Supports multiplication of an undistributed Matrix and an undistributed Vector or a distributed Matrix and a distributed Vector resulting in an undistributed Vector. If result has not been allocated it will be, otherwise it will be sized accordingly.
Definition at line 631 of file Matrix.cpp.
Multiplies the transpose of this Matrix with other and returns the product, pointer version.
Supports multiplication of an undistributed Matrix and an undistributed Vector or a distributed Matrix and a distributed Vector returning an undistributed Vector.
[in]  other  The Vector to multiply with this. 
void CAROM::Matrix::transposePseudoinverse  (  ) 
Computes the transposePseudoinverse of this.
Assumes this is full column rank; may fail if this is not full column rank.
Definition at line 882 of file Matrix.cpp.
void CAROM::Matrix::write  (  const std::string &  base_file_name  )  const 
write Matrix into (a) HDF file(s).
[in]  base_file_name  The base part of the file name. 
Definition at line 937 of file Matrix.cpp.