ug4
ug::MapSparseMatrix< TValueType > Class Template Reference

sparse matrix for big, variable sparse matrices. More...

#include <mapsparsematrix.h>

Classes

struct  connection
 
class  const_row_iterator
 
class  row_iterator
 

Public Types

enum  { rows_sorted =true }
 
typedef SparseMatrix< value_typethis_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 More...
 
template<typename Vector_type >
bool apply_transposed (Vector_type &res, const Vector_type &x) const
 calculate res = A.T x More...
 
template<typename vector_t >
bool 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) More...
 
template<typename vector_t >
bool 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) More...
 
row_iterator begin_row (size_t r)
 
const_row_iterator begin_row (size_t r) const
 
void defragment ()
 
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 More...
 
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
 
bool is_isolated (size_t i) const
 check for isolated condition of an index More...
 
 MapSparseMatrix ()
 constructor for empty SparseMatrix More...
 
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; More...
 
template<typename Vector_type >
bool matmul_minus (Vector_type &res, const Vector_type &x) const
 calculate res -= A x More...
 
size_t num_cols () const
 returns the number of cols More...
 
size_t num_connections (size_t i) const
 returns number of connections of row row. More...
 
size_t num_rows () const
 returns number of rows More...
 
value_typeoperator() (size_t r, size_t c)
 
const value_typeoperator() (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
 
bool resize (size_t newRows, size_t newCols)
 resizes the SparseMatrix More...
 
bool scale (double d)
 
template<typename M >
void set (const M &mat)
 set local matrix More...
 
bool set (double a)
 set matrix to Id*a More...
 
bool set_as_copy_of (const MapSparseMatrix< value_type > &B, double scale=1.0)
 create/recreate this as a copy of SparseMatrix B More...
 
bool set_as_transpose_of (const SparseMatrix< value_type > &B, double scale=1.0)
 write in a empty SparseMatrix (this) the transpose SparseMatrix of B. More...
 
void set_matrix_row (size_t row, connection *c, size_t nr)
 
size_t total_num_connections () const
 returns the total number of connections More...
 
virtual ~MapSparseMatrix ()
 destructor More...
 

Protected Attributes

size_t cols
 
std::vector< std::map< size_t, TValueType > > data
 

Private Member Functions

 MapSparseMatrix (MapSparseMatrix &)
 disallow copy operator More...
 

Friends

std::ostream & operator<< (std::ostream &out, const MapSparseMatrix &m)
 

Detailed Description

template<typename TValueType>
class ug::MapSparseMatrix< TValueType >

sparse matrix for big, variable sparse matrices.

SparseMatrix

See also
matrixrow, CreateAsMultiplyOf
Parameters
Tblocktype

Member Typedef Documentation

◆ this_type

template<typename TValueType >
typedef SparseMatrix<value_type> ug::MapSparseMatrix< TValueType >::this_type

◆ value_type

template<typename TValueType >
typedef TValueType ug::MapSparseMatrix< TValueType >::value_type

Member Enumeration Documentation

◆ anonymous enum

template<typename TValueType >
anonymous enum
Enumerator
rows_sorted 

Constructor & Destructor Documentation

◆ MapSparseMatrix() [1/2]

template<typename T >
ug::MapSparseMatrix< T >::MapSparseMatrix

constructor for empty SparseMatrix

◆ ~MapSparseMatrix()

template<typename TValueType >
virtual ug::MapSparseMatrix< TValueType >::~MapSparseMatrix ( )
inlinevirtual

destructor

◆ MapSparseMatrix() [2/2]

template<typename TValueType >
ug::MapSparseMatrix< TValueType >::MapSparseMatrix ( MapSparseMatrix< TValueType > &  )
private

disallow copy operator

Member Function Documentation

◆ add()

template<typename TValueType >
template<typename M >
void ug::MapSparseMatrix< TValueType >::add ( const M &  mat)

Add a local matrix

The local matrix type must declare the following members:

◆ add_matrix_row()

template<typename T >
void ug::MapSparseMatrix< 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.

Parameters
rowrow to add to
cconnections ("row") to be added the row.
nrnumber of connections in array c.
Returns
true on success.
Note
you may use double connections in c.

References ug::MapSparseMatrix< TValueType >::connection::iIndex, and PROFILE_BEGIN_GROUP.

◆ apply()

template<typename TValueType >
template<typename Vector_type >
bool ug::MapSparseMatrix< TValueType >::apply ( Vector_type &  res,
const Vector_type &  x 
) const
inline

calculate res = A x

References ug::MapSparseMatrix< TValueType >::axpy().

◆ apply_transposed()

template<typename TValueType >
template<typename Vector_type >
bool ug::MapSparseMatrix< TValueType >::apply_transposed ( Vector_type &  res,
const Vector_type &  x 
) const
inline

calculate res = A.T x

References ug::MapSparseMatrix< TValueType >::axpy_transposed().

◆ axpy()

template<typename T >
template<typename vector_t >
bool ug::MapSparseMatrix< T >::axpy ( vector_t &  dest,
const number alpha1,
const vector_t &  v1,
const number beta1,
const vector_t &  w1 
) const

◆ axpy_transposed()

template<typename T >
template<typename vector_t >
bool ug::MapSparseMatrix< T >::axpy_transposed ( vector_t &  dest,
const number alpha1,
const vector_t &  v1,
const number beta1,
const vector_t &  w1 
) const

◆ begin_row() [1/2]

template<typename TValueType >
row_iterator ug::MapSparseMatrix< TValueType >::begin_row ( size_t  r)
inline

◆ begin_row() [2/2]

template<typename TValueType >
const_row_iterator ug::MapSparseMatrix< TValueType >::begin_row ( size_t  r) const
inline

◆ defragment()

template<typename TValueType >
void ug::MapSparseMatrix< TValueType >::defragment ( )
inline

◆ end_row() [1/2]

◆ end_row() [2/2]

template<typename TValueType >
const_row_iterator ug::MapSparseMatrix< TValueType >::end_row ( size_t  r) const
inline

◆ get()

template<typename TValueType >
template<typename M >
void ug::MapSparseMatrix< TValueType >::get ( M &  mat) const

get local matrix

See also
add

◆ get_connection() [1/4]

template<typename TValueType >
row_iterator ug::MapSparseMatrix< TValueType >::get_connection ( size_t  r,
size_t  c 
)
inline
Parameters
rindex of the row
cindex of the column
Returns
a row_iterator to the connection A(r,c)
Remarks
creates connection if necessary.

References ug::MapSparseMatrix< TValueType >::data, and ug::find().

◆ get_connection() [2/4]

template<typename TValueType >
const_row_iterator ug::MapSparseMatrix< TValueType >::get_connection ( size_t  r,
size_t  c 
) const
inline
Parameters
rindex of the row
cindex of the column
Returns
a const_row_iterator to the connection A(r,c) if existing, otherwise end_row(row)

References ug::MapSparseMatrix< TValueType >::data, and ug::find().

◆ get_connection() [3/4]

template<typename TValueType >
row_iterator ug::MapSparseMatrix< TValueType >::get_connection ( size_t  r,
size_t  c,
bool &  bFound 
)
inline
Parameters
rindex of the row
cindex of the column
Returns
a row_iterator to the connection A(r,c) if existing, otherwise end_row(row)

References ug::MapSparseMatrix< TValueType >::data, ug::MapSparseMatrix< TValueType >::end_row(), and ug::find().

◆ get_connection() [4/4]

template<typename TValueType >
const_row_iterator ug::MapSparseMatrix< TValueType >::get_connection ( size_t  r,
size_t  c,
bool &  bFound 
) const
inline
Parameters
rindex of the row
cindex of the column
Returns
a const_row_iterator to the connection A(r,c) if existing, otherwise end_row(row)

References ug::MapSparseMatrix< TValueType >::data, ug::MapSparseMatrix< TValueType >::end_row(), and ug::find().

◆ is_isolated()

template<typename T >
bool ug::MapSparseMatrix< T >::is_isolated ( size_t  i) const
inline

check for isolated condition of an index

Parameters
i
Returns
true if only A[i,i] != 0.0

References begin_row(), end_row(), num_rows(), and UG_ASSERT.

◆ mat_mult_add_row()

template<typename T >
template<typename vector_t >
void ug::MapSparseMatrix< T >::mat_mult_add_row ( size_t  row,
typename vector_t::value_type dest,
double  alpha,
const vector_t &  v 
) const
inline

calculates dest += alpha * A[row, .] v;

References alpha, begin_row(), end_row(), and ug::MatMultAdd().

◆ matmul_minus()

template<typename TValueType >
template<typename Vector_type >
bool ug::MapSparseMatrix< TValueType >::matmul_minus ( Vector_type &  res,
const Vector_type &  x 
) const
inline

calculate res -= A x

References ug::MapSparseMatrix< TValueType >::axpy().

◆ num_cols()

template<typename TValueType >
size_t ug::MapSparseMatrix< TValueType >::num_cols ( ) const
inline

◆ num_connections()

template<typename TValueType >
size_t ug::MapSparseMatrix< TValueType >::num_connections ( size_t  i) const
inline

returns number of connections of row row.

References ug::MapSparseMatrix< TValueType >::data.

Referenced by ug::MapSparseMatrix< TValueType >::total_num_connections().

◆ num_rows()

template<typename TValueType >
size_t ug::MapSparseMatrix< TValueType >::num_rows ( ) const
inline

◆ operator()() [1/2]

template<typename TValueType >
value_type& ug::MapSparseMatrix< TValueType >::operator() ( size_t  r,
size_t  c 
)
inline

operator() (size_t r, size_t c) const access or create connection (r, c)

Parameters
rrow
ccolumn
Note
(r,c) is added to sparsity pattern if not already there use operator()(r,c,bConnectionFound) to prevent
Returns
SparseMat(r, c)=0.0 if connection created, otherwise SparseMat(r, c)

References ug::MapSparseMatrix< TValueType >::data.

◆ operator()() [2/2]

template<typename TValueType >
const value_type& ug::MapSparseMatrix< TValueType >::operator() ( size_t  r,
size_t  c 
) const
inline

operator() (size_t r, size_t c) const access connection (r, c)

Parameters
rrow
ccolumn
Note
if connection (r, c) is not there, returns 0.0
Returns
SparseMat(r, c)

References ug::MapSparseMatrix< TValueType >::data.

◆ operator*=()

template<typename TValueType >
SparseMatrix<value_type>& ug::MapSparseMatrix< TValueType >::operator*= ( double  d)
inline

◆ operator=()

template<typename TValueType >
SparseMatrix<value_type>& ug::MapSparseMatrix< TValueType >::operator= ( const SparseMatrix< value_type > &  B)
inline

◆ p()

template<typename TValueType >
void ug::MapSparseMatrix< TValueType >::p ( ) const
inline

◆ pr()

template<typename TValueType >
void ug::MapSparseMatrix< TValueType >::pr ( size_t  row) const
inline

◆ print()

template<typename T >
void ug::MapSparseMatrix< T >::print ( const char *const  text = NULL) const

print to console whole SparseMatrix

References num_cols(), num_rows(), and UG_LOG.

Referenced by ug::MapSparseMatrix< TValueType >::p().

◆ print_to_file()

template<typename TValueType >
void ug::MapSparseMatrix< TValueType >::print_to_file ( const char *  filename) const

◆ printrow()

template<typename T >
void ug::MapSparseMatrix< T >::printrow ( size_t  row) const

print the row row to the console

References begin_row(), end_row(), and UG_LOG.

Referenced by ug::MapSparseMatrix< TValueType >::pr().

◆ printtype()

template<typename T >
void ug::MapSparseMatrix< T >::printtype

◆ resize()

template<typename T >
bool ug::MapSparseMatrix< T >::resize ( size_t  newRows,
size_t  newCols 
)

resizes the SparseMatrix

Parameters
newRowsnew nr of rows
newColsnew nr of cols
Returns

References PROFILE_BEGIN_GROUP.

◆ scale()

template<typename T >
bool ug::MapSparseMatrix< T >::scale ( double  d)

◆ set() [1/2]

template<typename TValueType >
template<typename M >
void ug::MapSparseMatrix< TValueType >::set ( const M &  mat)

set local matrix

See also
add

◆ set() [2/2]

template<typename T >
bool ug::MapSparseMatrix< T >::set ( double  a)

set matrix to Id*a

References begin_row(), end_row(), num_rows(), and PROFILE_BEGIN_GROUP.

◆ set_as_copy_of()

template<typename TValueType >
bool ug::MapSparseMatrix< T >::set_as_copy_of ( const MapSparseMatrix< value_type > &  B,
double  scale = 1.0 
)

◆ set_as_transpose_of()

template<typename T >
bool ug::MapSparseMatrix< 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.

Parameters
Bthe matrix of which to create the transpose of
scalean optional scaling
Returns
true on success

References ug::SparseMatrix< TValueType >::begin_row(), ug::SparseMatrix< TValueType >::end_row(), ug::SparseMatrix< TValueType >::num_cols(), ug::SparseMatrix< TValueType >::num_rows(), operator()(), PROFILE_BEGIN_GROUP, and resize().

◆ set_matrix_row()

template<typename T >
void ug::MapSparseMatrix< 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 (

See also
add_matrix_row).
Parameters
rowindex of the row to set
cpointer to a array of sorted connections of size nr
nrnumber of connections in c
Remarks
will sort array c

References ug::MapSparseMatrix< TValueType >::connection::iIndex, and PROFILE_BEGIN_GROUP.

◆ total_num_connections()

template<typename TValueType >
size_t ug::MapSparseMatrix< TValueType >::total_num_connections ( ) const
inline

Friends And Related Function Documentation

◆ operator<<

template<typename TValueType >
std::ostream& operator<< ( std::ostream &  out,
const MapSparseMatrix< TValueType > &  m 
)
friend

Member Data Documentation

◆ cols

template<typename TValueType >
size_t ug::MapSparseMatrix< TValueType >::cols
protected

◆ data


The documentation for this class was generated from the following files: