#include <AMatrix.hpp>
Public Member Functions | |
AMatrix (int nrow=0, int ncol=0, int opt_eigen=-1) | |
AMatrix (const AMatrix &m) | |
AMatrix & | operator= (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 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) |
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) | |
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 |
Matrix
AMatrix::AMatrix | ( | int | nrow = 0 , |
int | ncol = 0 , |
||
int | opt_eigen = -1 |
||
) |
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
|
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.
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)
|
inlinevirtual |
Returns if the matrix belongs to the AMatrixDense class (avoids dynamic_cast)
Reimplemented in AMatrixDense.
|
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 Matrix is built using Eigen Library or not
|
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
[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)
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 |
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 diagonal constant
Reimplemented in MatrixSquareSymmetric, MatrixRectangular, and MatrixSquareGeneral.
|
inlinevirtual |
Say if the matrix must be diagonal
Reimplemented in MatrixSquareSymmetric, MatrixRectangular, and MatrixSquareGeneral.
|
inlinevirtual |
Say if the matrix must be symmetric
Reimplemented in MatrixSquareSymmetric, MatrixRectangular, and MatrixSquareGeneral.
|
inline |
Get value operator override
|
inline |
Set 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
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
|
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.
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
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 MatrixSparse, ProjMatrix, and Table.
|
virtual |
Transpose the matrix and return it as a copy
Reimplemented in MatrixSparse.
|
virtual |
Transpose the matrix in place