Matrix_SymComplexSparseInline.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_SYMCOMPLEXSPARSE_INLINE_CXX
22 
23 #include "Matrix_SymComplexSparse.hxx"
24 
25 namespace Seldon
26 {
27 
28  /**************
29  * DESTRUCTOR *
30  **************/
31 
32 
34  template <class T, class Prop, class Storage, class Allocator>
37  {
38  this->Clear();
39  }
40 
41 
42  /*******************
43  * BASIC FUNCTIONS *
44  *******************/
45 
46 
48 
54  template <class T, class Prop, class Storage, class Allocator>
57  {
58  return real_nz_ + imag_nz_;
59  }
60 
61 
63 
69  template <class T, class Prop, class Storage, class Allocator>
72  {
73  return real_nz_ + imag_nz_;
74  }
75 
76 
78 
82  template <class T, class Prop, class Storage, class Allocator>
85  {
86  return real_ptr_;
87  }
88 
89 
91 
95  template <class T, class Prop, class Storage, class Allocator>
98  {
99  return imag_ptr_;
100  }
101 
102 
104 
111  template <class T, class Prop, class Storage, class Allocator>
114  {
115  return real_ind_;
116  }
117 
118 
121 
128  template <class T, class Prop, class Storage, class Allocator>
131  {
132  return imag_ind_;
133  }
134 
135 
137 
140  template <class T, class Prop, class Storage, class Allocator>
143  {
144  return (this->m_ + 1);
145  }
146 
147 
149 
152  template <class T, class Prop, class Storage, class Allocator>
155  {
156  return (this->m_ + 1);
157  }
158 
159 
162 
172  template <class T, class Prop, class Storage, class Allocator>
175  {
176  return real_nz_;
177  }
178 
179 
182 
192  template <class T, class Prop, class Storage, class Allocator>
195  {
196  return imag_nz_;
197  }
198 
199 
202 
212  template <class T, class Prop, class Storage, class Allocator>
215  {
216  return real_nz_;
217  }
218 
219 
222 
232  template <class T, class Prop, class Storage, class Allocator>
235  {
236  return imag_nz_;
237  }
238 
239 
241 
244  template <class T, class Prop, class Storage, class Allocator>
245  inline typename Allocator::value_type*
247  {
248  return real_data_;
249  }
250 
251 
253 
256  template <class T, class Prop, class Storage, class Allocator>
257  inline typename Allocator::value_type*
259  {
260  return imag_data_;
261  }
262 
263 
264  /**********************************
265  * ELEMENT ACCESS AND AFFECTATION *
266  **********************************/
267 
268 
270 
277  template <class T, class Prop, class Storage, class Allocator>
279  ::value_type&
281  {
282  return ValReal(i, j);
283  }
284 
285 
287 
294  template <class T, class Prop, class Storage, class Allocator>
296  ::value_type&
298  {
299  return ValImag(i, j);
300  }
301 
302 
304 
311  template <class T, class Prop, class Storage, class Allocator>
313  ::AddInteraction(int i, int j, const entry_type& val)
314  {
315  if (i <= j)
316  {
317  if (real(val) != value_type(0))
318  GetReal(i, j) += real(val);
319 
320  if (imag(val) != value_type(0))
321  GetImag(i, j) += imag(val);
322  }
323  }
324 
325 
327  template <class T, class Prop, class Storage, class Allocator>
329  ::AddInteractionRow(int i, int nb, const Vector<int>& col,
330  const Vector<entry_type>& val, bool sorted)
331  {
332  throw Undefined("AddInteractionRow", "Not implemented");
333  }
334 
335 
337 
342  template <class T, class Prop, class Storage, class Allocator>
344  ::Set(int i, int j, const entry_type& val)
345  {
346  GetReal(i, j) = real(val);
347  GetImag(i, j) = imag(val);
348  }
349 
350 
352 
357  template <class T, class Prop, class Storage, class Allocator>
361  {
362  this->Copy(A);
363 
364  return *this;
365  }
366 
367 
368 #ifdef SELDON_WITH_VIRTUAL
369  template <class T, class Prop, class Storage, class Allocator>
371  ::ApplySor(const SeldonTranspose& trans, Vector<Treal>& x, const Vector<Treal>& r,
372  const typename ClassComplexType<T>::Treal& omega,
373  int nb_iter, int stage_ssor) const
374  {
375  SOR(trans, static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
376  x, r, omega, nb_iter, stage_ssor);
377  }
378 
379  template <class T, class Prop, class Storage, class Allocator>
380  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
381  ::ApplySor(const SeldonTranspose& trans, Vector<Tcplx>& x, const Vector<Tcplx>& r,
382  const typename ClassComplexType<T>::Treal& omega,
383  int nb_iter, int stage_ssor) const
384  {
385  SOR(trans,
386  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
387  x, r, omega, nb_iter, stage_ssor);
388  }
389 
390  template <class T, class Prop, class Storage, class Allocator>
391  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
392  ::MltAddVector(const Treal& alpha, const Vector<Treal>& x,
393  const Treal& beta, Vector<Treal>& y) const
394  {
395  cout << "Not defined for real numbers" << endl;
396  abort();
397  }
398 
399  template <class T, class Prop, class Storage, class Allocator>
400  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
401  ::MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
402  const Tcplx& beta, Vector<Tcplx>& y) const
403  {
404  MltAdd(alpha,
405  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
406  x, beta, y);
407  }
408 
409  template <class T, class Prop, class Storage, class Allocator>
410  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
411  ::MltAddVector(const Treal& alpha, const SeldonTranspose& trans,
412  const Vector<Treal>& x,
413  const Treal& beta, Vector<Treal>& y) const
414  {
415  cout << "Not defined for real numbers" << endl;
416  abort();
417  }
418 
419  template <class T, class Prop, class Storage, class Allocator>
420  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
421  ::MltAddVector(const Tcplx& alpha, const SeldonTranspose& trans,
422  const Vector<Tcplx>& x,
423  const Tcplx& beta, Vector<Tcplx>& y) const
424  {
425  MltAdd(alpha, trans,
426  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
427  x, beta, y);
428  }
429 
430  template <class T, class Prop, class Storage, class Allocator>
431  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
432  ::MltVector(const Vector<Treal>& x, Vector<Treal>& y) const
433  {
434  cout << "Not defined for real numbers" << endl;
435  abort();
436  }
437 
438  template <class T, class Prop, class Storage, class Allocator>
439  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
440  ::MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const
441  {
442  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
443  }
444 
445  template <class T, class Prop, class Storage, class Allocator>
446  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
447  ::MltVector(const SeldonTranspose& trans,
448  const Vector<Treal>& x, Vector<Treal>& y) const
449  {
450  cout << "Not defined for real numbers" << endl;
451  abort();
452  }
453 
454  template <class T, class Prop, class Storage, class Allocator>
455  inline void Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
456  ::MltVector(const SeldonTranspose& trans,
457  const Vector<Tcplx>& x, Vector<Tcplx>& y) const
458  {
459  Mlt(trans,
460  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
461  }
462 
463  template <class T, class Prop, class Storage, class Allocator>
464  inline bool Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
465  ::IsSymmetric() const
466  {
467  return true;
468  }
469 #endif
470 
471 
473  // MATRIX<COLSYMCOMPLEXSPARSE> //
475 
476 
477  /****************
478  * CONSTRUCTORS *
479  ****************/
480 
482 
485  template <class T, class Prop, class Allocator>
487  Matrix_SymComplexSparse<T, Prop, ColSymComplexSparse, Allocator>()
488  {
489  }
490 
491 
493 
497  template <class T, class Prop, class Allocator>
499  ::Matrix(int i, int j):
500  Matrix_SymComplexSparse<T, Prop, ColSymComplexSparse, Allocator>(i, j,
501  0, 0)
502  {
503  }
504 
505 
507 
518  template <class T, class Prop, class Allocator> inline
520  long real_nz,
521  long imag_nz):
522  Matrix_SymComplexSparse<T, Prop,
523  ColSymComplexSparse, Allocator>(i, j,
524  real_nz, imag_nz)
525  {
526  }
527 
528 
530 
549  template <class T, class Prop, class Allocator>
550  template <class Storage0, class Allocator0,
551  class Storage1, class Allocator1,
552  class Storage2, class Allocator2>
554  Matrix(int i, int j,
561  Matrix_SymComplexSparse<T, Prop,
562  ColSymComplexSparse, Allocator>(i, j,
563  real_values,
564  real_ptr,
565  real_ind,
566  imag_values,
567  imag_ptr,
568  imag_ind)
569  {
570  }
571 
572 
573 
575  // MATRIX<ROWSYMCOMPLEXSPARSE> //
577 
578 
579  /****************
580  * CONSTRUCTORS *
581  ****************/
582 
584 
587  template <class T, class Prop, class Allocator>
589  Matrix_SymComplexSparse<T, Prop, RowSymComplexSparse, Allocator>()
590  {
591  }
592 
593 
595 
599  template <class T, class Prop, class Allocator>
601  ::Matrix(int i, int j):
602  Matrix_SymComplexSparse<T, Prop, RowSymComplexSparse, Allocator>(i, j,
603  0, 0)
604  {
605  }
606 
607 
619  template <class T, class Prop, class Allocator>
621  ::Matrix(int i, int j, long real_nz, long imag_nz):
622  Matrix_SymComplexSparse<T, Prop, RowSymComplexSparse, Allocator>(i, j,
623  real_nz,
624  imag_nz)
625  {
626  }
627 
628 
630 
649  template <class T, class Prop, class Allocator>
650  template <class Storage0, class Allocator0,
651  class Storage1, class Allocator1,
652  class Storage2, class Allocator2>
654  Matrix(int i, int j,
661  Matrix_SymComplexSparse<T, Prop,
662  RowSymComplexSparse, Allocator>(i, j,
663  real_values,
664  real_ptr,
665  real_ind,
666  imag_values,
667  imag_ptr,
668  imag_ind)
669  {
670  }
671 
672 } // namespace Seldon.
673 
674 #define SELDON_FILE_MATRIX_SYMCOMPLEXSPARSE_INLINE_CXX
675 #endif
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_SymComplexSparse::AddInteractionRow
void AddInteractionRow(int i, int nb, const IVect &col, const Vector< entry_type > &val, bool sorted=false)
Adds values to several non-zero entries on a given row.
Definition: Matrix_SymComplexSparseInline.cxx:329
Seldon::Matrix_SymComplexSparse::GetRealInd
int * GetRealInd() const
Returns (row or column) indices of non-zero entries for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:113
Seldon::Vector< int >
Seldon::Matrix_SymComplexSparse::GetRealPtr
long * GetRealPtr() const
Returns (row or column) start indices for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:84
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix_SymComplexSparse::GetNonZeros
long GetNonZeros() const
Returns the number of elements stored in memory.
Definition: Matrix_SymComplexSparseInline.cxx:56
Seldon::RowSymComplexSparse
Definition: Storage.hxx:436
Seldon::Matrix_SymComplexSparse::operator=
Matrix_SymComplexSparse< T, Prop, Storage, Allocator > & operator=(const Matrix_SymComplexSparse< T, Prop, Storage, Allocator > &A)
Duplicates a matrix (assignment operator).
Definition: Matrix_SymComplexSparseInline.cxx:360
Seldon::Matrix_SymComplexSparse::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: Matrix_SymComplexSparseInline.cxx:71
Seldon::Matrix_SymComplexSparse
Symmetric complex sparse-matrix class.
Definition: Matrix_SymComplexSparse.hxx:113
Seldon::Undefined
Definition: Errors.hxx:62
Seldon::Matrix_SymComplexSparse::GetReal
value_type & GetReal(int i, int j)
Access method.
Definition: Matrix_SymComplexSparse.cxx:2104
Seldon::Matrix_SymComplexSparse::GetImagIndSize
long GetImagIndSize() const
Returns the length of the array of (column or row) indices for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:194
Seldon::Matrix_SymComplexSparse::AddInteraction
void AddInteraction(int i, int j, const entry_type &x)
Add a value to a non-zero entry.
Definition: Matrix_SymComplexSparseInline.cxx:313
Seldon::Matrix_SymComplexSparse::GetRealIndSize
long GetRealIndSize() const
Returns the length of the array of (column or row) indices for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:174
Seldon::Matrix_SymComplexSparse::GetImagPtr
long * GetImagPtr() const
Returns (row or column) start indices for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:97
Seldon::Matrix_SymComplexSparse::Set
void Set(int i, int j, const entry_type &x)
Sets an element (i, j) to a value.
Definition: Matrix_SymComplexSparseInline.cxx:344
Seldon::Matrix_SymComplexSparse::GetImagPtrSize
int GetImagPtrSize() const
Returns the length of the array of start indices for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:154
Seldon::Matrix_SymComplexSparse::GetRealPtrSize
int GetRealPtrSize() const
Returns the length of the array of start indices for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:142
Seldon::Matrix_SymComplexSparse::GetImagData
value_type * GetImagData() const
Returns the array of values of the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:258
Seldon::Matrix_SymComplexSparse::GetImagInd
int * GetImagInd() const
Returns (row or column) indices of non-zero entries for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:130
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Matrix_SymComplexSparse::GetImag
value_type & GetImag(int i, int j)
Access method.
Definition: Matrix_SymComplexSparse.cxx:2177
Seldon::Matrix_SymComplexSparse::GetRealDataSize
long GetRealDataSize() const
Returns the length of the array of (column or row) indices for the real part.
Definition: Matrix_SymComplexSparseInline.cxx:214
Seldon::Matrix_SymComplexSparse::~Matrix_SymComplexSparse
~Matrix_SymComplexSparse()
Destructor.
Definition: Matrix_SymComplexSparseInline.cxx:36
Seldon::ColSymComplexSparse
Definition: Storage.hxx:426
Seldon::Matrix_SymComplexSparse::GetRealData
value_type * GetRealData() const
Returns the array of values of the real part.
Definition: Matrix_SymComplexSparseInline.cxx:246
Seldon::Matrix_SymComplexSparse::GetImagDataSize
long GetImagDataSize() const
Returns the length of the array of (column or row) indices for the imaginary part.
Definition: Matrix_SymComplexSparseInline.cxx:234