gstlearn
1.0.0
CCC
|
TODO : Transform into template for storing something else than double. More...
#include <AMatrix.hpp>
Public Member Functions | |
virtual | ~AMatrix () |
void | init (int nrows, int ncols) |
void | reset (int nrows, int ncols, double value=0.) |
void | resetFromArray (int nrows, int ncols, const double *tab, bool byCol=true) |
void | resetFromVD (int nrows, int ncols, const VectorDouble &tab, bool byCol=true) |
void | resetFromVVD (const VectorVectorDouble &tab, bool byCol=true) |
virtual void | setColumn (int icol, const VectorDouble &tab) |
virtual void | setRow (int irow, const VectorDouble &tab) |
virtual void | setDiagonal (const VectorDouble &tab) |
virtual void | setDiagonal (double value=1.) |
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 | transposeInPlace () |
virtual AMatrix * | transpose () const |
virtual void | addScalar (double v) |
virtual void | addScalarDiag (double v) |
virtual void | prodScalar (double v) |
virtual String | toString (const AStringFormat *strfmt=nullptr) const override |
virtual double | getValue (int irow, int icol) const |
virtual double & | getValueRef (int irow, int icol) |
virtual void | setValue (int irow, int icol, double value) |
virtual void | setValuesByArrays (const VectorInt &irows, const VectorInt &icols, const VectorDouble &values) |
virtual void | addMatrix (const AMatrix &y) |
virtual void | prodMatrix (const AMatrix &x, const AMatrix &y) |
virtual void | linearCombination (double cx, double cy, const AMatrix &y) |
bool | isSame (const AMatrix &m, double eps=EPSILON10) |
bool | isSameSize (const AMatrix &m) const |
bool | isEmpty () const |
double | compare (const AMatrix &mat) const |
int | getNRows () const |
int | getNCols () const |
int | getNTotal () const |
VectorDouble | getValues (bool byCol=true) const |
VectorDouble | getDiagonal (int shift=0) const |
VectorDouble | getRow (int irow) const |
VectorDouble | getColumn (int icol) const |
bool | isColumnDefined (int icol) const |
bool | isRowDefined (int irow) const |
int | getNumberColumnDefined () const |
int | getNumberRowDefined () const |
void | add (int irow, int icol, double value) |
void | add (const AMatrix &tab, double value=1.) |
void | subtract (const AMatrix &tab, double value=1.) |
void | getValuesAsTriplets (VectorInt &irows, VectorInt &icols, VectorDouble &values) const |
void | prodVector (const double *inv, double *outv) const |
void | prodVector (const VectorDouble &inv, VectorDouble &outv) const |
void | multiplyRow (const VectorDouble &vec) |
void | multiplyColumn (const VectorDouble &vec) |
void | divideRow (const VectorDouble &vec) |
void | divideColumn (const VectorDouble &vec) |
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 | fill (double value) |
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 | setFlagCheckAddress (bool flagCheckAddress) |
double | operator() (int row, int col) const |
double & | operator() (int row, int col) |
Public Member Functions inherited from AStringable | |
AStringable () | |
AStringable (const AStringable &r) | |
AStringable & | operator= (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 ICloneable * | clone () const =0 |
Protected Member Functions | |
AMatrix (int nrow=0, int ncol=0) | |
AMatrix (const AMatrix &m) | |
AMatrix & | operator= (const AMatrix &m) |
virtual bool | _isPhysicallyPresent (int, int) const |
virtual bool | _isCompatible (const AMatrix &m) const =0 |
virtual void | _allocate ()=0 |
virtual void | _deallocate ()=0 |
virtual int | _getMatrixSize () const =0 |
virtual void | _setValue (int rank, double value)=0 |
virtual double | _getValue (int rank) const =0 |
virtual void | _setValue (int irow, int icol, double value)=0 |
virtual void | _setValues (const double *values, bool byCol) |
virtual double | _getValue (int irow, int icol) const =0 |
virtual double & | _getValueRef (int irow, int icol)=0 |
virtual void | _transposeInPlace ()=0 |
virtual void | _prodVector (const double *inv, double *outv) const =0 |
virtual int | _invert ()=0 |
virtual int | _solve (const VectorDouble &b, VectorDouble &x) const =0 |
virtual int | _getIndexToRank (int irow, int icol) const =0 |
virtual void | _clearContents () |
void | _setNCols (int ncols) |
void | _setNRows (int nrows) |
bool | _isNumbersValid (int nrows, int ncols) const |
bool | _isColumnValid (int icol) const |
bool | _isRowValid (int irow) const |
bool | _isIndexValid (int irow, int icol) const |
bool | _isRowVectorConsistent (const VectorDouble &tab) |
bool | _isColVectorConsistent (const VectorDouble &tab) |
bool | _isVectorSizeConsistent (int nrows, int ncols, const VectorDouble &tab) |
bool | _isRankValid (int rank) const |
void | _clear () |
void | _fillFromVVD (const VectorVectorDouble &X) |
bool | _getFlagCheckAddress () const |
Private Attributes | |
int | _nRows |
int | _nCols |
bool | _flagCheckAddress |
TODO : Transform into template for storing something else than double.
Matrix
|
protected |
|
protected |
|
virtual |
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protected |
|
inlineprotectedvirtual |
Reimplemented in Table, and MatrixSparse.
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protected |
Converts a VectorVectorDouble into a Matrix (generic) Note: the input argument is stored by row (if coming from [] specification)
X | Input VectorVectorDouble argument |
|
inlineprotected |
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protectedpure virtual |
Returns the number of elements actually stored as members in subsequent classes
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protectedpure virtual |
Implemented in MatrixSparse, MatrixSquareSymmetric, MatrixSquareGeneral, and MatrixRectangular.
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protected |
|
protected |
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protected |
|
protected |
|
inlineprotectedvirtual |
Say if (irow, icol) is stored physically or not
Reimplemented in MatrixSquareSymmetric, and MatrixSparse.
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
inlineprotected |
|
inlineprotected |
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protectedpure virtual |
Implemented in MatrixSparse, MatrixRectangular, MatrixSquareSymmetric, and MatrixSquareGeneral.
|
protectedvirtual |
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 double* array
values | Input array (Dimension: nrow * ncol) |
byCol | true for Column major; false for Row Major |
Reimplemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixRectangular, and MatrixSparse.
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
|
protectedpure virtual |
Implemented in MatrixSquareSymmetric, MatrixSquareGeneral, MatrixSparse, and MatrixRectangular.
void AMatrix::add | ( | const AMatrix & | tab, |
double | value = 1. |
||
) |
Add a matrix to this
Perform: this += 'value' * 'tab'
tab | Current matrix |
value | Multiplicative coefficient (default = 1) |
void AMatrix::add | ( | int | irow, |
int | icol, | ||
double | value | ||
) |
Add a value to a matrix term
|
virtual |
Add a matrix to this component by component
Add the matrix 'y' to the current Matrix
y | Matrix to be added |
|
virtual |
Add a value to each matrix component
v | Add a scalar value to all (valid) terms of the current matrix |
Reimplemented in MatrixSparse.
|
virtual |
Add value to matrix diagonal
v | Add constant value to the diagonal of the current Matrix |
Reimplemented in MatrixSparse.
double AMatrix::compare | ( | const AMatrix & | mat | ) | const |
Returns the sum of absolute difference between argument and this
void AMatrix::copyReduce | ( | const AMatrix * | x, |
const VectorInt & | activeRows, | ||
const VectorInt & | activeCols | ||
) |
void AMatrix::divideColumn | ( | const VectorDouble & | vec | ) |
Divide a Matrix column-wise
void AMatrix::divideRow | ( | const VectorDouble & | vec | ) |
Divide a Matrix row-wise
void AMatrix::dumpElements | ( | const String & | title, |
int | ifrom, | ||
int | ito | ||
) | const |
Dump a specific range of samples from the internal storage
void AMatrix::fill | ( | double | value | ) |
Set all the values of the Matrix at once
Fill 'this' with the constant 'value'
value | Constant value used for filling 'this' |
void AMatrix::fillRandom | ( | int | seed = 432432 , |
double | zeroPercent = 0.1 |
||
) |
VectorDouble AMatrix::getColumn | ( | int | icol | ) | const |
Extract a Column
VectorDouble AMatrix::getDiagonal | ( | int | shift = 0 | ) | const |
Extract a Diagonal (main or secondary) of this
double AMatrix::getMaximum | ( | ) | const |
double AMatrix::getMeanByColumn | ( | int | icol | ) | const |
double AMatrix::getMinimum | ( | ) | const |
|
inline |
Returns the number of columns
|
inline |
Returns the number of rows
|
inline |
Get the total number of elements of the (full) matrix
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 |
Extract a Row
|
virtual |
Gets the value at row 'irow' and column 'icol'
|
virtual |
Gets a reference to the value at row 'irow' and column 'icol'
VectorDouble AMatrix::getValues | ( | bool | byCol = true | ) | const |
Returns the contents of the whole matrix as a VectorDouble
void AMatrix::getValuesAsTriplets | ( | VectorInt & | irows, |
VectorInt & | icols, | ||
VectorDouble & | values | ||
) | const |
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
irows | Output array of row indices |
icols | Output array of column indices |
values | Output array of non-zero values |
TODO : use cs_sparce corresponding function
void AMatrix::init | ( | int | nrows, |
int | ncols | ||
) |
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 |
Check if the contents of the matrix is constant and diagonal
|
virtual |
Check if the matrix is (non empty) diagonal
|
inline |
Returns if the current matrix is Empty
|
virtual |
Check if the matrix is square and Identity
bool AMatrix::isRowDefined | ( | int | irow | ) | const |
Checks if a Row is valid (contains a non TEST value)
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
m | Matrix to be compared to the current Matrix |
|
inlinevirtual |
Returns if the current matrix is Sparse
Reimplemented in MatrixSparse.
|
virtual |
Check if the matrix is (non empty) square
Reimplemented in MatrixSquareGeneral.
|
virtual |
Check if the input matrix is (non empty and square) symmetric
Reimplemented in MatrixSquareSymmetric.
|
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
irow | Row index |
icol | Column index |
printWhyNot | Print the message is the answer if false |
|
virtual |
Linear combination of matrices
Updates the current Matrix as a linear combination of matrices as follows: this <- cx * this + cy * y
cx | Coefficient applied to the current Matrix |
cy | Coefficient applied to the Matrix 'y' |
y | Second Matrix in the Linear combination |
void AMatrix::multiplyColumn | ( | const VectorDouble & | vec | ) |
Multiply a Matrix column-wise
void AMatrix::multiplyRow | ( | const VectorDouble & | vec | ) |
Multiply a Matrix row-wise
|
inlinevirtual |
Say if the matrix must be diagonal constant
Reimplemented in MatrixSquareSymmetric, MatrixSquareGeneral, and MatrixRectangular.
|
inlinevirtual |
Say if the matrix must be diagonal
Reimplemented in MatrixSquareSymmetric, MatrixSquareGeneral, and MatrixRectangular.
|
inlinevirtual |
Say if the matrix must be symmetric
Reimplemented in MatrixSquareGeneral, MatrixRectangular, and MatrixSquareSymmetric.
|
inline |
Set value operator override
|
inline |
Get value operator override
Multiply a matrix by another and store the result in the current matrix
Store the product of 'x' by 'y' in this
x | First Matrix |
y | Second matrix |
|
virtual |
Multiply each matrix component by a value
v | Multiply all the terms of the matrix by the scalar 'v' |
Reimplemented in MatrixSparse.
void AMatrix::prodVector | ( | const double * | inv, |
double * | outv | ||
) | const |
Product of the Matrix by a vector (on its right)
inv | Input vector |
outv | Output vector obtained by multiplying 'inv' by current Matrix |
void AMatrix::prodVector | ( | const VectorDouble & | inv, |
VectorDouble & | outv | ||
) | const |
double AMatrix::quadraticMatrix | ( | const VectorDouble & | x, |
const VectorDouble & | y | ||
) |
Perform x %*% mat %*% y
void AMatrix::reset | ( | int | nrows, |
int | ncols, | ||
double | value = 0. |
||
) |
void AMatrix::resetFromArray | ( | int | nrows, |
int | ncols, | ||
const double * | tab, | ||
bool | byCol = true |
||
) |
void AMatrix::resetFromVD | ( | int | nrows, |
int | ncols, | ||
const VectorDouble & | tab, | ||
bool | byCol = true |
||
) |
void AMatrix::resetFromVVD | ( | const VectorVectorDouble & | tab, |
bool | byCol = true |
||
) |
|
virtual |
Set the contents of a Column
|
virtual |
Set the contents of the (main) Diagonal
|
virtual |
|
inline |
void AMatrix::setIdentity | ( | double | value = 1. | ) |
Sets the matrix as Identity
|
virtual |
Set the contents of a Row
|
virtual |
Sets the value at row 'irow' and column 'icol'
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
values | |
byCol | true for Column major; false for Row Major |
|
virtual |
Set a set of values simultaneously from an input array
Reimplemented in MatrixSparse.
int AMatrix::solve | ( | const VectorDouble & | b, |
VectorDouble & | x | ||
) | const |
Solving the Matrix Linear system
void AMatrix::subtract | ( | const AMatrix & | tab, |
double | value = 1. |
||
) |
Subtract a matrix to this
|
overridevirtual |
Conversion to a string
Reimplemented from AStringable.
Reimplemented in Table, MatrixSquareSymmetric, and MatrixSparse.
|
virtual |
Transpose the matrix and return it as a copy
Reimplemented in MatrixSparse.
|
virtual |
Transpose the matrix in place
|
private |
|
private |
|
private |