#include <MatrixSparse.hpp>
Sparse Matrix
Handle a sparse matrix that can be symmetrical, square or not. Storage relies on Eigen3 Library. Storage relies on Eigen3 Library.
Public Member Functions | |
| MatrixSparse (Id nrow=0, Id ncol=0, Id ncolmax=-1) | |
| MatrixSparse (const MatrixSparse &m) | |
| MatrixSparse & | operator= (const MatrixSparse &m) |
| virtual | ~MatrixSparse () |
| String | toString (const AStringFormat *strfmt=nullptr) const override |
| Cloneable interface. | |
| Id | getSize () const override |
| Interface for ALinearOp. | |
| bool | isSparse () const override |
| Interface for AMatrix. | |
| bool | isDense () const override |
| double | getValue (Id row, Id col) const override |
| void | setValue (Id irow, Id icol, double value) override |
| void | updValue (Id irow, Id icol, const EOperator &oper, double value) override |
| void | setColumn (Id icol, const 1 &tab) override |
| void | setColumnToConstant (Id icol, double value) override |
| void | setRow (Id irow, const 1 &tab) override |
| void | setRowToConstant (Id irow, double value) override |
| void | setDiagonal (const 1 &tab) override |
| void | setDiagonalToConstant (double value=1.) override |
| void | addScalar (double v) override |
| void | addScalarDiag (double v) override |
| void | prodScalar (double v) override |
| void | fill (double value) override |
| void | multiplyRow (const 1 &vec) override |
| void | multiplyColumn (const 1 &vec) override |
| void | divideRow (const 1 &vec) override |
| void | divideColumn (const 1 &vec) override |
| void | resetFromValue (Id nrows, Id ncols, double value) override |
| Reset the matrix to new dimensions and fill with a new value. | |
| void | resetFromArray (Id nrows, Id ncols, const double *tab, bool byCol=true) override |
| Reset the matrix from an array of double values. | |
| void | resetFromVD (Id nrows, Id ncols, const 1 &tab, bool byCol=true) override |
| Reset the matrix from a vector of double values. | |
| void | resetFromVVD (const 1 &tab, bool byCol=true) override |
| Reset the matrix from an array of double values. | |
| MatrixSparse * | transpose () const override |
| void | prodMatMatInPlace (const AMatrix *x, const AMatrix *y, bool transposeX=false, bool transposeY=false) override |
| void | prodNormMatMatInPlace (const AMatrix *a, const AMatrix *m, bool transpose=false) override |
| void | prodNormMatVecInPlace (const AMatrix *a, const 1 &vec, bool transpose=false) override |
| void | prodNormMatInPlace (const AMatrix *a, bool transpose=false) override |
| void | linearCombination (double val1, const AMatrix *mat1, double val2=1., const AMatrix *mat2=nullptr, double val3=1., const AMatrix *mat3=nullptr) override |
| void | addMat (const AMatrix &y, double cx=1., double cy=1.) override |
| NF_Triplet | getMatrixToTriplet (Id shiftRow=0, Id shiftCol=0) const override |
| MatrixSparse * | getRowAsMatrixSparse (Id irow, double coeff=1.) const |
| MatrixSparse * | getColumnAsMatrixSparse (Id icol, double coeff=1.) const |
| Id | addVecInPlaceEigen (const Eigen::Map< const Eigen::VectorXd > &xm, Eigen::Map< Eigen::VectorXd > &ym) const |
| void | resetFromTriplet (const NF_Triplet &NF_T) |
| void | fillRandom (Id seed=432432, double zeroPercent=0) |
| Id | addVecInPlace (const constvect x, vect y) const |
| void | addValue (Id row, Id col, double value) |
| double | L1Norm () const |
| void | getStats (Id *nrows, Id *ncols, Id *count, double *percent) const |
| Id | scaleByDiag () |
| Id | addVecInPlaceVD (const 1 &x, 1 &y) const |
| void | setConstant (double value) |
| extractDiag (Id oper_choice=1) const | |
| void | prodNormDiagVecInPlace (const 1 &vec, Id oper=1) |
| MatrixSparse * | extractSubmatrixByRanks (const 1 &rank_rows, const 1 &rank_cols) const |
| MatrixSparse * | extractSubmatrixByColor (const 1 &colors, Id ref_color, bool row_ok, bool col_ok) |
| colorCoding () const | |
| Id | getNonZeros () const |
| void | gibbs (Id iech, const 1 &zcur, double *yk, double *sk) |
| Id | forwardLU (const 1 &b, 1 &x, bool flagLower=true) const |
| void | forceDimension (Id maxRows, Id maxCols) |
| void | setDiagonal (const Eigen::Map< const Eigen::VectorXd > &tab) |
| void | setDiagonal (const constvect tab) |
| const Eigen::SparseMatrix< double > & | eigenMat () const |
| Eigen::SparseMatrix< double > & | eigenMat () |
Public Member Functions inherited from gstlrn::AMatrix | |
| AMatrix (Id nrow=0, Id ncol=0) | |
| AMatrix (const AMatrix &m) | |
| AMatrix & | operator= (const AMatrix &m) |
| virtual | ~AMatrix () |
| virtual bool | isSquare (bool printWhyNot=false) const |
| virtual bool | isSymmetric (double eps=EPSILON10, bool printWhyNot=false) const |
| virtual bool | mustBeSymmetric () const |
| virtual void | reset (Id nrows, Id ncols) |
| virtual void | transposeInPlace () |
| virtual | getRow (Id irow) const |
| virtual | getColumn (Id icol) const |
| void | clear () |
| void | resize (Id nrows, Id ncols) |
| Resize the matrix to new dimensions (this method doesn't change the storage type) | |
| bool | isValid (Id irow, Id icol, bool printWhyNot=false) const |
| bool | isIdentity (bool printWhyNot=false) const |
| void | addValue (Id irow, Id 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 |
| Id | getNRows () const |
| Id | getNCols () const |
| Id | size () const |
| getValues (bool byCol=true) const | |
| const & | getDiagonal (Id shift=0) const |
| bool | isColumnDefined (Id icol) const |
| bool | isRowDefined (Id irow) const |
| Id | getNColDefined () const |
| Id | getNRowDefined () const |
| getColumnByRowRange (Id icol, Id rowFrom, Id rowTo) const | |
| bool | isNonNegative (bool verbose=false) const |
| prodMatVec (const 1 &x, bool transpose=false) const | |
| void | prodMatVecInPlace (const 1 &x, 1 &y, bool transpose=false) const |
| void | prodMatVecInPlaceC (const constvect x, vect y, bool transpose=false) const |
| void | addProdMatVecInPlaceC (const constvect x, vect y, bool transpose=false) const |
| prodVecMat (const 1 &x, bool transpose=false) const | |
| void | prodVecMatInPlace (const 1 &x, 1 &y, bool transpose=false) const |
| void | prodVecMatInPlaceC (const constvect x, vect y, bool transpose=false) const |
| void | addProdVecMatInPlaceC (const constvect x, vect y, bool transpose=false) const |
| double | prodVecMatVec (const 1 &x, const 1 &y) const |
| void | prodMat (const AMatrix *matY, bool transposeY=false) |
| Id | invert () |
| Id | solve (const 1 &b, 1 &x) const |
| void | dumpElements (const String &title, Id ifrom, Id ito) const |
| void | dumpStatistics (const String &title) const |
| void | setIdentity (double value=1.) |
| void | fillRandom (Id seed=432432, double zeroPercent=0) |
| void | setValues (const 1 &values, bool byCol=true) |
| double | getMeanByColumn (Id icol) const |
| double | getMinimum () const |
| double | getMaximum () const |
| double | getNormInf () const |
| void | copyReduce (const AMatrix *x, const 1 &validRows, const 1 &validCols) |
| void | copyElements (const AMatrix &m, double factor=1.) |
| void | makePositiveColumn () |
| void | dumpRange (const char *title) |
| double | operator() (Id row, Id col) const |
| double & | operator() (Id row, Id col) |
Public Member Functions inherited from gstlrn::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 (Id level) const final |
Public Member Functions inherited from gstlrn::ICloneable | |
| ICloneable () | |
| virtual | ~ICloneable () |
| virtual ICloneable * | clone () const =0 |
| std::shared_ptr< ICloneable > | cloneShared () const |
| std::unique_ptr< ICloneable > | cloneUnique () const |
Public Member Functions inherited from gstlrn::ALinearOp | |
| ALinearOp () | |
| ALinearOp (const ALinearOp &m)=delete | |
| ALinearOp & | operator= (const ALinearOp &m)=delete |
| virtual | ~ALinearOp () |
| Id | evalDirect (const 1 &inv, 1 &outv) const |
| evalDirect (const 1 &in) const | |
| virtual void | multiplyByValueAndAddDiagonal (double v1=1., double v2=0.) const |
| virtual void | resetModif () const |
| void | setUseFactor (bool usefactor) |
| Id | evalDirect (constvect inv, vect outv) const |
| Id | addToDest (const constvect inv, vect outv) const |
| Id | addToDest (const ::Eigen::VectorXd &inv, ::Eigen::VectorXd &outv) const |
Static Public Member Functions | |
| static MatrixSparse * | create (const MatrixSparse *mat) |
| static MatrixSparse * | create (Id nrow, Id ncol) |
| static MatrixSparse * | createFromTriplet (const NF_Triplet &NF_T, Id nrow=0, Id ncol=0, Id nrowmax=-1) |
| static MatrixSparse * | Identity (Id nrow, double value=1.) |
| static MatrixSparse * | addMatMat (const MatrixSparse *x, const MatrixSparse *y, double cx=1., double cy=1.) |
| static MatrixSparse * | diagVec (const 1 &vec) |
| static MatrixSparse * | diagConstant (Id number, double value=1.) |
| static MatrixSparse * | diagMat (MatrixSparse *A, Id oper_choice) |
| static MatrixSparse * | glue (const MatrixSparse *A1, const MatrixSparse *A2, bool flagShiftRow, bool flagShiftCol) |
| static void | glueInPlace (MatrixSparse *A1, const MatrixSparse *A2, bool flagShiftRow, bool flagShiftCol) |
| static void | dumpElements (const String &title, Id ifrom, Id ito) |
Public Attributes | |
| DECLARE_TOTL | |
| Has a specific implementation in the Target language. | |
| gstlrn::MatrixSparse::MatrixSparse | ( | const MatrixSparse & | m | ) |
|
virtual |
|
overridevirtual |
Add a matrix (multiplied by a constant)
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 |
Reimplemented from gstlrn::AMatrix.
|
static |
|
overridevirtual |
Add a value to each matrix component
| v | Add a scalar value to all terms of the current matrix |
Implements gstlrn::AMatrix.
|
overridevirtual |
Add value to matrix diagonal
| v | Add constant value to the diagonal of the current Matrix |
Implements gstlrn::AMatrix.
| Id gstlrn::MatrixSparse::addVecInPlaceEigen | ( | const Eigen::Map< const Eigen::VectorXd > & | xm, |
| Eigen::Map< Eigen::VectorXd > & | ym | ||
| ) | const |
| Id gstlrn::MatrixSparse::addVecInPlaceVD | ( | const 1 & | x, |
| 1 & | y | ||
| ) | const |
| gstlrn::MatrixSparse::colorCoding | ( | ) | const |
|
static |
|
static |
|
static |
|
static |
|
static |
Construct a sparse matrix with the diagonal of 'A', where each element is transformed
| A | Input sparse matrix |
| oper_choice | Operation on the diagonal term (see Utilities::operate_XXX) |
|
static |
|
overridevirtual |
|
overridevirtual |
Dump a specific range of samples from the internal storage
|
inline |
|
inline |
| gstlrn::MatrixSparse::extractDiag | ( | Id | oper_choice = 1 | ) | const |
| MatrixSparse * gstlrn::MatrixSparse::extractSubmatrixByColor | ( | const 1 & | colors, |
| Id | ref_color, | ||
| bool | row_ok, | ||
| bool | col_ok | ||
| ) |
| MatrixSparse * gstlrn::MatrixSparse::extractSubmatrixByRanks | ( | const 1 & | rank_rows, |
| const 1 & | rank_cols | ||
| ) | const |
|
overridevirtual |
Set all the values of the matrix at once
| value | Constant value used for filling 'this' |
Implements gstlrn::AMatrix.
| void gstlrn::MatrixSparse::fillRandom | ( | Id | seed = 432432, |
| double | zeroPercent = 0 |
||
| ) |
Set all the values of the Matrix with random values
| Id gstlrn::MatrixSparse::forwardLU | ( | const 1 & | b, |
| 1 & | x, | ||
| bool | flagLower = true |
||
| ) | const |
| MatrixSparse * gstlrn::MatrixSparse::getColumnAsMatrixSparse | ( | Id | icol, |
| double | coeff = 1. |
||
| ) | const |
Extract a Column
|
overridevirtual |
Extract the contents of the matrix
From a matrix of any type, creates the triplet (specific format for creating efficiently a Sparse matrix) It only takes the only non-zero elements of the matrix
Reimplemented from gstlrn::AMatrix.
|
inline |
| MatrixSparse * gstlrn::MatrixSparse::getRowAsMatrixSparse | ( | Id | irow, |
| double | coeff = 1. |
||
| ) | const |
Extract a Row
|
inlineoverridevirtual |
Interface for ALinearOp.
Implements gstlrn::ALinearOp.
Get the value from a matrix cell
Implements gstlrn::AMatrix.
| void gstlrn::MatrixSparse::gibbs | ( | Id | iech, |
| const 1 & | zcur, | ||
| double * | yk, | ||
| double * | sk | ||
| ) |
|
static |
|
static |
|
static |
|
inlineoverridevirtual |
Returns if the matrix belongs to the MatrixSparse class (avoids dynamic_cast)
Implements gstlrn::AMatrix.
|
inlineoverridevirtual |
| double gstlrn::MatrixSparse::L1Norm | ( | ) | const |
|
overridevirtual |
Perform 'this' = 'val1' * 'mat1' + 'val2' * 'mat2' + 'val3' * 'mat3'
Reimplemented from gstlrn::AMatrix.
|
overridevirtual |
|
overridevirtual |
| MatrixSparse & gstlrn::MatrixSparse::operator= | ( | const MatrixSparse & | m | ) |
|
overridevirtual |
Multiply matrix 'x' by matrix 'y' and store the result in 'this'
Store the product of 'x' by 'y' in this
| x | First Matrix |
| y | Second matrix |
| transposeX | True if First matrix is transposed |
| transposeY | True if Second matrix is transposed |
Reimplemented from gstlrn::AMatrix.
| void gstlrn::MatrixSparse::prodNormDiagVecInPlace | ( | const 1 & | vec, |
| Id | oper_choice = 1 |
||
| ) |
Perform: 'this' = diag('vec') %*% 'A' %*% diag('vec')
| vec | Input Vector |
| oper_choice | Type of transformation |
|
overridevirtual |
Perform 'this' = 't(A)' %*% 'A' or 'A' %*% 't(A)'
Reimplemented from gstlrn::AMatrix.
|
overridevirtual |
Perform 'this' = 't(A)' %*% 'M' %*% 'A' or 'A' %*% 'M' %*% 't(A)'
Reimplemented from gstlrn::AMatrix.
|
overridevirtual |
Perform 'this' = 't(A)' %*% ['vec'] %*% 'A' or 'A' %*% ['vec'] %*% 't(A)'
Reimplemented from gstlrn::AMatrix.
|
overridevirtual |
Multiply each matrix component by a value
| v | Multiply all the terms of the matrix by the scalar 'v' |
Implements gstlrn::AMatrix.
|
overridevirtual |
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 from gstlrn::AMatrix.
| void gstlrn::MatrixSparse::resetFromTriplet | ( | const NF_Triplet & | NF_T | ) |
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 from gstlrn::AMatrix.
|
overridevirtual |
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 from gstlrn::AMatrix.
|
overridevirtual |
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 from gstlrn::AMatrix.
| Id gstlrn::MatrixSparse::scaleByDiag | ( | ) |
|
overridevirtual |
Set the contents of a Column
Fill a column of an already existing Sparse matrix, using 'tab' as entry The input 'tab' corresponds to the whole column contents
| icol | Column rank |
| tab | Vector containing the information (Dimension: nrows) |
Implements gstlrn::AMatrix.
|
overridevirtual |
Set the contents of a Column to a constant
Implements gstlrn::AMatrix.
| void gstlrn::MatrixSparse::setConstant | ( | double | value | ) |
|
overridevirtual |
Set the contents of the (main) Diagonal
Implements gstlrn::AMatrix.
| void gstlrn::MatrixSparse::setDiagonal | ( | const constvect | tab | ) |
| void gstlrn::MatrixSparse::setDiagonal | ( | const Eigen::Map< const Eigen::VectorXd > & | tab | ) |
|
overridevirtual |
Set the contents of the (main) Diagonal to a constant value
Implements gstlrn::AMatrix.
|
overridevirtual |
Set the contents of a Row
Fill a row of an already existing Sparse matrix, using 'tab' as entry The input 'tab' corresponds to the whole row contents
| irow | Row rank |
| tab | Vector containing the information (Dimension: ncols) |
Implements gstlrn::AMatrix.
|
overridevirtual |
Set the contents of a Row to a constant
Implements gstlrn::AMatrix.
Set the value for a matrix cell
Implements gstlrn::AMatrix.
|
overridevirtual |
|
overridevirtual |
Transpose the matrix and return it as a copy
Reimplemented from gstlrn::AMatrix.
|
overridevirtual |
Modifies the contents of a matrix cell
Implements gstlrn::AMatrix.
| gstlrn::MatrixSparse::DECLARE_TOTL |
Has a specific implementation in the Target language.