|
ug4
|
sparse matrix for big, variable sparse matrices. More...
#include <sparsematrix.h>
Classes | |
| class | const_row_iterator |
| class | row_iterator |
Public Types | |
| enum | { rows_sorted =true } |
| typedef AlgebraicConnection< TValueType > | connection |
| typedef ConstMatrixRow< this_type > | const_row_type |
| typedef MatrixRow< this_type > | row_type |
| typedef SparseMatrix< value_type > | this_type |
| typedef TValueType | value_type |
Public Member Functions | |
| template<typename M > | |
| void | add (const M &mat) |
| void | add_matrix_row (size_t row, connection *c, size_t nr) |
| template<typename Vector_type > | |
| bool | apply (Vector_type &res, const Vector_type &x) const |
| calculate res = A x | |
| template<typename vector_t > | |
| void | apply_ignore_zero_rows (vector_t &dest, const number &beta1, const vector_t &w1) const |
| calculated dest = beta1*A*w1 . For empty rows, dest will not be changed | |
| template<typename Vector_type > | |
| bool | apply_transposed (Vector_type &res, const Vector_type &x) const |
| calculate res = A.T x | |
| template<typename vector_t > | |
| void | apply_transposed_ignore_zero_rows (vector_t &dest, const number &beta1, const vector_t &w1) const |
| calculated dest = beta1*A*w1 . For empty cols of A (=empty rows of A^T), dest will not be changed | |
| template<typename vector_t > | |
| void | axpy (vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const vector_t &w1) const |
| calculate dest = alpha1*v1 + beta1*A*w1 (A = this matrix) | |
| template<typename vector_t > | |
| void | axpy_transposed (vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const vector_t &w1) const |
| calculate dest = alpha1*v1 + beta1*A^T*w1 (A = this matrix) | |
| row_iterator | begin_row (size_t r) |
| const_row_iterator | begin_row (size_t r) const |
| void | check_rc (size_t r, size_t c) const |
| void | check_row_modifiable (size_t r) const |
| void | clear_and_free () |
| Clears the matrix vectors and frees their memory. | |
| void | clear_retain_structure () |
| int | col (size_t i) const |
| void | copy_crs (size_t &numRows, size_t &numCols, std::vector< value_type > &argValues, std::vector< int > &argRowStart, std::vector< int > &argColInd) const |
| void | defragment () |
| void | defragment () const |
| row_iterator | end_row (size_t r) |
| const_row_iterator | end_row (size_t r) const |
| template<typename M > | |
| void | get (M &mat) const |
| get local matrix | |
| row_iterator | get_connection (size_t r, size_t c) |
| const_row_iterator | get_connection (size_t r, size_t c) const |
| row_iterator | get_connection (size_t r, size_t c, bool &bFound) |
| const_row_iterator | get_connection (size_t r, size_t c, bool &bFound) const |
| void | get_crs (size_t &numRows, size_t &numCols, value_type *&pValues, size_t *pRowStart, size_t *pColInd, size_t &nnz) const |
| row_iterator | get_iterator_or_next (size_t r, size_t c) |
| row_type | get_row (size_t r) |
| const_row_type | get_row (size_t r) const |
| void | get_values (std::vector< value_type > &argValues) const |
| bool | has_connection (size_t r, size_t c) const |
| bool | is_isolated (size_t i) const |
| check for isolated condition of an index | |
| int | iters () const |
| template<typename vector_t > | |
| void | mat_mult_add_row (size_t row, typename vector_t::value_type &dest, double alpha, const vector_t &v) const |
| calculates dest += alpha * A[row, .] v; | |
| template<typename Vector_type > | |
| bool | matmul_minus (Vector_type &res, const Vector_type &x) const |
| calculate res -= A x | |
| size_t | num_cols () const |
| returns the number of cols | |
| size_t | num_connections (size_t i) const |
| returns number of connections of row row. | |
| size_t | num_rows () const |
| returns number of rows | |
| value_type & | operator() (size_t r, size_t c) |
| const value_type & | operator() (size_t r, size_t c) const |
| SparseMatrix< value_type > & | operator*= (double d) |
| SparseMatrix< value_type > & | operator= (const SparseMatrix< value_type > &B) |
| void | p () const |
| void | pr (size_t row) const |
| void | print (const char *const name=NULL) const |
| void | print_to_file (const char *filename) const |
| void | printrow (size_t row) const |
| void | printtype () const |
| void | resize_and_clear (size_t newRows, size_t newCols) |
| resizes the SparseMatrix | |
| void | resize_and_keep_values (size_t newRows, size_t newCols) |
| void | scale (double d) |
| template<typename M > | |
| void | set (const M &mat) |
| set local matrix | |
| void | set (double a) |
| set matrix to Id*a | |
| void | set_as_copy_of (const SparseMatrix< value_type > &B, double scale=1.0) |
| create/recreate this as a copy of SparseMatrix B | |
| void | set_as_transpose_of (const SparseMatrix< value_type > &B, double scale=1.0) |
| write in a empty SparseMatrix (this) the transpose SparseMatrix of B. | |
| void | set_as_transpose_of2 (const SparseMatrix< value_type > &B, double scale=1.0) |
| void | set_matrix_row (size_t row, connection *c, size_t nr) |
| SparseMatrix () | |
| constructor for empty SparseMatrix | |
| size_t | total_num_connections () const |
| returns the total number of connections | |
| virtual | ~SparseMatrix () |
| destructor | |
Public Attributes | |
| std::vector< int > | nrOfRowIterators |
Protected Member Functions | |
| void | check_fragmentation () const |
| void | copyToNewSize (size_t newSize) |
| void | copyToNewSize (size_t newSize, size_t maxCols) |
| int | get_index (int r, int c) |
| int | get_index_const (int r, int c) const |
| int | get_index_internal (size_t row, int col) const |
| int | get_nnz_max_cols (size_t maxCols) |
Protected Attributes | |
| bool | bNeedsValues |
| std::vector< int > | cols |
| size_t | fragmented |
| int | iIterators |
| int | m_numCols |
| int | maxValues |
| size_t | nnz |
| std::vector< int > | rowEnd |
| std::vector< int > | rowMax |
| std::vector< int > | rowStart |
| std::vector< value_type > | values |
Private Member Functions | |
| void | add_iterator (size_t row) const |
| void | assureValuesSize (size_t s) |
| void | check_row (size_t row, int i) const |
| size_t | get_nnz () const |
| void | remove_iterator (size_t row) const |
| SparseMatrix (SparseMatrix &) | |
| disallow copy operator | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, const SparseMatrix &m) |
sparse matrix for big, variable sparse matrices.
matrix is stored independent row-wise When doing discretisation, use the add set and get methods for dealing with submatrices of A. For other things you can use the row iterators or operator()-methods.
| T | blocktype |
| T | blocktype |
| typedef AlgebraicConnection<TValueType> ug::SparseMatrix< TValueType >::connection |
| typedef ConstMatrixRow<this_type> ug::SparseMatrix< TValueType >::const_row_type |
| typedef MatrixRow<this_type> ug::SparseMatrix< TValueType >::row_type |
| typedef SparseMatrix<value_type> ug::SparseMatrix< TValueType >::this_type |
| typedef TValueType ug::SparseMatrix< TValueType >::value_type |
| SparseMatrix< T >::SparseMatrix | ( | ) |
constructor for empty SparseMatrix
References PROFILE_SPMATRIX.
|
inlinevirtual |
destructor
|
private |
disallow copy operator
Add a local matrix
The local matrix type must declare the following members:
| mat | the whole local matrix type |
|
inlineprivate |
References ug::SparseMatrix< TValueType >::iIterators, and ug::SparseMatrix< TValueType >::nrOfRowIterators.
Referenced by ug::SparseMatrix< TValueType >::const_row_iterator::const_row_iterator(), ug::SparseMatrix< TValueType >::const_row_iterator::const_row_iterator(), ug::SparseMatrix< TValueType >::const_row_iterator::const_row_iterator(), ug::SparseMatrix< TValueType >::row_iterator::row_iterator(), ug::SparseMatrix< TValueType >::row_iterator::row_iterator(), and ug::SparseMatrix< TValueType >::row_iterator::row_iterator().
| void SparseMatrix< T >::add_matrix_row | ( | size_t | row, |
| connection * | c, | ||
| size_t | nr | ||
| ) |
adds the connections c to the matrixrow row. if c has a connection con with con.iIndex=i, and the matrix already has a connection (row, i), the function will set A(row,i) += con.dValue. otherwise the connection A(row, i) is created and set to con.dValue.
| row | row to add to |
| c | connections ("row") to be added the row. |
| nr | number of connections in array c. |
References ug::AlgebraicConnection< T >::iIndex.
|
inline |
calculate res = A x
References ug::SparseMatrix< TValueType >::axpy().
| void SparseMatrix< T >::apply_ignore_zero_rows | ( | vector_t & | dest, |
| const number & | beta1, | ||
| const vector_t & | w1 | ||
| ) | const |
calculated dest = beta1*A*w1 . For empty rows, dest will not be changed
References ug::MatMult(), ug::MatMultAdd(), and num_rows().
|
inline |
calculate res = A.T x
References ug::SparseMatrix< TValueType >::axpy_transposed().
| void SparseMatrix< T >::apply_transposed_ignore_zero_rows | ( | vector_t & | dest, |
| const number & | beta1, | ||
| const vector_t & | w1 | ||
| ) | const |
calculated dest = beta1*A*w1 . For empty cols of A (=empty rows of A^T), dest will not be changed
References begin_row(), end_row(), ug::MatMultTransposedAdd(), and num_rows().
|
private |
References s.
| void SparseMatrix< T >::axpy | ( | vector_t & | dest, |
| const number & | alpha1, | ||
| const vector_t & | v1, | ||
| const number & | beta1, | ||
| const vector_t & | w1 | ||
| ) | const |
calculate dest = alpha1*v1 + beta1*A*w1 (A = this matrix)
References num_rows(), and PROFILE_SPMATRIX.
Referenced by ug::SparseMatrix< TValueType >::apply(), and ug::SparseMatrix< TValueType >::matmul_minus().
| void SparseMatrix< T >::axpy_transposed | ( | vector_t & | dest, |
| const number & | alpha1, | ||
| const vector_t & | v1, | ||
| const number & | beta1, | ||
| const vector_t & | w1 | ||
| ) | const |
calculate dest = alpha1*v1 + beta1*A^T*w1 (A = this matrix)
References ug::MatMultTransposedAdd(), num_rows(), PROFILE_SPMATRIX, and ug::VecScaleAssign().
Referenced by ug::SparseMatrix< TValueType >::apply_transposed(), and ug::MatMultTransposedAdd().
|
inline |
|
inline |
References ug::SparseMatrix< TValueType >::rowStart.
|
protected |
References defragment().
|
inline |
References ug::SparseMatrix< TValueType >::num_cols(), ug::SparseMatrix< TValueType >::num_rows(), and UG_ASSERT.
Referenced by ug::SparseMatrix< TValueType >::get_connection(), ug::SparseMatrix< TValueType >::get_connection(), ug::SparseMatrix< TValueType >::get_connection(), ug::SparseMatrix< TValueType >::get_iterator_or_next(), ug::SparseMatrix< TValueType >::has_connection(), ug::SparseMatrix< TValueType >::operator()(), and ug::SparseMatrix< TValueType >::operator()().
|
inlineprivate |
|
inline |
References ug::SparseMatrix< TValueType >::nrOfRowIterators, and UG_ASSERT.
| void SparseMatrix< T >::clear_and_free | ( | ) |
Clears the matrix vectors and frees their memory.
| void SparseMatrix< T >::clear_retain_structure | ( | ) |
|
inline |
References ug::SparseMatrix< TValueType >::cols.
|
inline |
copies the matrix to the standard CRS format
| numRows | (out) num rows of A |
| numCols | (out) num rows of A |
| argValues | (out) value_type vector with non-zero values |
| argRowStart | (out) row i is from argRowStart[i] to argRowStart[i+1] |
| argColInd | (out) argColInd[i] is colum index of nonzero i |
References ug::SparseMatrix< TValueType >::cols, ug::SparseMatrix< TValueType >::defragment(), ug::SparseMatrix< TValueType >::num_cols(), ug::SparseMatrix< TValueType >::num_rows(), ug::SparseMatrix< TValueType >::rowStart, and ug::SparseMatrix< TValueType >::values.
|
inlineprotected |
|
protected |
|
inline |
References ug::SparseMatrix< TValueType >::copyToNewSize(), ug::SparseMatrix< TValueType >::nnz, ug::SparseMatrix< TValueType >::num_cols(), and ug::SparseMatrix< TValueType >::num_rows().
Referenced by ug::SparseMatrix< TValueType >::copy_crs(), ug::SparseMatrix< TValueType >::get_crs(), and ug::SparseMatrix< TValueType >::get_values().
|
inline |
|
inline |
References ug::SparseMatrix< TValueType >::rowEnd.
Referenced by boost::adjacent_vertices(), ug::SparseMatrix< TValueType >::get_connection(), ug::SparseMatrix< TValueType >::get_connection(), ug::SparseMatrix< TValueType >::get_iterator_or_next(), ug::SparseMatrix< TValueType >::set_as_copy_of(), ug::MapSparseMatrix< TValueType >::set_as_transpose_of(), and ug::SparseMatrix< TValueType >::set_as_transpose_of2().
|
inline |
References ug::SparseMatrix< TValueType >::rowEnd.
get local matrix
|
inline |
| r | index of the row |
| c | index of the column |
References ug::SparseMatrix< TValueType >::bNeedsValues, ug::SparseMatrix< TValueType >::check_rc(), and ug::SparseMatrix< TValueType >::get_index().
|
inline |
| r | index of the row |
| c | index of the column |
References ug::SparseMatrix< TValueType >::get_connection().
|
inline |
| r | index of the row |
| c | index of the column |
References ug::SparseMatrix< TValueType >::check_rc(), ug::SparseMatrix< TValueType >::end_row(), and ug::SparseMatrix< TValueType >::get_index_const().
|
inline |
| r | index of the row |
| c | index of the column |
References ug::SparseMatrix< TValueType >::check_rc(), ug::SparseMatrix< TValueType >::end_row(), and ug::SparseMatrix< TValueType >::get_index_const().
Referenced by ug::SparseMatrix< TValueType >::get_connection(), and ug::SparseMatrix< TValueType >::has_connection().
|
inline |
returns pointers to CRS format. note that these are only valid as long as the matrix is not modified.
| numRows | (out) num rows of A |
| numCols | (out) num rows of A |
| pValues | (out) value_type vector with non-zero values |
| pRowStart | (out) row i is from pRowStart[i] to pRowStart[i+1] |
| pColInd | (out) pColInd[i] is colum index of nonzero i |
References ug::SparseMatrix< TValueType >::defragment(), ug::SparseMatrix< TValueType >::nnz, ug::SparseMatrix< TValueType >::num_cols(), ug::SparseMatrix< TValueType >::num_rows(), ug::SparseMatrix< TValueType >::total_num_connections(), UG_THROW, and ug::SparseMatrix< TValueType >::values.
|
protected |
|
protected |
|
protected |
References UG_ASSERT.
Referenced by ug::SparseMatrix< TValueType >::get_iterator_or_next().
|
inline |
| r | index of the row |
| c | index of the column |
References ug::SparseMatrix< TValueType >::check_rc(), ug::SparseMatrix< TValueType >::end_row(), ug::SparseMatrix< TValueType >::get_index_internal(), ug::SparseMatrix< TValueType >::maxValues, ug::SparseMatrix< TValueType >::rowEnd, and ug::SparseMatrix< TValueType >::rowStart.
|
inlineprivate |
References ug::SparseMatrix< TValueType >::nnz.
|
protected |
References num_rows().
|
inline |
|
inline |
|
inline |
assigns a reference to the values vector to argument vector
| argValues | vector to be assigned |
References ug::SparseMatrix< TValueType >::defragment(), and ug::SparseMatrix< TValueType >::values.
|
inline |
|
inline |
check for isolated condition of an index
| i |
References begin_row(), end_row(), num_rows(), and UG_ASSERT.
|
inline |
References ug::SparseMatrix< TValueType >::iIterators.
|
inline |
calculates dest += alpha * A[row, .] v;
|
inline |
calculate res -= A x
References ug::SparseMatrix< TValueType >::axpy().
|
inline |
returns the number of cols
References ug::SparseMatrix< TValueType >::m_numCols.
Referenced by ug::SparseMatrix< TValueType >::check_rc(), ug::SparseMatrix< TValueType >::copy_crs(), ug::SparseMatrix< TValueType >::copyToNewSize(), ug::SparseMatrix< TValueType >::defragment(), ug::SparseMatrix< TValueType >::get_crs(), boost::num_vertices(), ug::SparseMatrix< T >::set_as_copy_of(), ug::SparseMatrix< TValueType >::set_as_copy_of(), ug::MapSparseMatrix< TValueType >::set_as_transpose_of(), and ug::SparseMatrix< TValueType >::set_as_transpose_of2().
|
inline |
returns number of connections of row row.
References ug::SparseMatrix< TValueType >::rowEnd, and ug::SparseMatrix< TValueType >::rowStart.
|
inline |
returns number of rows
References ug::SparseMatrix< TValueType >::rowEnd.
Referenced by boost::adjacent_vertices(), ug::SparseMatrix< TValueType >::check_rc(), ug::SparseMatrix< TValueType >::copy_crs(), ug::SparseMatrix< TValueType >::defragment(), ug::SparseMatrix< TValueType >::get_crs(), boost::num_vertices(), boost::out_edges(), ug::SparseMatrix< T >::set_as_copy_of(), ug::SparseMatrix< TValueType >::set_as_copy_of(), ug::MapSparseMatrix< TValueType >::set_as_transpose_of(), ug::SparseMatrix< TValueType >::set_as_transpose_of2(), and boost::vertices().
|
inline |
operator() (size_t r, size_t c) const access or create connection (r, c)
| r | row |
| c | column |
References ug::SparseMatrix< TValueType >::check_rc(), ug::SparseMatrix< TValueType >::cols, ug::SparseMatrix< TValueType >::get_index(), ug::SparseMatrix< TValueType >::rowEnd, ug::SparseMatrix< TValueType >::rowStart, UG_ASSERT, and ug::SparseMatrix< TValueType >::values.
|
inline |
operator() (size_t r, size_t c) const access connection (r, c)
| r | row |
| c | column |
References ug::SparseMatrix< TValueType >::check_rc(), ug::SparseMatrix< TValueType >::cols, ug::SparseMatrix< TValueType >::get_index_const(), ug::SparseMatrix< TValueType >::rowEnd, ug::SparseMatrix< TValueType >::rowStart, UG_ASSERT, and ug::SparseMatrix< TValueType >::values.
|
inline |
References ug::SparseMatrix< TValueType >::scale().
|
inline |
References ug::SparseMatrix< TValueType >::set_as_copy_of().
|
inline |
References ug::SparseMatrix< TValueType >::print().
|
inline |
References ug::SparseMatrix< TValueType >::printrow().
| void ug::SparseMatrix< TValueType >::print_to_file | ( | const char * | filename | ) | const |
|
inlineprivate |
| void SparseMatrix< T >::resize_and_clear | ( | size_t | newRows, |
| size_t | newCols | ||
| ) |
resizes the SparseMatrix
| newRows | new nr of rows |
| newCols | new nr of cols |
References PROFILE_SPMATRIX.
| void SparseMatrix< T >::resize_and_keep_values | ( | size_t | newRows, |
| size_t | newCols | ||
| ) |
References PROFILE_SPMATRIX.
| void SparseMatrix< T >::scale | ( | double | d | ) |
References begin_row(), end_row(), and num_rows().
Referenced by ug::SparseMatrix< TValueType >::operator*=().
set local matrix
| void SparseMatrix< T >::set | ( | double | a | ) |
set matrix to Id*a
References begin_row(), end_row(), num_rows(), and PROFILE_SPMATRIX.
| void SparseMatrix< T >::set_as_copy_of | ( | const SparseMatrix< value_type > & | B, |
| double | scale = 1.0 |
||
| ) |
create/recreate this as a copy of SparseMatrix B
| B | the matrix of which to create a copy of |
| scale | an optional scaling |
References ug::SparseMatrix< TValueType >::begin_row(), ug::SparseMatrix< TValueType >::end_row(), ug::SparseMatrix< TValueType >::num_cols(), ug::SparseMatrix< TValueType >::num_rows(), and ug::SparseMatrix< TValueType >::row_iterator::value().
Referenced by ug::SparseMatrix< TValueType >::operator=().
| void SparseMatrix< T >::set_as_transpose_of | ( | const SparseMatrix< value_type > & | B, |
| double | scale = 1.0 |
||
| ) |
write in a empty SparseMatrix (this) the transpose SparseMatrix of B.
| B | the matrix of which to create the transpose of |
| scale | an optional scaling |
| void SparseMatrix< T >::set_as_transpose_of2 | ( | const SparseMatrix< value_type > & | B, |
| double | scale = 1.0 |
||
| ) |
References ug::SparseMatrix< TValueType >::begin_row(), ug::SparseMatrix< TValueType >::bNeedsValues, ug::SparseMatrix< TValueType >::end_row(), ug::iszero(), ug::SparseMatrix< TValueType >::maxValues, ug::SparseMatrix< TValueType >::num_cols(), num_cols(), ug::SparseMatrix< TValueType >::num_rows(), num_rows(), and PROFILE_SPMATRIX.
| void SparseMatrix< T >::set_matrix_row | ( | size_t | row, |
| connection * | c, | ||
| size_t | nr | ||
| ) |
set a row of the matrix. all previous content in this row is destroyed (
| row | index of the row to set |
| c | pointer to a array of sorted connections of size nr |
| nr | number of connections in c |
References ug::AlgebraicConnection< T >::iIndex.
|
inline |
returns the total number of connections
References ug::SparseMatrix< TValueType >::nnz.
Referenced by ug::SparseMatrix< TValueType >::get_crs().
|
friend |
|
protected |
|
protected |
Referenced by ug::SparseMatrix< TValueType >::col(), ug::SparseMatrix< TValueType >::copy_crs(), ug::SparseMatrix< TValueType >::row_iterator::index(), ug::SparseMatrix< TValueType >::const_row_iterator::index(), ug::SparseMatrix< TValueType >::operator()(), and ug::SparseMatrix< TValueType >::operator()().
|
protected |
|
mutableprotected |
|
protected |
Referenced by ug::SparseMatrix< TValueType >::num_cols().
|
protected |
|
protected |
|
mutable |
|
protected |
Referenced by ug::SparseMatrix< TValueType >::check_row(), ug::SparseMatrix< TValueType >::end_row(), ug::SparseMatrix< TValueType >::end_row(), ug::SparseMatrix< TValueType >::get_iterator_or_next(), ug::SparseMatrix< TValueType >::num_connections(), ug::SparseMatrix< TValueType >::num_rows(), ug::SparseMatrix< TValueType >::operator()(), and ug::SparseMatrix< TValueType >::operator()().
|
protected |
|
protected |
Referenced by ug::SparseMatrix< TValueType >::begin_row(), ug::SparseMatrix< TValueType >::begin_row(), ug::SparseMatrix< TValueType >::check_row(), ug::SparseMatrix< TValueType >::copy_crs(), ug::SparseMatrix< TValueType >::get_iterator_or_next(), ug::SparseMatrix< TValueType >::num_connections(), ug::SparseMatrix< TValueType >::operator()(), and ug::SparseMatrix< TValueType >::operator()().
|
protected |
Referenced by ug::SparseMatrix< TValueType >::copy_crs(), ug::SparseMatrix< TValueType >::get_crs(), ug::SparseMatrix< TValueType >::get_values(), ug::SparseMatrix< TValueType >::operator()(), ug::SparseMatrix< TValueType >::operator()(), ug::SparseMatrix< TValueType >::row_iterator::value(), and ug::SparseMatrix< TValueType >::const_row_iterator::value().