1.1.0
CCC
 
AMatrix Class Referenceabstract

#include <AMatrix.hpp>

Inheritance diagram for AMatrix:
AStringable ICloneable AMatrixDense MatrixSparse MatrixRectangular ProjMatrix AMatrixSquare Table MatrixSquareGeneral MatrixSquareSymmetric

Public Member Functions

 AMatrix (int nrow=0, int ncol=0, int opt_eigen=-1)
 
 AMatrix (const AMatrix &m)
 
AMatrixoperator= (const AMatrix &m)
 
virtual ~AMatrix ()
 
void init (int nrows, int ncols, int opt_eigen=-1)
 
void reset (int nrows, int ncols, double value=0., int opt_eigen=-1)
 
void resetFromArray (int nrows, int ncols, const double *tab, bool byCol=true, int opt_eigen=-1)
 
void resetFromVD (int nrows, int ncols, const VectorDouble &tab, bool byCol=true, int opt_eigen=-1)
 
void resetFromVVD (const VectorVectorDouble &tab, bool byCol=true, int opt_eigen=-1)
 
virtual String toString (const AStringFormat *strfmt=nullptr) const override
 Interface to AStringable. More...
 
virtual bool isDense () const
 
virtual bool isSparse () const
 
virtual bool isSquare (bool printWhyNot=false) const
 
virtual bool isValid (int irow, int icol, bool printWhyNot=false) const
 
virtual bool isIdentity (bool printWhyNot=false) const
 
virtual bool isSymmetric (bool printWhyNot=false) const
 
virtual bool isDiagonal (bool printWhyNot=false) const
 
virtual bool isDiagCst (bool printWhyNot=false) const
 
virtual bool mustBeSymmetric () const
 
virtual bool mustBeDiagonal () const
 
virtual bool mustBeDiagCst () const
 
virtual void setColumn (int icol, const VectorDouble &tab)
 
virtual void setRow (int irow, const VectorDouble &tab)
 
virtual void setDiagonal (const VectorDouble &tab)
 
virtual void setDiagonalToConstant (double value=1.)
 
virtual void transposeInPlace ()
 
virtual AMatrixtranspose () const
 
virtual void addScalar (double v)
 
virtual void addScalarDiag (double v)
 
virtual void prodScalar (double v)
 
virtual void fill (double value)
 
virtual void multiplyRow (const VectorDouble &vec)
 
virtual void multiplyColumn (const VectorDouble &vec)
 
virtual void divideRow (const VectorDouble &vec)
 
virtual void divideColumn (const VectorDouble &vec)
 
virtual VectorDouble prodVecMat (const VectorDouble &x, bool transpose=false) const
 
virtual VectorDouble prodMatVec (const VectorDouble &x, bool transpose=false) const
 
virtual VectorDouble getRow (int irow) const
 
virtual VectorDouble getColumn (int icol) const
 
virtual void prodMatMatInPlace (const AMatrix *x, const AMatrix *y, bool transposeX=false, bool transposeY=false)
 
virtual NF_Triplet getMatrixToTriplet (int shiftRow=0, int shiftCol=0) const
 
void addMatInPlace (const AMatrix &y, double cx=1., double cy=1.)
 
void prodMatInPlace (const AMatrix *matY, bool transposeY=false)
 
void prodNormMatMatInPlace (const AMatrix &a, const AMatrix &m, bool transpose=false)
 
void prodNormMatInPlace (const AMatrix &a, const VectorDouble &vec=VectorDouble(), bool transpose=false)
 
void resize (int nrows, int ncols)
 
double getValue (int irow, int icol) const
 
void setValue (int irow, int icol, double value)
 
void setValue_ (int irow, int icol, double value)
 
double getValue_ (int irow, int icol) const
 
void addValue (int irow, int icol, double value)
 
bool isSame (const AMatrix &m, double eps=EPSILON10)
 
bool isSameSize (const AMatrix &m) const
 
bool empty () const
 
double compare (const AMatrix &mat) const
 
int getNRows () const
 
int getNCols () const
 
int size () const
 
VectorDouble getValues (bool byCol=true) const
 
VectorDouble getDiagonal (int shift=0) const
 
bool isColumnDefined (int icol) const
 
bool isRowDefined (int irow) const
 
int getNumberColumnDefined () const
 
int getNumberRowDefined () const
 
bool isFlagEigen () const
 
void prodMatVecInPlace (const VectorDouble &x, VectorDouble &y, bool transpose=false) const
 
void prodMatVecInPlacePtr (const double *x, double *y, bool transpose=false) const
 
void prodVecMatInPlace (const VectorDouble &x, VectorDouble &y, bool transpose=false) const
 
void prodVecMatInPlacePtr (const double *x, double *y, bool transpose=false) const
 
double quadraticMatrix (const VectorDouble &x, const VectorDouble &y)
 
int invert ()
 
int solve (const VectorDouble &b, VectorDouble &x) const
 
void dumpElements (const String &title, int ifrom, int ito) const
 
void setIdentity (double value=1.)
 
void fillRandom (int seed=432432, double zeroPercent=0.1)
 
void setValues (const VectorDouble &values, bool byCol=true)
 
double getMeanByColumn (int icol) const
 
double getMinimum () const
 
double getMaximum () const
 
void copyReduce (const AMatrix *x, const VectorInt &activeRows, const VectorInt &activeCols)
 
void copyElements (const AMatrix &m, double factor=1.)
 
void setFlagCheckAddress (bool flagCheckAddress)
 
bool isNonNegative (bool verbose)
 
void makePositiveColumn ()
 
double operator() (int row, int col) const
 
double & operator() (int row, int col)
 
- Public Member Functions inherited from AStringable
 AStringable ()
 
 AStringable (const AStringable &r)
 
AStringableoperator= (const AStringable &r)
 
virtual ~AStringable ()
 
virtual void display (const AStringFormat *strfmt=nullptr) const final
 
virtual void display (int level) const final
 
- Public Member Functions inherited from ICloneable
 ICloneable ()
 
virtual ~ICloneable ()
 
virtual ICloneableclone () const =0
 

Detailed Description

Matrix

Constructor & Destructor Documentation

AMatrix::AMatrix ( int  nrow = 0,
int  ncol = 0,
int  opt_eigen = -1 
)
AMatrix::AMatrix ( const AMatrix m)
AMatrix::~AMatrix ( )
virtual

Member Function Documentation

void AMatrix::addMatInPlace ( const AMatrix y,
double  cx = 1.,
double  cy = 1. 
)

Add a matrix (multiplied by a constant)

Add the matrix 'y' to the current Matrix

Parameters
yMatrix to be added
cxMultiplicative parameter for this
cyMultiplicative parameter for y
void AMatrix::addScalar ( double  v)
virtual

Add a value to each matrix component

Parameters
vAdd a scalar value to all (valid) terms of the current matrix

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::addScalarDiag ( double  v)
virtual

Add value to matrix diagonal

Parameters
vAdd constant value to the diagonal of the current Matrix

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::addValue ( int  irow,
int  icol,
double  value 
)

Add a value to a matrix term

double AMatrix::compare ( const AMatrix mat) const

Returns the sum of absolute difference between argument and this

void AMatrix::copyElements ( const AMatrix m,
double  factor = 1. 
)

Copy the contents of matrix 'm' into 'this' Warning: matrices must have the same dimensions (not checked)

Parameters
mInput matrix
factorMultiplicative factor (applied to each element)
void AMatrix::copyReduce ( const AMatrix x,
const VectorInt activeRows,
const VectorInt activeCols 
)
void AMatrix::divideColumn ( const VectorDouble vec)
virtual

Divide a Matrix column-wise

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::divideRow ( const VectorDouble vec)
virtual

Divide a Matrix row-wise

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::dumpElements ( const String title,
int  ifrom,
int  ito 
) const

Dump a specific range of samples from the internal storage

bool AMatrix::empty ( ) const
inline

Returns if the current matrix is Empty

void AMatrix::fill ( double  value)
virtual

Set all the values of the Matrix at once

Fill 'this' with the constant 'value'

Parameters
valueConstant value used for filling 'this'

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::fillRandom ( int  seed = 432432,
double  zeroPercent = 0.1 
)
VectorDouble AMatrix::getColumn ( int  icol) const
virtual

Extract a Column

Reimplemented in AMatrixDense.

VectorDouble AMatrix::getDiagonal ( int  shift = 0) const

Extract a Diagonal (main or secondary) of this

NF_Triplet AMatrix::getMatrixToTriplet ( int  shiftRow = 0,
int  shiftCol = 0 
) const
virtual

Extract the contents of the matrix

From a matrix of any type, creates the three vectors of the triplet (specific format for creating efficiently a Sparse matrix) It only takes the only non-zero elements of the matrix

Reimplemented in MatrixSparse.

double AMatrix::getMaximum ( ) const
double AMatrix::getMeanByColumn ( int  icol) const
double AMatrix::getMinimum ( ) const
int AMatrix::getNCols ( ) const
inline

Returns the number of columns

int AMatrix::getNRows ( ) const
inline

Returns the number of rows

int AMatrix::getNumberColumnDefined ( ) const

Define the number of defined columns

int AMatrix::getNumberRowDefined ( ) const

Define the number of defined rows

VectorDouble AMatrix::getRow ( int  irow) const
virtual

Extract a Row

Reimplemented in AMatrixDense.

double AMatrix::getValue ( int  irow,
int  icol 
) const

Gets the value at row 'irow' and column 'icol'

double AMatrix::getValue_ ( int  irow,
int  icol 
) const

Gets the value at row 'irow' and column 'icol' (no test)

VectorDouble AMatrix::getValues ( bool  byCol = true) const

Returns the contents of the whole matrix as a VectorDouble

void AMatrix::init ( int  nrows,
int  ncols,
int  opt_eigen = -1 
)
int AMatrix::invert ( )

Matrix inversion in place

bool AMatrix::isColumnDefined ( int  icol) const

Checks if a Column is valid (contains a non TEST value)

virtual bool AMatrix::isDense ( ) const
inlinevirtual

Returns if the matrix belongs to the AMatrixDense class (avoids dynamic_cast)

Reimplemented in AMatrixDense.

bool AMatrix::isDiagCst ( bool  printWhyNot = false) const
virtual

Check if the contents of the matrix is constant and diagonal

bool AMatrix::isDiagonal ( bool  printWhyNot = false) const
virtual

Check if the matrix is (non empty) diagonal

bool AMatrix::isFlagEigen ( ) const
inline

Returns if the Matrix is built using Eigen Library or not

bool AMatrix::isIdentity ( bool  printWhyNot = false) const
virtual

Check if the matrix is square and Identity

bool AMatrix::isNonNegative ( bool  verbose)

Check if all the elements of a matrix are non-negative

Returns
True if the matrix is non-negative; False otherwise
Parameters
[in]verboseTrue for the verbose option
bool AMatrix::isRowDefined ( int  irow) const

Checks if a Row is valid (contains a non TEST value)

bool AMatrix::isSame ( const AMatrix m,
double  eps = EPSILON10 
)

Check if a matrix is the same as me (norm L1)

bool AMatrix::isSameSize ( const AMatrix m) const

Check that both matrix have the same number of rows and columns

Check that Matrix 'm' share the same dimensions as current one

Parameters
mMatrix to be compared to the current Matrix
Returns
true if 'm' has same dimensions as the current Matrix
virtual bool AMatrix::isSparse ( ) const
inlinevirtual

Returns if the current matrix is Sparse

Reimplemented in MatrixSparse.

bool AMatrix::isSquare ( bool  printWhyNot = false) const
virtual

Check if the matrix is (non empty) square

Reimplemented in MatrixSquareGeneral.

bool AMatrix::isSymmetric ( bool  printWhyNot = false) const
virtual

Check if the input matrix is (non empty and square) symmetric

Reimplemented in MatrixSquareSymmetric.

bool AMatrix::isValid ( int  irow,
int  icol,
bool  printWhyNot = false 
) const
virtual

Indicate if the given indices are valid for the current matrix size

Indicate if the given indices are valid for the current matrix size

Parameters
irowRow index
icolColumn index
printWhyNotPrint the message is the answer if false
Returns
true if indices are valid for the current matrix size
void AMatrix::makePositiveColumn ( )

Modify the contents of the matrix so that each column has a positive sum of elements. If this is not the case, simply invert the sign of the column

void AMatrix::multiplyColumn ( const VectorDouble vec)
virtual

Multiply a Matrix column-wise

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::multiplyRow ( const VectorDouble vec)
virtual

Multiply a Matrix row-wise

Reimplemented in MatrixSparse, and AMatrixDense.

virtual bool AMatrix::mustBeDiagCst ( ) const
inlinevirtual

Say if the matrix must be diagonal constant

Reimplemented in MatrixSquareSymmetric, MatrixRectangular, and MatrixSquareGeneral.

virtual bool AMatrix::mustBeDiagonal ( ) const
inlinevirtual

Say if the matrix must be diagonal

Reimplemented in MatrixSquareSymmetric, MatrixRectangular, and MatrixSquareGeneral.

virtual bool AMatrix::mustBeSymmetric ( ) const
inlinevirtual

Say if the matrix must be symmetric

Reimplemented in MatrixSquareSymmetric, MatrixRectangular, and MatrixSquareGeneral.

double AMatrix::operator() ( int  row,
int  col 
) const
inline

Get value operator override

double& AMatrix::operator() ( int  row,
int  col 
)
inline

Set value operator override

AMatrix & AMatrix::operator= ( const AMatrix m)
void AMatrix::prodMatInPlace ( const AMatrix matY,
bool  transposeY = false 
)

Multiply 'this' by matrix 'y' and store in 'this'

void AMatrix::prodMatMatInPlace ( const AMatrix x,
const AMatrix y,
bool  transposeX = false,
bool  transposeY = false 
)
virtual

Multiply matrix 'x' by matrix 'y' and store the result in 'this'

Store the product of 'x'(or 't(x)') by 'y' (or 't(y') in this

Parameters
xFirst Matrix
ySecond matrix
transposeXTrue if first matrix must be transposed
transposeYTrue if second matrix must be transposed

Reimplemented in MatrixSparse, and AMatrixDense.

VectorDouble AMatrix::prodMatVec ( const VectorDouble x,
bool  transpose = false 
) const
virtual

Perform 'this' * 'vec'

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::prodMatVecInPlace ( const VectorDouble x,
VectorDouble y,
bool  transpose = false 
) const

Perform 'y' = 'this' * 'x'

Returns 'y' = 'this' %*% 'x'

Parameters
xInput vector
yOutput vector obtained by multiplying 'inv' by current Matrix
transposeTrue if the matrix 'this' must be transposed
void AMatrix::prodMatVecInPlacePtr ( const double *  x,
double *  y,
bool  transpose = false 
) const
void AMatrix::prodNormMatInPlace ( const AMatrix a,
const VectorDouble vec = VectorDouble(),
bool  transpose = false 
)

Product 't(A)' %*% ['vec'] %*% 'A' or 'A' %*% ['vec'] %*% 't(A)' stored in 'this'

void AMatrix::prodNormMatMatInPlace ( const AMatrix a,
const AMatrix m,
bool  transpose = false 
)

Product 't(A)' %*% 'M' %*% 'A' or 'A' %*% 'M' %*% 't(A)' stored in 'this'

Product 't(A)' %*% 'M' %*% 'A' or 'A' %*% 'M' %*% 't(A)' stored in 'this'

Parameters
aMatrix A
mMatrix M
transposeTrue for first implementation, False for the second
void AMatrix::prodScalar ( double  v)
virtual

Multiply each matrix component by a value

Parameters
vMultiply all the terms of the matrix by the scalar 'v'

Reimplemented in MatrixSparse, and AMatrixDense.

VectorDouble AMatrix::prodVecMat ( const VectorDouble x,
bool  transpose = false 
) const
virtual

Perform 'vec' * 'this'

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::prodVecMatInPlace ( const VectorDouble x,
VectorDouble y,
bool  transpose = false 
) const

Perform 'y' = 'x' * 'this'

void AMatrix::prodVecMatInPlacePtr ( const double *  x,
double *  y,
bool  transpose = false 
) const
double AMatrix::quadraticMatrix ( const VectorDouble x,
const VectorDouble y 
)

Perform x %*% mat %*% y

void AMatrix::reset ( int  nrows,
int  ncols,
double  value = 0.,
int  opt_eigen = -1 
)
void AMatrix::resetFromArray ( int  nrows,
int  ncols,
const double *  tab,
bool  byCol = true,
int  opt_eigen = -1 
)
void AMatrix::resetFromVD ( int  nrows,
int  ncols,
const VectorDouble tab,
bool  byCol = true,
int  opt_eigen = -1 
)
void AMatrix::resetFromVVD ( const VectorVectorDouble tab,
bool  byCol = true,
int  opt_eigen = -1 
)
void AMatrix::resize ( int  nrows,
int  ncols 
)

Modify the dimension of the matrix

void AMatrix::setColumn ( int  icol,
const VectorDouble tab 
)
virtual

Set the contents of a Column

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::setDiagonal ( const VectorDouble tab)
virtual

Set the contents of the (main) Diagonal

Reset the contents of a matrix by setting all terms to 0 and update diagonal terms from the input argument 'tab'

Parameters
tabInput vector to be copied to the diagonal of the output matrix

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::setDiagonalToConstant ( double  value = 1.)
virtual

Set the contents of the (main) Diagonal to a constant value

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::setFlagCheckAddress ( bool  flagCheckAddress)
inline
void AMatrix::setIdentity ( double  value = 1.)

Sets the matrix as Identity

void AMatrix::setRow ( int  irow,
const VectorDouble tab 
)
virtual

Set the contents of a Row

Reimplemented in MatrixSparse, and AMatrixDense.

void AMatrix::setValue ( int  irow,
int  icol,
double  value 
)

Sets the value at row 'irow' and column 'icol'

void AMatrix::setValue_ ( int  irow,
int  icol,
double  value 
)

Sets the value at row 'irow' and column 'icol' (no test performed)

Sets the value at row 'irow' and column 'icol' (no test)

void AMatrix::setValues ( const VectorDouble values,
bool  byCol = true 
)

Filling the matrix with an array of values Note that this array is ALWAYS dimensioned to the total number of elements in the matrix. Kept for compatibility with old code where matrix contents was stored as a VectorDouble

Parameters
values
byColtrue for Column major; false for Row Major
int AMatrix::size ( ) const
inline

Get the total number of elements of the (full) matrix

int AMatrix::solve ( const VectorDouble b,
VectorDouble x 
) const

Solving the Matrix Linear system

String AMatrix::toString ( const AStringFormat strfmt = nullptr) const
overridevirtual

Interface to AStringable.

Reimplemented from AStringable.

Reimplemented in MatrixSparse, ProjMatrix, and Table.

AMatrix * AMatrix::transpose ( ) const
virtual

Transpose the matrix and return it as a copy

Reimplemented in MatrixSparse.

void AMatrix::transposeInPlace ( )
virtual

Transpose the matrix in place


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