33 #ifndef __H__UG__MAP_ALGEBRA__SPARSEMATRIX__
34 #define __H__UG__MAP_ALGEBRA__SPARSEMATRIX__
39 #include "../common/operations_mat/operations_mat.h"
71 void print(){std::cout << *
this;}
74 output <<
"(" << c.
iIndex <<
"-> ";
108 bool resize(
size_t newRows,
size_t newCols);
135 template<
typename vector_t>
136 bool axpy(vector_t &dest,
137 const number &alpha1,
const vector_t &v1,
138 const number &beta1,
const vector_t &w1)
const;
141 template<
typename vector_t>
143 const number &alpha1,
const vector_t &v1,
144 const number &beta1,
const vector_t &w1)
const;
150 template<
typename Vector_type>
151 bool apply(Vector_type &res,
const Vector_type &x)
const
153 return axpy(res, 0.0, res, 1.0, x);
158 template<
typename Vector_type>
166 template<
typename Vector_type>
169 return axpy(res, 1.0, res, -1.0, x);
181 bool scale(
double d);
225 typename std::map<size_t, TValueType>::const_iterator it =
data[r].find(c);
226 if(it !=
data[r].end(c))
276 return data[i].size();
280 template<
typename vector_t>
296 for(
size_t i=0; i<
data.size(); i++)
327 typedef typename std::map<size_t, TValueType>::iterator
super;
335 typedef typename std::map<size_t, TValueType>::const_iterator
super;
406 void print(
const char *
const name = NULL)
const;
414 out <<
"MapSparseMatrix "
430 std::vector<std::map<size_t, TValueType> >
data;
442 template<
typename vector_t,
typename matrix_t>
444 const number &alpha1,
const vector_t &v1,
location name
Definition: checkpoint_util.lua:128
Definition: mapsparsematrix.h:334
size_t index() const
Definition: mapsparsematrix.h:339
const_row_iterator(super it)
Definition: mapsparsematrix.h:337
std::map< size_t, TValueType >::const_iterator super
Definition: mapsparsematrix.h:335
const value_type & value()
Definition: mapsparsematrix.h:338
Definition: mapsparsematrix.h:326
size_t index() const
Definition: mapsparsematrix.h:331
std::map< size_t, TValueType >::iterator super
Definition: mapsparsematrix.h:327
value_type & value()
Definition: mapsparsematrix.h:330
row_iterator(super it)
Definition: mapsparsematrix.h:329
sparse matrix for big, variable sparse matrices.
Definition: mapsparsematrix.h:54
void print(const char *const name=NULL) const
Definition: mapsparsematrix_print.h:44
friend std::ostream & operator<<(std::ostream &out, const MapSparseMatrix &m)
Definition: mapsparsematrix.h:412
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)
Definition: mapsparsematrix_impl.h:135
row_iterator get_connection(size_t r, size_t c)
Definition: mapsparsematrix.h:391
SparseMatrix< value_type > this_type
Definition: mapsparsematrix.h:59
void p() const
Definition: mapsparsematrix.h:420
size_t total_num_connections() const
returns the total number of connections
Definition: mapsparsematrix.h:293
bool matmul_minus(Vector_type &res, const Vector_type &x) const
calculate res -= A x
Definition: mapsparsematrix.h:167
bool set_as_copy_of(const MapSparseMatrix< value_type > &B, double scale=1.0)
create/recreate this as a copy of SparseMatrix B
Definition: mapsparsematrix_impl.h:211
size_t num_connections(size_t i) const
returns number of connections of row row.
Definition: mapsparsematrix.h:274
@ rows_sorted
Definition: mapsparsematrix.h:57
void defragment()
Definition: mapsparsematrix.h:397
SparseMatrix< value_type > & operator=(const SparseMatrix< value_type > &B)
Definition: mapsparsematrix.h:126
const_row_iterator end_row(size_t r) const
Definition: mapsparsematrix.h:346
void printtype() const
Definition: mapsparsematrix_print.h:69
const_row_iterator get_connection(size_t r, size_t c, bool &bFound) const
Definition: mapsparsematrix.h:358
size_t cols
Definition: mapsparsematrix.h:431
TValueType value_type
Definition: mapsparsematrix.h:56
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;
Definition: mapsparsematrix_impl.h:80
void set(const M &mat)
set local matrix
void get(M &mat) const
get local matrix
bool resize(size_t newRows, size_t newCols)
resizes the SparseMatrix
Definition: mapsparsematrix_impl.h:57
size_t num_cols() const
returns the number of cols
Definition: mapsparsematrix.h:290
size_t num_rows() const
returns number of rows
Definition: mapsparsematrix.h:287
void print_to_file(const char *filename) const
bool apply_transposed(Vector_type &res, const Vector_type &x) const
calculate res = A.T x
Definition: mapsparsematrix.h:159
virtual ~MapSparseMatrix()
destructor
Definition: mapsparsematrix.h:99
bool is_isolated(size_t i) const
check for isolated condition of an index
Definition: mapsparsematrix_impl.h:182
row_iterator begin_row(size_t r)
Definition: mapsparsematrix.h:343
MapSparseMatrix()
constructor for empty SparseMatrix
Definition: mapsparsematrix_impl.h:52
row_iterator get_connection(size_t r, size_t c, bool &bFound)
Definition: mapsparsematrix.h:369
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)
Definition: mapsparsematrix_impl.h:90
const_row_iterator begin_row(size_t r) const
Definition: mapsparsematrix.h:345
const_row_iterator get_connection(size_t r, size_t c) const
Definition: mapsparsematrix.h:381
const value_type & operator()(size_t r, size_t c) const
Definition: mapsparsematrix.h:223
row_iterator end_row(size_t r)
Definition: mapsparsematrix.h:344
void pr(size_t row) const
Definition: mapsparsematrix.h:421
SparseMatrix< value_type > & operator*=(double d)
Definition: mapsparsematrix.h:182
void printrow(size_t row) const
Definition: mapsparsematrix_print.h:55
std::vector< std::map< size_t, TValueType > > data
Definition: mapsparsematrix.h:430
void set_matrix_row(size_t row, connection *c, size_t nr)
Definition: mapsparsematrix_impl.h:194
void add_matrix_row(size_t row, connection *c, size_t nr)
Definition: mapsparsematrix_impl.h:202
MapSparseMatrix(MapSparseMatrix &)
disallow copy operator
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.
Definition: mapsparsematrix_impl.h:67
bool apply(Vector_type &res, const Vector_type &x) const
calculate res = A x
Definition: mapsparsematrix.h:151
bool scale(double d)
Definition: mapsparsematrix_impl.h:224
sparse matrix for big, variable sparse matrices.
Definition: sparsematrix.h:99
double number
Definition: types.h:124
IndexLayout::Interface::iterator find(IndexLayout::Interface &interface, size_t i)
Definition: parallel_index_layout.h:77
bool MatMultTransposedAdd(vector_t &dest, const number &alpha1, const vector_t &v1, const number &beta1, const matrix_t &A1, const vector_t &w1)
calculates dest = alpha1*v1 + beta1 * A1 *w1;
Definition: operations_mat.h:121
MatVec_Expression< L, R > operator*(const AlphaMat_Expression< L > &l, const R &r)
create a MatVec_Expression by (alpha*MATRIX) * VECTOR
Definition: template_expressions.h:223
@ MATRIX_USE_ROW_FUNCTIONS
Definition: matrix_algebra_types.h:68
T value_type
Definition: sparsematrix_interface.h:2
Definition: mapsparsematrix.h:64
connection()
Definition: mapsparsematrix.h:67
int operator<(const connection &c) const
Definition: mapsparsematrix.h:86
connection(size_t i, const value_type &v)
Definition: mapsparsematrix.h:68
void print()
Definition: mapsparsematrix.h:71
friend std::ostream & operator<<(std::ostream &output, const connection &c)
Definition: mapsparsematrix.h:72
void operator=(const connection &other)
Definition: mapsparsematrix.h:80
size_t iIndex
Definition: mapsparsematrix.h:65
value_type dValue
Definition: mapsparsematrix.h:66
Definition: matrix_algebra_types.h:79
static const int type
Definition: matrix_algebra_types.h:80