#include <AMatrix.hpp>
This class is the root of the Matrix organization in gstlearn A matrix is a 2-D organization: it is characterized by its number of rows and its number of columns. Although the user should not bother with this remark, the elements of a matrix processed in 'gstlearn' are stored in a Row-major format. This is to say that the internal rank of an element characterized by its row and column numbers is: (icol * getNRows() + irow)
Since gstlearn version v1.3:
Public Member Functions | |
AMatrix (int nrow=0, int ncol=0) | |
AMatrix (const AMatrix &m) | |
AMatrix & | operator= (const AMatrix &m) |
virtual | ~AMatrix () |
virtual void | reset (int nrows, int ncols) |
virtual void | resetFromValue (int nrows, int ncols, double value) |
Reset the matrix to new dimensions and fill with a new value. More... | |
virtual void | resetFromArray (int nrows, int ncols, const double *tab, bool byCol=true) |
Reset the matrix from an array of double values. More... | |
virtual void | resetFromVD (int nrows, int ncols, const VectorDouble &tab, bool byCol=true) |
Reset the matrix from a vector of double values. More... | |
virtual void | resetFromVVD (const VectorVectorDouble &tab, bool byCol=true) |
Reset the matrix from an array of double values. More... | |
virtual String | toString (const AStringFormat *strfmt=nullptr) const override |
Interface to AStringable. More... | |
virtual bool | isDense () const =0 |
Interface to AMatrix. More... | |
virtual bool | isSparse () const =0 |
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, double eps=EPSILON10) const |
virtual bool | mustBeSymmetric () 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 AMatrix * | transpose () 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) |
Resize the matrix to new dimensions (this method doesn't change the storage type) More... | |
virtual double | getValue (int irow, int icol, bool flagCheck=true) const =0 |
virtual void | setValue (int irow, int icol, double value, bool flagCheck=true)=0 |
virtual void | updValue (int irow, int icol, const EOperator &oper, double value, bool flagCheck=true)=0 |
void | addValue (int irow, int icol, double value) |
bool | isSame (const AMatrix &m, double eps=EPSILON4, bool printWhyNot=false) |
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 | isNonNegative (bool verbose=false) |
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 |
double | getNormInf () const |
void | copyReduce (const AMatrix *x, const VectorInt &activeRows, const VectorInt &activeCols) |
void | copyElements (const AMatrix &m, double factor=1.) |
void | setFlagCheckAddress (bool flagCheckAddress) |
void | makePositiveColumn () |
void | linearCombination (double val1, const AMatrix *mat1, double val2=1., const AMatrix *mat2=nullptr) |
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 |
AMatrix::AMatrix | ( | int | nrow = 0 , |
int | ncol = 0 |
||
) |
AMatrix::AMatrix | ( | const AMatrix & | m | ) |
|
virtual |
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
y | Matrix to be added |
cx | Multiplicative parameter for this |
cy | Multiplicative parameter for y |
|
virtual |
Add a value to each matrix component
v | Add a scalar value to all (valid) terms of the current matrix |
Reimplemented in MatrixSparse, and AMatrixDense.
|
virtual |
Add value to matrix diagonal
v | Add 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)
m | Input matrix |
factor | Multiplicative factor (applied to each element) |
void AMatrix::copyReduce | ( | const AMatrix * | x, |
const VectorInt & | activeRows, | ||
const VectorInt & | activeCols | ||
) |
|
virtual |
Divide a Matrix column-wise
Reimplemented in MatrixSparse, and AMatrixDense.
|
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
|
inline |
Returns if the current matrix is Empty
|
virtual |
Set all the values of the Matrix at once
Fill 'this' with the constant 'value'
value | Constant value used for filling 'this' |
Reimplemented in MatrixSparse, and AMatrixDense.
void AMatrix::fillRandom | ( | int | seed = 432432 , |
double | zeroPercent = 0.1 |
||
) |
|
virtual |
Extract a Column
Reimplemented in AMatrixDense.
VectorDouble AMatrix::getDiagonal | ( | int | shift = 0 | ) | const |
Extract a Diagonal (main or secondary) of this
|
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 |
|
inline |
Returns the number of columns
double AMatrix::getNormInf | ( | ) | 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
|
virtual |
Extract a Row
Reimplemented in AMatrixDense.
|
pure virtual |
Gets the value at row 'irow' and column 'icol'
Implemented in MatrixSparse, and AMatrixDense.
VectorDouble AMatrix::getValues | ( | bool | byCol = true | ) | const |
Returns the contents of the whole matrix as a VectorDouble
int AMatrix::invert | ( | ) |
Matrix inversion in place
bool AMatrix::isColumnDefined | ( | int | icol | ) | const |
Checks if a Column is valid (contains a non TEST value)
|
pure virtual |
Interface to AMatrix.
Returns if the matrix belongs to the AMatrixDense class (avoids dynamic_cast)
Implemented in MatrixSparse, and AMatrixDense.
|
virtual |
bool AMatrix::isNonNegative | ( | bool | verbose = false | ) |
Check if the matrix does not contain any negative element
Check if all the elements of a matrix are non-negative
[in] | verbose | True for the verbose option |
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)
Check that Matrix 'm' is equal to the current Matrix
m | Matrix to be compared to the current Matrix |
eps | Epsilon for double equality comparison |
printWhyNot | Print the message is the answer is false |
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 |
|
pure virtual |
Returns if the current matrix is Sparse
Implemented in MatrixSparse, and AMatrixDense.
|
virtual |
Check if the matrix is (non empty) square
Indicate if the given matrce is a square matrix
printWhyNot | Print the message is the answer is false |
Reimplemented in AMatrixSquare.
|
virtual |
Check if the input matrix is (non empty and square) symmetric
Indicate if the current matrix is symmetric
printWhyNot | Print the message is the answer is false |
eps | Epsilon for double equality comparison |
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 is false |
void AMatrix::linearCombination | ( | double | val1, |
const AMatrix * | mat1, | ||
double | val2 = 1. , |
||
const AMatrix * | mat2 = nullptr |
||
) |
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
|
virtual |
Multiply a Matrix column-wise
Reimplemented in MatrixSparse, and AMatrixDense.
|
virtual |
Multiply a Matrix row-wise
Reimplemented in MatrixSparse, and AMatrixDense.
|
inlinevirtual |
Say if the matrix must be symmetric
Reimplemented in MatrixSquareGeneral, MatrixRectangular, and MatrixSquareSymmetric.
|
inline |
Set value operator override
|
inline |
Get value operator override
void AMatrix::prodMatInPlace | ( | const AMatrix * | matY, |
bool | transposeY = false |
||
) |
Multiply 'this' by matrix 'y' and store in 'this'
|
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
x | First Matrix |
y | Second matrix |
transposeX | True if first matrix must be transposed |
transposeY | True if second matrix must be transposed |
Reimplemented in MatrixSparse, and AMatrixDense.
|
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'
x | Input vector |
y | Output vector obtained by multiplying 'inv' by current Matrix |
transpose | True 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'
a | Matrix A |
m | Matrix M |
transpose | True for first implementation, False for the second |
|
virtual |
Multiply each matrix component by a value
v | Multiply all the terms of the matrix by the scalar 'v' |
Reimplemented in MatrixSparse, and AMatrixDense.
|
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
|
virtual |
Reimplemented in Table.
|
virtual |
Reset the matrix from an array of double values.
nrows | New number of rows |
ncols | New number of columns |
tab | The array of values |
byCol | True if values are column-major in the array |
Reimplemented in MatrixSparse.
|
virtual |
Reset the matrix to new dimensions and fill with a new value.
nrows | New number of rows |
ncols | New number of columns |
value | The new value used to fill the matrix |
Reimplemented in MatrixSparse.
|
virtual |
Reset the matrix from a vector of double values.
nrows | New number of rows |
ncols | New number of columns |
tab | The vector of values |
byCol | True if values are column-major in the vector |
Reimplemented in MatrixSparse.
|
virtual |
Reset the matrix from an array of double values.
tab | The array of values |
byCol | True if values are column-major in the array |
Reimplemented in MatrixSparse.
void AMatrix::resize | ( | int | nrows, |
int | ncols | ||
) |
Resize the matrix to new dimensions (this method doesn't change the storage type)
Modify the dimension of the matrix (if needed)
nrows | New number of rows |
ncols | New number of columns |
|
virtual |
Set the contents of a Column
Reimplemented in MatrixSparse, and AMatrixDense.
|
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'
tab | Input vector to be copied to the diagonal of the output matrix |
Reimplemented in MatrixSparse, and AMatrixDense.
|
virtual |
Set the contents of the (main) Diagonal to a constant value
Reimplemented in MatrixSparse, and AMatrixDense.
|
inline |
void AMatrix::setIdentity | ( | double | value = 1. | ) |
Sets the matrix as Identity
|
virtual |
Set the contents of a Row
Reimplemented in MatrixSparse, and AMatrixDense.
|
pure virtual |
Sets the value at row 'irow' and column 'icol'
Implemented in MatrixSparse, and AMatrixDense.
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 |
|
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
|
overridevirtual |
Interface to AStringable.
Reimplemented from AStringable.
Reimplemented in Table, MatrixSparse, and ProjMatrix.
|
virtual |
Transpose the matrix and return it as a copy
Reimplemented in MatrixSparse.
|
virtual |
Transpose the matrix in place
|
pure virtual |
Update the value at row 'irow' and column 'icol'
Implemented in MatrixSparse, and AMatrixDense.