45 #ifndef __H__UG__COMMON__DENSEMATRIX_IMPL_H__
46 #define __H__UG__COMMON__DENSEMATRIX_IMPL_H__
49 #include "../blocks.h"
55 template<
typename TStorage>
60 template<
typename TStorage>
65 template<
typename TStorage>
74 template<
typename TStorage>
79 for(
size_t r1=0; r1<t.
num_rows(); r1++)
80 for(
size_t c1=0; c1<t.
num_cols(); c1++)
81 entry(r1, c1) = t(r1, c1);
85 template<
typename TStorage>
90 resize(t.num_rows(), t.num_cols());
91 for(
size_t r1=0; r1<t.num_rows(); r1++)
92 for(
size_t c1=0; c1<t.num_cols(); c1++)
93 entry(r1, c1) = t(r1, c1);
97 template<
typename TStorage>
107 if(r==c) entry(r, c) = rhs;
108 else entry(r, c) = 0.0;
114 template<
typename TStorage>
115 template<
typename T2>
116 DenseMatrix<TStorage> &
120 for(
size_t r1=0; r1<t.num_rows(); r1++)
121 for(
size_t c1=0; c1<t.num_cols(); c1++)
122 entry(r1, c1) += t(r1, c1);
126 template<
typename TStorage>
131 for(
size_t i=0; i<minimum; i++)
132 entry(i, i) +=
alpha;
138 template<
typename TStorage>
139 template<
typename T2>
144 for(
size_t r1=0; r1<t.num_rows(); r1++)
145 for(
size_t c1=0; c1<t.num_cols(); c1++)
146 entry(r1, c1) -= t(r1, c1);
150 template<
typename TStorage>
156 entry(r, c) -=
alpha;
162 template<
typename TStorage>
168 entry(r, c) *=
alpha;
172 template<
typename TStorage>
176 operator=(
operator*(mat));
181 template<
typename TStorage>
187 entry(r, c) /=
alpha;
191 template<
typename TStorage>
196 bool success =
Invert(tmp);
198 (*this) = (*this) * tmp;
204 template<
typename TStorage>
213 erg(r, c) = entry(r, c) + other(r,c);
217 template<
typename TStorage>
227 erg(r, c) = entry(r, c) - other(r,c);
232 template<
typename TStorage>
238 for(
size_t r=0; r <
num_rows(); r++)
239 for(
size_t c=0; c <
num_cols(); c++)
241 erg(r,c) = entry(r, c);
249 template<
typename TStorage>
257 erg.resize(
num_rows(), other.num_cols());
259 for(
size_t r=0; r <
num_rows(); r++)
260 for(
size_t c=0; c < other.num_cols(); c++)
263 for(
size_t i=0; i <
num_cols(); i++)
264 AddMult(erg(r,c), at(r, i), other.at(i, c));
270 template<
typename TStorage>
276 for(
size_t r=0; r <
num_rows(); r++)
277 for(
size_t c=0; c <
num_cols(); c++)
278 erg(r,c) = entry(c, r);
282 template<
typename TStorage>
283 template<
typename TStorage2>
291 for(
size_t r=0; r <
num_rows(); r++)
294 for(
size_t c=0; c <
num_cols(); c++)
295 erg[r] += at(r,c) * vec[c];
300 template<
typename TStorage>
307 for(
size_t r=0; r <
num_rows(); r++)
308 for(
size_t c=0; c <
num_cols(); c++)
309 erg(r,c) = at(r,c)*
alpha;
316 template<
typename TStorage>
323 return (*
this) * tmp;
328 template<
typename TStorage>
337 if(entry(r,c) != t)
return false;
340 if(entry(r,c) != 0.0)
return false;
345 template<
typename TStorage>
346 template<
typename TStorage2>
352 if(entry(r,c) != t(r,c))
return false;
357 template<
typename TStorage>
358 template<
typename T2>
364 template<
typename TStorage>
371 template<
typename TStorage>
375 typedef size_t size_type;
376 for(size_type r=0; r<mat.num_rows(); ++r)
378 for(size_type c=0; c<mat.num_cols(); ++c)
379 out << mat(r, c) <<
" ";
380 if(r != mat.num_rows()-1) out <<
"| ";
389 template<
size_t Tr,
size_t Tc>
394 buff.write((
char*)&mat,
sizeof(mat));
398 template<
size_t Tr,
size_t Tc>
403 buff.read((
char*)&mat,
sizeof(mat));
413 size_t rows = mat.num_rows();
414 size_t cols = mat.num_cols();
415 buff.write((
char*)&rows,
sizeof(rows));
416 buff.write((
char*)&cols,
sizeof(cols));
417 for(
size_t r=0; r<rows; r++)
418 for(
size_t c=0; c<cols; c++)
429 buff.read((
char*)&rows,
sizeof(rows));
430 buff.read((
char*)&cols,
sizeof(cols));
431 mat.resize(rows, cols);
432 for(
size_t r=0; r<rows; r++)
433 for(
size_t c=0; c<cols; c++)
437 template<
typename T >
440 for(
size_t r=0; r<m.num_rows(); r++)
441 for(
size_t c=0; c<m.num_cols(); c++)
location name
Definition: checkpoint_util.lua:128
Definition: densematrix.h:57
this_type & operator+=(const T &t)
bool operator!=(const TStorage2 &t) const
this_type & operator-=(const T &t)
this_type & operator*=(double alpha)
Definition: densematrix_impl.h:164
this_type & operator/=(double alpha)
Definition: densematrix_impl.h:183
void maple_print(const char *name)
Definition: densematrix_impl.h:365
bool operator==(double t) const
Definition: densematrix_impl.h:330
this_type operator/(this_type &other)
Definition: densematrix_impl.h:318
DenseMatrix()
Definition: densematrix_impl.h:56
DenseVector< TStorage2 > operator*(const DenseVector< TStorage2 > &vec) const
Definition: densematrix_impl.h:285
this_type T() const
Definition: densematrix_impl.h:272
this_type operator-() const
Definition: densematrix_impl.h:234
this_type & operator=(const this_type &t)
Definition: densematrix_impl.h:76
this_type operator+(const this_type &other) const
Definition: densematrix_impl.h:206
Definition: densevector.h:101
Definition: fixed_array.h:135
Definition: variable_array.h:139
size_type num_rows() const
Definition: variable_array_impl.h:222
size_type num_cols() const
Definition: variable_array_impl.h:229
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_LOG(msg)
Definition: log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
bool operator==(const MathVector< N, T > &v, const MathVector< N, T > &w)
Definition: math_vector.h:523
bool BlockSerialize(const DenseMatrix< FixedArray2< number, Tr, Tc > > &mat, std::ostream &buff)
Definition: densematrix_impl.h:392
std::string MatlabString(const DenseMatrix< TStorage > &A, const char *name)
Definition: print.h:65
bool BlockDeserialize(std::istream &buff, const DenseMatrix< FixedArray2< number, Tr, Tc > > &mat)
Definition: densematrix_impl.h:401
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
bool IsFiniteAndNotTooBig(double d)
Definition: number_util.h:39
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103
void AddMult(A &dest, const B &b, const C &vec)
bool resize(size_t newRows, size_t newCols)
size_t num_rows() const
Definition: sparsematrix_interface.h:38
size_t num_cols() const
Definition: sparsematrix_interface.h:39