iRoCS Toolbox
1.1.0
|
The SparseMatrix class provides a sparse matrix data structure and corresponding arithmetics. More...
#include "libArrayToolbox/SparseMatrix.hh"
Public Member Functions | |
SparseMatrix () | |
Create a new empty SparseMatrix object. More... | |
SparseMatrix (size_t r, size_t c) | |
Create a new empty SparseMatrix object with given number of rows and colums. More... | |
SparseMatrix (SparseMatrix const &m) | |
Create a new deep copy of the given SparseMatrix object. More... | |
SparseMatrix (blitz::Array< T, 2 > const &m) | |
Create a new SparseMatrix object from a dense blitz++ Array. More... | |
template<int NRows, int NCols> | |
SparseMatrix (blitz::TinyMatrix< T, NRows, NCols > const &m) | |
Create a new SparseMatrix object from a dense blitz++ TinyMatrix. More... | |
~SparseMatrix () | |
Destroy the SparseMatrix object and release all its ressources. More... | |
void | clear () |
Set all entries of this matrix to zero. More... | |
void | clearColumn (size_t c) |
Set all entries of the given matrix column to zero. More... | |
void | clearRow (size_t r) |
Set all entries of the given matrix row to zero. More... | |
SparseVector< T > const & | column (size_t c) const |
Get a read-only sparse vector view of the selected matrix column. More... | |
SparseVector< T >::const_iterator | erase (size_t r, size_t c) |
Clear the matrix entry at the given position (set it zero). More... | |
void | load (std::string const &fileName, std::string const &groupName, bool throwErrors=false) |
Load the SparseMatrix from an HDF5 group in a file with given name. More... | |
size_t | nColumns () const |
Get the number of rows of this SparseMatrix. More... | |
size_t | nNonZeroEntries () const |
Get the number of non-zero entries of this SparseMatrix. More... | |
bool | nonZero (size_t r, size_t c) const |
Check whether the given matrix entry is non-zero. More... | |
size_t | nRows () const |
Get the number of rows of this SparseMatrix. More... | |
T const & | operator() (size_t r, size_t c) const |
Get a read-only reference on the entry at the specified position in the matrix. More... | |
T & | operator() (size_t r, size_t c) |
Get a random-access reference on the entry at the specified position in the matrix. More... | |
void | operator*= (T const &alpha) |
Multiply every entry of this matrix with the given scalar. More... | |
void | operator+= (SparseMatrix< T > const &m) |
Add the given matrix to this matrix. More... | |
void | operator-= (SparseMatrix< T > const &m) |
Subtract the given matrix from this matrix. More... | |
void | operator/= (T const &alpha) |
Divide every entry of this matrix by the given scalar. More... | |
void | resize (size_t r, size_t c) |
Resize the SparseMatrix to the given number of rows and columns. More... | |
SparseVector< T > const & | row (size_t r) const |
Get a read-only sparse vector view of the selected matrix row. More... | |
void | save (std::string const &fileName, std::string const &groupName, bool throwErrors=false) |
Save this SparseMatrix to an HDF5 group in a file with given name. More... | |
blitz::TinyVector< size_t, 2 > | shape () const |
Get the shape of this SparseMatrix. More... | |
blitz::Array< T, 2 > | toBlitz () const |
Get a dense blitz++ Array copy of this SparseMatrix. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T > | |
SparseVector< T > | operator* (SparseMatrix< T > const &A, SparseVector< T > const &x) |
template<typename T > | |
blitz::Array< T, 1 > | operator* (SparseMatrix< T > const &A, blitz::Array< T, 1 > const &x) |
template<typename T , int Dim> | |
blitz::TinyVector< T, Dim > | operator* (SparseMatrix< T > const &A, blitz::TinyVector< T, Dim > const &x) |
template<typename T > | |
SparseMatrix< T > | operator* (SparseMatrix< T > const &A, SparseMatrix< T > const &B) |
template<typename T > | |
SparseMatrix< T > | operator* (blitz::Array< T, 2 > const &A, SparseMatrix< T > const &B) |
template<typename T > | |
SparseMatrix< T > | operator* (SparseMatrix< T > const &A, blitz::Array< T, 2 > const &B) |
The SparseMatrix class provides a sparse matrix data structure and corresponding arithmetics.
Definition at line 90 of file SparseMatrix.hh.
atb::SparseMatrix< T >::SparseMatrix | ( | ) |
Create a new empty SparseMatrix object.
atb::SparseMatrix< T >::SparseMatrix | ( | size_t | r, |
size_t | c | ||
) |
Create a new empty SparseMatrix object with given number of rows and colums.
r | The number of matrix rows |
c | The number of matrix columns |
atb::SparseMatrix< T >::SparseMatrix | ( | SparseMatrix< T > const & | m | ) |
Create a new deep copy of the given SparseMatrix object.
m | The sparse matrix to copy |
atb::SparseMatrix< T >::SparseMatrix | ( | blitz::Array< T, 2 > const & | m | ) |
Create a new SparseMatrix object from a dense blitz++ Array.
SparseMatrix dimensions and content will be taken from the given Array.
m | The blitz++ Array containing the values to copy into the new SparseMatrix object |
atb::SparseMatrix< T >::SparseMatrix | ( | blitz::TinyMatrix< T, NRows, NCols > const & | m | ) |
Create a new SparseMatrix object from a dense blitz++ TinyMatrix.
SparseMatrix dimensions and content will be taken from the given TinyMatrix.
m | The blitz++ TinyMatrix containing the values to copy into the new SparseMatrix object |
atb::SparseMatrix< T >::~SparseMatrix | ( | ) |
Destroy the SparseMatrix object and release all its ressources.
Any existing references to this SparseMatrix or views of its rows and columns get invalidated.
void atb::SparseMatrix< T >::resize | ( | size_t | r, |
size_t | c | ||
) |
Resize the SparseMatrix to the given number of rows and columns.
r | The number of matrix rows |
c | The number of matrix columns |
size_t atb::SparseMatrix< T >::nRows | ( | ) | const |
Get the number of rows of this SparseMatrix.
size_t atb::SparseMatrix< T >::nColumns | ( | ) | const |
Get the number of rows of this SparseMatrix.
blitz::TinyVector<size_t,2> atb::SparseMatrix< T >::shape | ( | ) | const |
Get the shape of this SparseMatrix.
size_t atb::SparseMatrix< T >::nNonZeroEntries | ( | ) | const |
Get the number of non-zero entries of this SparseMatrix.
void atb::SparseMatrix< T >::clear | ( | ) |
Set all entries of this matrix to zero.
void atb::SparseMatrix< T >::clearRow | ( | size_t | r | ) |
Set all entries of the given matrix row to zero.
r | The row to clear |
void atb::SparseMatrix< T >::clearColumn | ( | size_t | c | ) |
Set all entries of the given matrix column to zero.
c | The column to clear |
SparseVector<T> const& atb::SparseMatrix< T >::row | ( | size_t | r | ) | const |
Get a read-only sparse vector view of the selected matrix row.
This is a O(1) operation.
r | The matrix row to get a view for |
SparseVector<T> const& atb::SparseMatrix< T >::column | ( | size_t | c | ) | const |
Get a read-only sparse vector view of the selected matrix column.
Getting a matrix column for the first time is quite expensive because a new SparseVector must be created and columns entries searched in the matrix. Collecting the column entries requires to iterate over the rows. Later access to the same column is an O(1) operation if column entries did not change (Requesting a random-access reference is regarded as change! However, when changing a column through an old random-access reference will not be recognized. At best never store random-access references!).
c | The matrix column to get a view for |
bool atb::SparseMatrix< T >::nonZero | ( | size_t | r, |
size_t | c | ||
) | const |
Check whether the given matrix entry is non-zero.
r | The row index |
c | The column index |
true
if the matrix entry at the given row and column is non-zero, false
otherwise T const& atb::SparseMatrix< T >::operator() | ( | size_t | r, |
size_t | c | ||
) | const |
Get a read-only reference on the entry at the specified position in the matrix.
r | The row index |
c | The column index |
T& atb::SparseMatrix< T >::operator() | ( | size_t | r, |
size_t | c | ||
) |
Get a random-access reference on the entry at the specified position in the matrix.
If the entry contains zero (is not yet contained in the matrix) it will be created. Using this operator invalidates any views on the specified column, because it can potentially change. Only use these references directly. When using "old" previously stored references the column cache will not be updated!
r | The row index |
c | The column index |
SparseVector<T>::const_iterator atb::SparseMatrix< T >::erase | ( | size_t | r, |
size_t | c | ||
) |
Clear the matrix entry at the given position (set it zero).
r | The row index |
c | The column index |
blitz::Array<T,2> atb::SparseMatrix< T >::toBlitz | ( | ) | const |
Get a dense blitz++ Array copy of this SparseMatrix.
void atb::SparseMatrix< T >::operator+= | ( | SparseMatrix< T > const & | m | ) |
Add the given matrix to this matrix.
m | The matrix to add to this matrix |
void atb::SparseMatrix< T >::operator-= | ( | SparseMatrix< T > const & | m | ) |
Subtract the given matrix from this matrix.
m | The matrix to subtract from this matrix |
void atb::SparseMatrix< T >::operator*= | ( | T const & | alpha | ) |
Multiply every entry of this matrix with the given scalar.
alpha | The scalar the matrix entries are scaled with |
void atb::SparseMatrix< T >::operator/= | ( | T const & | alpha | ) |
Divide every entry of this matrix by the given scalar.
alpha | The scalar the matrix entries are divided by |
void atb::SparseMatrix< T >::save | ( | std::string const & | fileName, |
std::string const & | groupName, | ||
bool | throwErrors = false |
||
) |
Save this SparseMatrix to an HDF5 group in a file with given name.
fileName | The name of the HDF5 file |
groupName | The name of the HDF5 group |
throwErrors | If false is given the program aborts on error with exit code -1, otherwise a BlitzH5Error is thrown |
BlitzH5Error | If the matrix cannot be saved and throwErrors is set to true . |
void atb::SparseMatrix< T >::load | ( | std::string const & | fileName, |
std::string const & | groupName, | ||
bool | throwErrors = false |
||
) |
Load the SparseMatrix from an HDF5 group in a file with given name.
This function resizes the matrix accordingly and fills in the values stored in the HDF5 file. Previous content of this SparseMatrix is lost.
fileName | The name of the HDF5 file |
groupName | The name of the HDF5 group |
throwErrors | If false is given the program aborts on error with exit code -1, otherwise a BlitzH5Error is thrown |
BlitzH5Error | If the matrix cannot be loaded and throwErrors is set to true . |
|
related |
Matrix-vector product for sparse matrices and sparse vectors.
A | The left-hand-side matrix |
x | The right-hand-side vector |
|
related |
Matrix-vector product for sparse matrices and dense 1-D blitz++ Arrays.
A | The left-hand-side matrix |
x | The right-hand-side vector |
|
related |
Matrix-vector product for quadratic sparse matrices and blitz++ TinyVectors.
A | The left-hand-side matrix |
x | The right-hand-side vector |
|
related |
Matrix-Matrix product for sparse matrices.
A | The left-hand-side matrix (n x k) |
B | The right-hand-side matrix (k x m) |
|
related |
Matrix-Matrix product for blitz++ Array and sparse matrix.
A | The left-hand-side matrix (n x k) |
B | The right-hand-side matrix (k x m) |
|
related |
Matrix-Matrix product for sparse matrix and blitz++ Array.
A | The left-hand-side matrix (n x k) |
B | The right-hand-side matrix (k x m) |