Dynamical system model
|
The SparseMatrix class represents a sparse matrix. More...
#include <SparseMatrix.hpp>
Public Member Functions | |
SparseMatrix (Id rows, Id cols) | |
SparseMatrix constructor. | |
SparseMatrix (Id index) | |
SparseMatrix constructor - colum. | |
void | insert (Id i, Id j, T value) |
insert a value in the matrix | |
void | insert (Id i, T value) |
insert a value in the matrix | |
void | insert_or_assign (Id i, Id j, T value) |
insert a value in the matrix. If the element already exist, it overwrites it | |
void | insert_or_assign (Id index, T value) |
insert a value in the matrix. If the element already exist, it overwrites it | |
void | insert_and_expand (Id i, Id j, T value) |
insert a value in the matrix and expand the matrix if necessary. | |
void | erase (Id i, Id j) |
remove a value from the matrix | |
void | erase (Id index) |
remove a value from the matrix | |
void | eraseRow (Id index) |
remove a row from the matrix | |
void | eraseColumn (Id index) |
remove a column from the matrix | |
void | emptyRow (Id index) |
set to 0 all the elements in a row | |
void | emptyColumn (Id index) |
set to 0 all the elements in a column | |
void | clear () |
empty the matrix and set the dimensions to zero | |
bool | contains (Id i, Id j) const |
check if the element is non zero | |
bool | contains (Id const index) const |
check if the element is non zero | |
SparseMatrix< int > | getDegreeVector () const |
get the input degree of all nodes | |
SparseMatrix< double > | getStrengthVector () const |
get the strength of all nodes | |
SparseMatrix< int > | getLaplacian () const |
get the laplacian matrix | |
SparseMatrix | getRow (Id index, bool keepId=false) const |
get a row as a row vector | |
SparseMatrix | getCol (Id index, bool keepId=false) const |
get a column as a column vector | |
SparseMatrix< double > | getNormRows () const |
get a matrix of double with every row normalized to 1 | |
SparseMatrix< double > | getNormCols () const |
get a matrix of double with every column normalized to 1 | |
Id | getRowDim () const |
get the number of rows | |
Id | getColDim () const |
get the number of columns | |
Id | size () const |
get the number of non zero elements in the matrix | |
Id | max_size () const |
get the maximum number of elements in the matrix | |
void | symmetrize () |
symmetrize the matrix | |
void | reshape (Id rows, Id cols) |
reshape the matrix | |
void | reshape (Id dim) |
reshape the matrix | |
std::unordered_map< Id, T >::const_iterator | begin () const |
return the begin iterator of the matrix | |
std::unordered_map< Id, T >::const_iterator | end () const |
return the end iterator of the matrix | |
const T & | operator() (Id i, Id j) const |
access an element of the matrix | |
T & | operator() (Id i, Id j) |
access an element of the matrix | |
const T & | operator() (Id index) const |
access an element of the matrix | |
T & | operator() (Id index) |
access an element of the matrix | |
template<typename U > | |
SparseMatrix< T > | operator+ (const SparseMatrix< U > &other) |
sum of two matrices | |
template<typename U > | |
SparseMatrix< T > | operator- (const SparseMatrix< U > &other) |
difference of two matrices | |
SparseMatrix | operator++ () |
transpose the matrix | |
template<typename U > | |
SparseMatrix & | operator+= (const SparseMatrix< U > &other) |
sum of two matrices | |
template<typename U > | |
SparseMatrix & | operator-= (const SparseMatrix< U > &other) |
difference of two matrices | |
template<typename U > | |
SparseMatrix< T > & | operator+= (const SparseMatrix< U > &other) |
template<typename U > | |
SparseMatrix< T > & | operator-= (const SparseMatrix< U > &other) |
The SparseMatrix class represents a sparse matrix.
Id | The type of the matrix's index. It must be an unsigned integral type. |
T | The type of the matrix's value. |
dsm::SparseMatrix< T >::SparseMatrix | ( | Id | rows, |
Id | cols ) |
SparseMatrix constructor.
rows | number of rows |
cols | number of columns |
std::invalid_argument | if rows or cols are < 0 |
|
explicit |
SparseMatrix constructor - colum.
index | number of rows |
std::invalid_argument | if index is < 0 |
|
inline |
return the begin iterator of the matrix
bool dsm::SparseMatrix< T >::contains | ( | Id const | index | ) | const |
check if the element is non zero
index | index in vectorial form |
std::out_of_range | if the index is out of range |
bool dsm::SparseMatrix< T >::contains | ( | Id | i, |
Id | j ) const |
check if the element is non zero
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
|
inline |
return the end iterator of the matrix
void dsm::SparseMatrix< T >::erase | ( | Id | i, |
Id | j ) |
remove a value from the matrix
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
std::runtime_error | if the element is not found |
void dsm::SparseMatrix< T >::erase | ( | Id | index | ) |
remove a value from the matrix
index | index in vectorial form |
std::out_of_range | if the index is out of range |
std::runtime_error | if the element is not found |
void dsm::SparseMatrix< T >::eraseColumn | ( | Id | index | ) |
remove a column from the matrix
index | column index |
std::out_of_range | if the index is out of range |
void dsm::SparseMatrix< T >::eraseRow | ( | Id | index | ) |
remove a row from the matrix
index | row index |
std::out_of_range | if the index is out of range |
SparseMatrix< T > dsm::SparseMatrix< T >::getCol | ( | Id | index, |
bool | keepId = false ) const |
get a column as a column vector
index | column index |
keepId | if true, the index of the elements in the column will be the same as the index of the elements in the matrix |
std::out_of_range | if the index is out of range |
|
inline |
get the number of columns
SparseMatrix< int > dsm::SparseMatrix< T >::getDegreeVector | ( | ) | const |
get the input degree of all nodes
std::runtime_error | if the matrix is not square |
SparseMatrix< int > dsm::SparseMatrix< T >::getLaplacian | ( | ) | const |
get the laplacian matrix
std::runtime_error | if the matrix is not square |
SparseMatrix< double > dsm::SparseMatrix< T >::getNormCols | ( | ) | const |
get a matrix of double with every column normalized to 1
SparseMatrix< double > dsm::SparseMatrix< T >::getNormRows | ( | ) | const |
get a matrix of double with every row normalized to 1
SparseMatrix< T > dsm::SparseMatrix< T >::getRow | ( | Id | index, |
bool | keepId = false ) const |
get a row as a row vector
index | row index |
keepId | if true, the index of the elements in the row will be the same as the index of the elements in the matrix |
std::out_of_range | if the index is out of range |
|
inline |
get the number of rows
SparseMatrix< double > dsm::SparseMatrix< T >::getStrengthVector | ( | ) | const |
get the strength of all nodes
std::runtime_error | if the matrix is not square |
void dsm::SparseMatrix< T >::insert | ( | Id | i, |
Id | j, | ||
T | value ) |
insert a value in the matrix
i | row index |
j | column index |
value | value to insert |
std::out_of_range | if the index is out of range |
void dsm::SparseMatrix< T >::insert | ( | Id | i, |
T | value ) |
insert a value in the matrix
i | index |
value | value to insert |
std::out_of_range | if the index is out of range |
void dsm::SparseMatrix< T >::insert_and_expand | ( | Id | i, |
Id | j, | ||
T | value ) |
insert a value in the matrix and expand the matrix if necessary.
i | row index |
j | column index |
value | value to insert |
void dsm::SparseMatrix< T >::insert_or_assign | ( | Id | i, |
Id | j, | ||
T | value ) |
insert a value in the matrix. If the element already exist, it overwrites it
i | row index |
j | column index |
value | value to insert |
std::out_of_range | if the index is out of range |
void dsm::SparseMatrix< T >::insert_or_assign | ( | Id | index, |
T | value ) |
insert a value in the matrix. If the element already exist, it overwrites it
index | index in vectorial form |
value | value to insert |
std::out_of_range | if the index is out of range |
|
inline |
get the maximum number of elements in the matrix
T & dsm::SparseMatrix< T >::operator() | ( | Id | i, |
Id | j ) |
access an element of the matrix
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
const T & dsm::SparseMatrix< T >::operator() | ( | Id | i, |
Id | j ) const |
access an element of the matrix
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
T & dsm::SparseMatrix< T >::operator() | ( | Id | index | ) |
access an element of the matrix
index | index in vectorial form |
std::out_of_range | if the index is out of range |
const T & dsm::SparseMatrix< T >::operator() | ( | Id | index | ) | const |
access an element of the matrix
index | index in vectorial form |
std::out_of_range | if the index is out of range |
|
inline |
sum of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
SparseMatrix< T > dsm::SparseMatrix< T >::operator++ | ( | ) |
transpose the matrix
SparseMatrix & dsm::SparseMatrix< T >::operator+= | ( | const SparseMatrix< U > & | other | ) |
sum of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
|
inline |
difference of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
SparseMatrix & dsm::SparseMatrix< T >::operator-= | ( | const SparseMatrix< U > & | other | ) |
difference of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
|
inline |
get the number of non zero elements in the matrix