Matrix_SymSparseInline.cxx
1 // Copyright (C) 2001-2011 Vivien Mallet
2 // Copyright (C) 2003-2011 Marc DuruflĂ©
3 //
4 // This file is part of the linear-algebra library Seldon,
5 // http://seldon.sourceforge.net/.
6 //
7 // Seldon is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your option)
10 // any later version.
11 //
12 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with Seldon. If not, see http://www.gnu.org/licenses/.
19 
20 
21 #ifndef SELDON_FILE_MATRIX_SYMSPARSE_INLINE_CXX
22 
23 #include "Matrix_SymSparse.hxx"
24 
25 namespace Seldon
26 {
27 
28 
29  /****************
30  * CONSTRUCTORS *
31  ****************/
32 
33 
35 
38  template <class T, class Prop, class Storage, class Allocator>
40  Matrix_Base<T, Allocator>()
41  {
42  nz_ = 0;
43  ptr_ = NULL;
44  ind_ = NULL;
45  }
46 
47 
49 
55  template <class T, class Prop, class Storage, class Allocator>
57  ::Matrix_SymSparse(int i, int j): Matrix_Base<T, Allocator>()
58  {
59  nz_ = 0;
60  ptr_ = NULL;
61  ind_ = NULL;
62 
63  Reallocate(i, j);
64  }
65 
66 
68 
77  template <class T, class Prop, class Storage, class Allocator>
79  Matrix_SymSparse(int i, int j, long nz):
80  Matrix_Base<T, Allocator>()
81  {
82  this->nz_ = 0;
83  ind_ = NULL;
84  ptr_ = NULL;
85 
86  Reallocate(i, j, nz);
87  }
88 
89 
90  /**************
91  * DESTRUCTOR *
92  **************/
93 
94 
96  template <class T, class Prop, class Storage, class Allocator>
98  {
99  this->Clear();
100  }
101 
102 
103  /*******************
104  * BASIC FUNCTIONS *
105  *******************/
106 
107 
109 
113  template <class T, class Prop, class Storage, class Allocator>
115  {
116  return nz_;
117  }
118 
119 
121 
125  template <class T, class Prop, class Storage, class Allocator>
127  {
128  return nz_;
129  }
130 
131 
133 
137  template <class T, class Prop, class Storage, class Allocator>
139  {
140  return ptr_;
141  }
142 
143 
145 
152  template <class T, class Prop, class Storage, class Allocator>
154  {
155  return ind_;
156  }
157 
158 
160 
163  template <class T, class Prop, class Storage, class Allocator>
165  {
166  return (this->m_ + 1);
167  }
168 
169 
171 
180  template <class T, class Prop, class Storage, class Allocator>
182  {
183  return nz_;
184  }
185 
186 
187  /**********************************
188  * ELEMENT ACCESS AND AFFECTATION *
189  **********************************/
190 
191 
193 
198  template <class T, class Prop, class Storage, class Allocator>
199  inline const typename Matrix_SymSparse<T, Prop, Storage, Allocator>::value_type&
201  {
202  return Val(i, j);
203  }
204 
205 
207 
214  template <class T, class Prop, class Storage, class Allocator>
216  ::AddInteraction(int i, int j, const T& val)
217  {
218  if (i <= j)
219  Get(i, j) += val;
220  }
221 
222 
224  template <class T, class Prop, class Storage, class Allocator>
226  ::AddInteractionRow(int i, int nb, const Vector<int>& col,
227  const Vector<T>& val, bool sorted)
228  {
229  throw Undefined("AddInteractionRow", "Not implemented");
230  }
231 
232 
234 
239  template <class T, class Prop, class Storage, class Allocator>
241  ::Set(int i, int j, const T& val)
242  {
243  Get(i, j) = val;
244  }
245 
246 
248 
253  template <class T, class Prop, class Storage, class Allocator>
255  ::SetEntry(int i, int j, const T& val)
256  {
257  Get(i, j) = val;
258  }
259 
260 
262 
267  template <class T, class Prop, class Storage, class Allocator>
271  {
272  this->Copy(A);
273 
274  return *this;
275  }
276 
277 
278 #ifdef SELDON_WITH_VIRTUAL
279  template <class T, class Prop, class Storage, class Allocator>
281  ::ApplySor(const SeldonTranspose& trans, Vector<Treal>& x, const Vector<Treal>& r,
282  const typename ClassComplexType<T>::Treal& omega,
283  int nb_iter, int stage_ssor) const
284  {
285  SOR(trans, static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
286  x, r, omega, nb_iter, stage_ssor);
287  }
288 
289  template <class T, class Prop, class Storage, class Allocator>
290  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
291  ::ApplySor(const SeldonTranspose& trans, Vector<Tcplx>& x, const Vector<Tcplx>& r,
292  const typename ClassComplexType<T>::Treal& omega,
293  int nb_iter, int stage_ssor) const
294  {
295  SOR(trans,
296  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
297  x, r, omega, nb_iter, stage_ssor);
298  }
299 
300  template <class T, class Prop, class Storage, class Allocator>
301  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
302  ::MltAddVector(const Treal& alpha, const Vector<Treal>& x,
303  const Treal& beta, Vector<Treal>& y) const
304  {
305  MltAdd(alpha,
306  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
307  x, beta, y);
308  }
309 
310  template <class T, class Prop, class Storage, class Allocator>
311  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
312  ::MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
313  const Tcplx& beta, Vector<Tcplx>& y) const
314  {
315  MltAdd(alpha,
316  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
317  x, beta, y);
318  }
319 
320  template <class T, class Prop, class Storage, class Allocator>
321  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
322  ::MltAddVector(const Treal& alpha, const SeldonTranspose& trans,
323  const Vector<Treal>& x,
324  const Treal& beta, Vector<Treal>& y) const
325  {
326  MltAdd(alpha, trans,
327  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
328  x, beta, y);
329  }
330 
331  template <class T, class Prop, class Storage, class Allocator>
332  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
333  ::MltAddVector(const Tcplx& alpha, const SeldonTranspose& trans,
334  const Vector<Tcplx>& x,
335  const Tcplx& beta, Vector<Tcplx>& y) const
336  {
337  MltAdd(alpha, trans,
338  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
339  x, beta, y);
340  }
341 
342  template <class T, class Prop, class Storage, class Allocator>
343  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
344  ::MltVector(const Vector<Treal>& x, Vector<Treal>& y) const
345  {
346  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
347  }
348 
349  template <class T, class Prop, class Storage, class Allocator>
350  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
351  ::MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const
352  {
353  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
354  }
355 
356  template <class T, class Prop, class Storage, class Allocator>
357  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
358  ::MltVector(const SeldonTranspose& trans,
359  const Vector<Treal>& x, Vector<Treal>& y) const
360  {
361  Mlt(trans,
362  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
363  }
364 
365  template <class T, class Prop, class Storage, class Allocator>
366  inline void Matrix_SymSparse<T, Prop, Storage, Allocator>
367  ::MltVector(const SeldonTranspose& trans,
368  const Vector<Tcplx>& x, Vector<Tcplx>& y) const
369  {
370  Mlt(trans,
371  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
372  }
373 
374  template <class T, class Prop, class Storage, class Allocator>
375  inline bool Matrix_SymSparse<T, Prop, Storage, Allocator>
376  ::IsSymmetric() const
377  {
378  return true;
379  }
380 #endif
381 
382 
384  // MATRIX<COLSYMSPARSE> //
386 
387 
388  /****************
389  * CONSTRUCTORS *
390  ****************/
391 
393 
396  template <class T, class Prop, class Allocator>
398  Matrix_SymSparse<T, Prop, ColSymSparse, Allocator>()
399  {
400  }
401 
402 
404 
408  template <class T, class Prop, class Allocator>
410  Matrix_SymSparse<T, Prop, ColSymSparse, Allocator>(i, j, 0)
411  {
412  }
413 
414 
416 
423  template <class T, class Prop, class Allocator>
425  Matrix_SymSparse<T, Prop, ColSymSparse, Allocator>(i, j, nz)
426  {
427  }
428 
429 
431 
443  template <class T, class Prop, class Allocator>
444  template <class Storage0, class Allocator0,
445  class Storage1, class Allocator1,
446  class Storage2, class Allocator2>
448  Matrix(int i, int j,
452  Matrix_SymSparse<T, Prop, ColSymSparse, Allocator>(i, j, values, ptr, ind)
453  {
454  }
455 
456 
457 
459  // MATRIX<ROWSYMSPARSE> //
461 
462 
463  /****************
464  * CONSTRUCTORS *
465  ****************/
466 
467 
469 
472  template <class T, class Prop, class Allocator>
474  Matrix_SymSparse<T, Prop, RowSymSparse, Allocator>()
475  {
476  }
477 
478 
480 
484  template <class T, class Prop, class Allocator>
486  Matrix_SymSparse<T, Prop, RowSymSparse, Allocator>(i, j, 0)
487  {
488  }
489 
490 
492 
499  template <class T, class Prop, class Allocator>
501  Matrix_SymSparse<T, Prop, RowSymSparse, Allocator>(i, j, nz)
502  {
503  }
504 
505 
507 
519  template <class T, class Prop, class Allocator>
520  template <class Storage0, class Allocator0,
521  class Storage1, class Allocator1,
522  class Storage2, class Allocator2>
524  Matrix(int i, int j,
528  Matrix_SymSparse<T, Prop, RowSymSparse, Allocator>(i, j, values, ptr, ind)
529  {
530  }
531 
532 
533 } // namespace Seldon.
534 
535 #define SELDON_FILE_MATRIX_SYMSPARSE_INLINE_CXX
536 #endif
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Vector< int >
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix_SymSparse
Symmetric sparse-matrix class.
Definition: Matrix_SymSparse.hxx:46
Seldon::ColSymSparse
Definition: Storage.hxx:103
Seldon::Undefined
Definition: Errors.hxx:62
Seldon::Matrix_SymSparse::Matrix_SymSparse
Matrix_SymSparse()
Default constructor.
Definition: Matrix_SymSparseInline.cxx:39
Seldon::RowSymSparse
Definition: Storage.hxx:114
Seldon
Seldon namespace.
Definition: Array.cxx:24