xc
Public Member Functions | Friends | List of all members
XC::Matrix Class Reference

Matrix of floats. More...

#include <Matrix.h>

Inheritance diagram for XC::Matrix:
Inheritance graph
[legend]
Collaboration diagram for XC::Matrix:
Collaboration graph
[legend]

Public Member Functions

 Matrix (void)
 Default constructor.
 
 Matrix (int nrows, int ncols)
 Constructor. More...
 
 Matrix (double *data, int nrows, int ncols)
 Constructor. More...
 
 Matrix (const Vector &v)
 Construct from vector.
 
 Matrix (const boost::python::list &l)
 Constructor (Python interface).
 
int setData (double *newData, int nRows, int nCols)
 
const double * getDataPtr (void) const
 
double * getDataPtr (void)
 
bool isEmpty (void) const
 
int getDataSize (void) const
 
int getNumBytes (void) const
 
int noRows () const
 Returns the number of rows, numRows, of the Matrix.
 
int noCols () const
 Returns the number of columns, numCols, of the Matrix.
 
void Zero (void)
 Zero's out the Matrix. More...
 
void Identity (void)
 
int resize (int numRow, int numCol)
 
int Assemble (const Matrix &, const ID &rows, const ID &cols, double fact=1.0)
 Assembles the argument into the current Matrix. More...
 
int Solve (const Vector &V, Vector &res) const
 Solve the equation {\(Ax=V\)} for the Vector x, which is returned. More...
 
int Solve (const Matrix &M, Matrix &res) const
 
int Invert (Matrix &res) const
 Return the inverse matrix in the argument.
 
Matrix getInverse (void) const
 
double rowSum (int i) const
 Returns the sum of the i-th row.
 
double columnSum (int j) const
 Returns the sum of the j-th row.
 
double rowNorm (void) const
 Returns the maximum value of the elements of the vector that results that contains the row sums. More...
 
double columnNorm (void) const
 Returns the maximum value of the elements of the vector that results that contains the column sums. More...
 
double Norm2 (void) const
 Returns the squared modulus (euclidean norm) of the matrix.
 
double Norm (void) const
 Returns the modulus (euclidean norm) of the matrix.
 
double OneNorm (void) const
 Returns the value of the one norm.
 
double RCond (void) const
 Return an estimation of the reciprocal of the condition number. More...
 
int addMatrix (double factThis, const Matrix &other, double factOther)
 Add a factor fact times the Matrix other to the current Matrix. More...
 
int addMatrixTranspose (double factThis, const Matrix &other, double factOther)
 
int addMatrixProduct (double factThis, const Matrix &A, const Matrix &B, double factOther)
 
int addMatrixTransposeProduct (double factThis, const Matrix &A, const Matrix &B, double factOther)
 
int addMatrixTripleProduct (double factThis, const Matrix &A, const Matrix &B, double factOther)
 to perform this += T' * B * T
 
int addMatrixTripleProduct (double factThis, const Matrix &A, const Matrix &B, const Matrix &C, double otherFact)
 to perform this += At * B * C
 
double & operator() (int row, int col)
 Returns a reference to the data at location({row,col}). More...
 
const double & operator() (int row, int col) const
 Returns a constant reference to the data at location({row,col}). More...
 
Matrix operator() (const ID &rows, const ID &cols) const
 Returns a new Matrix of dimension (rows.Size(), {cols.Size()}). More...
 
Vector getRow (int row) const
 Return the row which index being passed as parameter.
 
void putRow (int, const Vector &)
 Put the vector at the i-th row.
 
Vector getCol (int col) const
 Return the column which index being passed as parameter.
 
void putCol (int, const Vector &)
 Put the vector at the i-th col.
 
boost::python::list getPyList (void) const
 Return the matrix values in a Python list.
 
void setPyList (const boost::python::list &)
 Populate the matrix with the values of the given list.
 
template<class TNSR >
Matrixoperator= (const TNSR &)
 
bool isRow (void) const
 
bool isColumn (void) const
 
Matrixoperator+= (double fact)
 A method to add fact to each component of the current Matrix. More...
 
Matrixoperator-= (double fact)
 A method to subtract fact from each component of the current Matrix. More...
 
Matrixoperator*= (double fact)
 A method to multiply each component of the current Matrix by fact. More...
 
Matrixoperator/= (double fact)
 A method which will divide each component of the current Matrix by fact. More...
 
Matrix operator+ (double fact) const
 A method to return a new Matrix, whose components are equal to the components of the current Matrix plus the value fact. More...
 
Matrix operator- (double fact) const
 A method to return a new Matrix, whose components are equal to the components of the current Matrix minus the value fact. More...
 
Matrix operator* (double fact) const
 A method to return a new Matrix, whose components are equal to the components of the current Matrix times the value fact. More...
 
Matrix operator/ (double fact) const
 A method to return a new Matrix whose components are equal to the components of the current Matrix divided the value fact. More...
 
Vector operator* (const Vector &V) const
 A method to return a new Vector, of size numRows, whose components are equal to the product of the current Matrix times the Vector {V}. More...
 
Vector operator^ (const Vector &V) const
 A method to return a new Vector, of size numCols, whose components are equal to the product of the transpose of the current Matrix times the Vector V. More...
 
Matrix operator- (void) const
 Unary minus operator.
 
Matrix operator+ (const Matrix &M) const
 A method to return a new Matrix equal to the sum of the current Matrix and the Matrix M. More...
 
Matrix operator- (const Matrix &M) const
 A method to return a new Matrix equal to the the current Matrix minus the Matrix M. More...
 
Matrix operator* (const Matrix &M) const
 A method to return a new Matrix equal to the product of the current Matrix and the Matrix M. More...
 
Matrix operator^ (const Matrix &M) const
 A method to return a new Matrix equal to the product of the transpose of the current Matrix and the Matrix M. More...
 
Matrixoperator+= (const Matrix &M)
 += operator.
 
Matrixoperator-= (const Matrix &M)
 -= operator.
 
Matrix getTrn (void) const
 Return the transpuesta.
 
void Output (std::ostream &s) const
 Write to the argument stream.
 
void Input (const std::string &)
 Read from string.
 
void write (std::ofstream &)
 Write to a binary file.
 
void read (std::ifstream &)
 Read from a bynary file.
 
int Assemble (const Matrix &V, int init_row, int init_col, double fact=1.0)
 Assemble.
 
int AssembleTranspose (const Matrix &V, int init_row, int init_col, double fact=1.0)
 
int Extract (const Matrix &V, int init_row, int init_col, double fact=1.0)
 
std::string toString (void) const
 
template<class TNSR >
XC::Matrixoperator= (const TNSR &V)
 Assignment operator.
 
- Public Member Functions inherited from CommandEntity
 CommandEntity (CommandEntity *owr=nullptr)
 Default constructor.
 
CommandEntityOwner (void)
 Return a pointer to the object owner.
 
const CommandEntityOwner (void) const
 Return un puntero al objeto propietario de ESTE.
 
const StandardOutputWrappergetStandardOutputWrapper (void) const
 Return the regular output stream wrapper.
 
StandardOutputWrappergetStandardOutputWrapper (void)
 Return the regular output stream wrapper.
 
const std::string & getLogFileName (void) const
 Returns log file name.
 
void setLogFileName (const std::string &)
 Sets log file name.
 
const std::string & getErrFileName (void) const
 Returns err file name.
 
void setErrFileName (const std::string &)
 Sets error file name.
 
const std::string & getOutputFileName (void) const
 Returns regular output file name.
 
void setOutputFileName (const std::string &)
 Sets regular output file name.
 
boost::python::object evalPy (boost::python::object dict, const std::string &)
 Return the Python object that results from evaluating the argument.
 
boost::python::object execPy (boost::python::object dict, const std::string &)
 Return the Python objects that results from executing the code in the string argument.
 
boost::python::object execFilePy (boost::python::object dict, const std::string &)
 Return the Python object that results from executing the code in the file.
 
- Public Member Functions inherited from EntityWithProperties
 EntityWithProperties (EntityWithProperties *owr=nullptr)
 Default constructor.
 
void clearPyProps (void)
 Clear python properties map.
 
bool hasPyProp (const std::string &)
 Returns true if property exists.
 
boost::python::object getPyProp (const std::string &str)
 Return the Python object with the name being passed as parameter.
 
void setPyProp (std::string str, boost::python::object val)
 Sets/appends a value tho the Python object's dictionary.
 
void copyPropsFrom (const EntityWithProperties &)
 Copy the properties from the argument.
 
boost::python::list getPropNames (void) const
 Return the names of the object properties weightings.
 
const PythonDict & getPropertiesDict (void) const
 Return a std::map container with the properties of the object.
 
boost::python::dict getPyDict (void) const
 Return a Python dictionary containing the object members values.
 
void setPyDict (const boost::python::dict &)
 Set the values of the object members from a Python dictionary.
 
- Public Member Functions inherited from EntityWithOwner
 EntityWithOwner (EntityWithOwner *owr=nullptr)
 Default constructor.
 
 EntityWithOwner (const EntityWithOwner &)
 Copy constructor.
 
EntityWithOwneroperator= (const EntityWithOwner &)
 Assignment operator.
 
virtual bool operator== (const EntityWithOwner &) const
 Comparison operator.
 
virtual ~EntityWithOwner (void)
 Virtual destructor.
 
virtual std::string getClassName (void) const
 Returns demangled class name.
 
void set_owner (EntityWithOwner *owr)
 Assigns the owner of the object.
 
EntityWithOwnerOwner (void)
 
const EntityWithOwnerOwner (void) const
 

Friends

class Vector
 
class Message
 
class TCP_Socket
 
class TCP_SocketNoDelay
 
class UDP_Socket
 
class MPI_Channel
 
std::ostream & operator<< (std::ostream &, const Matrix &)
 
std::string to_string (const Matrix &)
 Returns a string that represents the matrix.
 
Matrix operator* (double, const Matrix &)
 

Additional Inherited Members

- Public Types inherited from EntityWithProperties
typedef std::map< std::string, boost::python::object > PythonDict
 
- Static Public Member Functions inherited from CommandEntity
static void resetStandardOutput (void)
 Reset the standard output streams to its defaults buffers.
 
- Static Public Member Functions inherited from EntityWithOwner
static int getVerbosityLevel (void)
 Get the value of the verbosity level.
 
static void setVerbosityLevel (const int &)
 Set the value of the verbosity level.
 
- Protected Member Functions inherited from CommandEntity
template<class T >
void string_to (T &, const std::string &) const
 
- Protected Member Functions inherited from EntityWithProperties
bool isEqual (const EntityWithProperties &) const
 Return true if both objects are equal.
 
- Protected Member Functions inherited from EntityWithOwner
virtual bool isEqual (const EntityWithOwner &) const
 Return true if both objects are equal.
 
- Static Protected Member Functions inherited from CommandEntity
static CommandEntityentcmd_cast (boost::any &data)
 
- Static Protected Attributes inherited from EntityWithOwner
static int verbosity = 1
 Object that owns THIS ONE. More...
 

Detailed Description

Matrix of floats.

The Matrix class provides the matrix abstraction. A matrix of order numRows X numCols is an ordered 2d array of numbers arranged in numRows rows and numCols columns. For example, a matrix \(A\) of order 2 X 3: \( A = \left[ \begin{array}{ccc} a_{0,0} & a_{0,1} & a_{0,2}\\ a_{1,0} & a_{1,1} & a_{1,2} \end{array} \right] \)

The Matrix class provides the implementation of a general unsymmetric matrix. The data for the matrix is stored in a 1d double array of size numRows*numCols with the data for \(a_{i,j}\) located at j*numRows + i in the 1d array. This is similar to the ordering of a Fortran 2d array and will permit calls to numerical Fortran libraries, e.g. BLAS, for certain method calls at a future stage. At present no subclassing is permitted (THIS MAY CHANGE), the reason for this is that the Matrix objects are envisioned to be small scale matrices primarily used for the passing of data between objects in the system. To allow subclassing could reduce the efficiency of the program due to the manner in which virtual functions are implemented.

Constructor & Destructor Documentation

◆ Matrix() [1/2]

XC::Matrix::Matrix ( int  nRows,
int  nCols 
)

Constructor.

To construct a Matrix with nRows and numberOfColumns and all coefficients equal to \(0\). Allocates memory for the storage of the data. If numRows \(<\) \(0\), numCols \(<\) \(0\) or not enough memory is available available, an error message is printed and a Matrix with numRows = \(0\) and numCols = \(0\) is returned. Before the Matrix is returned, Zero() is called.

Parameters
nRowsnumber of matrix rows.
numberOfColumnsnumber of matrix columns.

◆ Matrix() [2/2]

XC::Matrix::Matrix ( double *  theData,
int  nRows,
int  nCols 
)

Constructor.

Wrapper for values contained in theData.

To construct a Matrix with nRow and nCols. The memory for storage of the data is found at the location pointed to by data. Note that this memory must have been previously allocated and it must be of appropriate size, erroneous results and segmentation faults can occur otherwise. No additional memory is allocated for the storage of the data.

Parameters
theDatavalues.
nRowsnumber of matrix rows.
nColsnumber of matrix columns.

Member Function Documentation

◆ addMatrix()

int XC::Matrix::addMatrix ( double  factThis,
const Matrix other,
double  factOther 
)

Add a factor fact times the Matrix other to the current Matrix.

To add a factor fact times the Matrix other to the current Matrix. The size of the other Matrix is first checked to see sizes are compatible; if size are not compatible nothing is done and a warning message is printed. The method tests for the type of other, to see whether the performance can be improved by avoiding having to call other's overloaded (i,j) operators, if other is of type genMatrix.

◆ Assemble()

int XC::Matrix::Assemble ( const Matrix V,
const ID rows,
const ID cols,
double  fact = 1.0 
)

Assembles the argument into the current Matrix.

Assembles into the current Matrix the Matrix M. The contents of the current matrix at location ({rows(i),cols(j)}) is set equal to the current value plus fact times the value of the matrix M at location ({i,j }). A warning is printed for every {rows(i), cols(j)} specified which is outside the bounds of the matrix.

◆ columnNorm()

double XC::Matrix::columnNorm ( void  ) const

Returns the maximum value of the elements of the vector that results that contains the column sums.

◆ operator()() [1/3]

double & XC::Matrix::operator() ( int  row,
int  col 
)
inline

Returns a reference to the data at location({row,col}).

Returns a reference to the data at location({row,col}) in the Matrix. Assumes ({row,col}) is a valid location in the Matrix, a segmentation fault or erroneous results can occur if this is not the case.

{inline double &operator()(int row, int col);} Used to set the data at location({row,col}) in the Matrix. Assumes ({row,col}) is a valid location in the Matrix, a segmentation fault or erroneous results can occur if this is not the case.

◆ operator()() [2/3]

const double & XC::Matrix::operator() ( int  row,
int  col 
) const
inline

Returns a constant reference to the data at location({row,col}).

Returns a constant reference to the data at location({row,col}) in the Matrix. Assumes ({row,col}) is a valid location in the Matrix, a segmentation fault or erroneous results can occur if this is not the case.

{inline double &operator()(int row, int col);} Used to set the data at location({row,col}) in the Matrix. Assumes ({row,col}) is a valid location in the Matrix, a segmentation fault or erroneous results can occur if this is not the case.

◆ operator()() [3/3]

XC::Matrix XC::Matrix::operator() ( const ID rows,
const ID cols 
) const

Returns a new Matrix of dimension (rows.Size(), {cols.Size()}).

The contents of the new matrix are given by the contents of the current matrix at the locations given by the {rows} and cols objects. For example the contents of the new matrix at location ({i,j}) are equal to the contents of the current matrix at location ({rows(i),cols(j)}). Assumes ({row,col}) is a valid location in the Matrix, a segmentation fault or erroneous results can occur if this is not the case.

◆ operator*() [1/3]

XC::Matrix XC::Matrix::operator* ( double  fact) const

A method to return a new Matrix, whose components are equal to the components of the current Matrix times the value fact.

A method to return a new Matrix, whose components are equal to the components of the current Matrix times the value fact. A new Matrix object is constructed, using the current Matrix as the argument to the constructor. The {*=} operator is then invoked on this Matrix with fact as the argument, and this new Matrix is then returned.

◆ operator*() [2/3]

XC::Vector XC::Matrix::operator* ( const Vector V) const

A method to return a new Vector, of size numRows, whose components are equal to the product of the current Matrix times the Vector {V}.

A method to return a new Vector, of size numRows, whose components are equal to the product of the current Matrix times the Vector {V}. If the current Matrix and Vector V are not compatible, i.e. V.Size() is not equal to numCols, an error message is printed and a zero Vector of size equal to the number of rows in the current Matrix is returned. The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if the current Matrix is of type genMatrix.

◆ operator*() [3/3]

XC::Matrix XC::Matrix::operator* ( const Matrix M) const

A method to return a new Matrix equal to the product of the current Matrix and the Matrix M.

A method to return a new Matrix equal to the product of the current Matrix and the Matrix M. It does this by first creating a new Matrix of size numRows and M.numCols. The contents of this new Matrix are then determined and the resulting Matrix is returned. If the two matrices are of incompatible sizes, a warning message is printed and a zeroed Matrix is returned. The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if M is of type genMatrix.

◆ operator*=()

XC::Matrix & XC::Matrix::operator*= ( double  fact)

A method to multiply each component of the current Matrix by fact.

A method to multiply each component of the current Matrix by fact. The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if the current Matrix is of type genMatrix.

◆ operator+() [1/2]

XC::Matrix XC::Matrix::operator+ ( double  fact) const

A method to return a new Matrix, whose components are equal to the components of the current Matrix plus the value fact.

A method to return a new Matrix, whose components are equal to the components of the current Matrix plus the value fact. A new Matrix object is constructed, using the current Matrix as the argument to the constructor. The {+=} operator is then invoked on this Matrix with fact as the argument, and the new Matrix is then returned.

◆ operator+() [2/2]

XC::Matrix XC::Matrix::operator+ ( const Matrix M) const

A method to return a new Matrix equal to the sum of the current Matrix and the Matrix M.

A method to return a new Matrix equal to the sum of the current Matrix and the Matrix M. It does this by creating a new matrix passing itself as an argument to the constructor. The addMatrix() method is then invoked on this new Matrix with \(M\) and \(-1\) as the arguments. The new Matrix is then returned.

◆ operator+=()

XC::Matrix & XC::Matrix::operator+= ( double  fact)

A method to add fact to each component of the current Matrix.

A method to add fact to each component of the current Matrix. The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if the current Matrix is of type genMatrix.

◆ operator-() [1/2]

XC::Matrix XC::Matrix::operator- ( double  fact) const

A method to return a new Matrix, whose components are equal to the components of the current Matrix minus the value fact.

A method to return a new Matrix, whose components are equal to the components of the current Matrix minus the value fact. A new Matrix object is constructed, using the current Matrix as the argument to the constructor. The {-=} operator is then invoked on this Matrix with fact as the argument, and this new Matrix is then returned.

◆ operator-() [2/2]

XC::Matrix XC::Matrix::operator- ( const Matrix M) const

A method to return a new Matrix equal to the the current Matrix minus the Matrix M.

A method to return a new Matrix equal to the the current Matrix minus the Matrix M. It does this by creating a new matrix passing itself as an argument to the constructor. The addMatrix() method is then invoked on this new Matrix with \(M\) and \(-1\) as the arguments. The new Matrix is then returned.

◆ operator-=()

XC::Matrix & XC::Matrix::operator-= ( double  fact)

A method to subtract fact from each component of the current Matrix.

A method to subtract fact from each component of the current Matrix. The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if the current Matrix is of type genMatrix.

◆ operator/()

XC::Matrix XC::Matrix::operator/ ( double  fact) const

A method to return a new Matrix whose components are equal to the components of the current Matrix divided the value fact.

A method to return a new Matrix whose components are equal to the components of the current Matrix divided the value fact. A new Matrix object is constructed by using the current Matrix as the argument to the constructor. The {/=} operator is then invoked on this Matrix with fact as the argument, and this new Matrix is then returned.

◆ operator/=()

XC::Matrix & XC::Matrix::operator/= ( double  fact)

A method which will divide each component of the current Matrix by fact.

A method which will divide each component of the current Matrix by fact. If fact is equal to zero, an error message is printed and the contents of the Matrix are set to MATRIX_VERY_LARGE_VALUE (defined in \(<\)Matrix.h \(>\)). The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if the current Matrix is of type genMatrix.

◆ operator^() [1/2]

XC::Vector XC::Matrix::operator^ ( const Vector V) const

A method to return a new Vector, of size numCols, whose components are equal to the product of the transpose of the current Matrix times the Vector V.

A method to return a new Vector, of size numCols, whose components are equal to the product of the transpose of the current Matrix times the Vector V. If the current Matrix and Vector V are not compatible, i.e. V.Size() is not equal to numRows, an error message is printed and a zero Vector of size equal to the number of columns in the current Matrix is returned. The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if the current Matrix is of type genMatrix.

◆ operator^() [2/2]

XC::Matrix XC::Matrix::operator^ ( const Matrix M) const

A method to return a new Matrix equal to the product of the transpose of the current Matrix and the Matrix M.

A method to return a new Matrix equal to the product of the transpose of the current Matrix and the Matrix M. It does this by first creating a new Matrix of size numRows and M.numRows. The contents of this new Matrix are then determined and the resulting Matrix is returned. If the two matrices are of incompatible sizes, a warning message is printed and a zeroed Matrix is returned. The method tests for the type of the current Matrix, to see whether the performance can be improved by avoiding having to call the overloaded (i,j) operators, if M is of type genMatrix.

◆ RCond()

double XC::Matrix::RCond ( void  ) const

Return an estimation of the reciprocal of the condition number.

estimates the reciprocal of the condition number of the matrix using the 1-norm. An estimate is obtained for norm(inv(A)), and the reciprocal of the condition number is computed as RCond = 1 / ( norm(A) * norm(inv(A)) ).

◆ rowNorm()

double XC::Matrix::rowNorm ( void  ) const

Returns the maximum value of the elements of the vector that results that contains the row sums.

◆ Solve()

int XC::Matrix::Solve ( const Vector b,
Vector x 
) const

Solve the equation {\(Ax=V\)} for the Vector x, which is returned.

Will solve the equation {\(Ax=V\)} for the Vector x, which is returned. At the moment the current matrix is assumed to be symmetric positive definite. THIS IS TO CHANGE. A Vector is created using V. If this Vector is not of the correct size or if an error occurs during factorization a warning message is printed and the Vector x is returned.

◆ Zero()

void XC::Matrix::Zero ( void  )

Zero's out the Matrix.

Zero's out the Matrix, i.e. sets all the components of the matrix to \(0\).


The documentation for this class was generated from the following files: