Matrix_ComplexSparseInline.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_COMPLEXSPARSE_INLINE_CXX
22 
23 #include "Matrix_ComplexSparse.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>
56  {
57  return real_nz_ + imag_nz_;
58  }
59 
60 
62 
68  template <class T, class Prop, class Storage, class Allocator>
70  {
71  return real_nz_ + imag_nz_;
72  }
73 
74 
76 
80  template <class T, class Prop, class Storage, class Allocator>
82  {
83  return real_ptr_;
84  }
85 
86 
88 
92  template <class T, class Prop, class Storage, class Allocator>
94  {
95  return imag_ptr_;
96  }
97 
98 
100 
107  template <class T, class Prop, class Storage, class Allocator>
109  {
110  return real_ind_;
111  }
112 
113 
116 
123  template <class T, class Prop, class Storage, class Allocator>
125  {
126  return imag_ind_;
127  }
128 
129 
131 
134  template <class T, class Prop, class Storage, class Allocator>
137  {
138  return (Storage::GetFirst(this->m_, this->n_) + 1);
139  }
140 
141 
143 
146  template <class T, class Prop, class Storage, class Allocator>
149  {
150  return (Storage::GetFirst(this->m_, this->n_) + 1);
151  }
152 
153 
156 
165  template <class T, class Prop, class Storage, class Allocator>
168  {
169  return real_nz_;
170  }
171 
172 
175 
184  template <class T, class Prop, class Storage, class Allocator>
187  {
188  return imag_nz_;
189  }
190 
191 
194 
203  template <class T, class Prop, class Storage, class Allocator>
206  {
207  return real_nz_;
208  }
209 
210 
213 
222  template <class T, class Prop, class Storage, class Allocator>
225  {
226  return imag_nz_;
227  }
228 
229 
231 
234  template <class T, class Prop, class Storage, class Allocator>
235  inline typename Allocator::value_type*
237  {
238  return real_data_;
239  }
240 
241 
243 
246  template <class T, class Prop, class Storage, class Allocator>
247  inline typename Allocator::value_type*
249  {
250  return imag_data_;
251  }
252 
253 
254  /**********************************
255  * ELEMENT ACCESS AND AFFECTATION *
256  **********************************/
257 
258 
260 
267  template <class T, class Prop, class Storage, class Allocator>
269  ::value_type&
271  {
272  return ValReal(i, j);
273  }
274 
275 
277 
284  template <class T, class Prop, class Storage, class Allocator>
286  ::value_type&
288  {
289  return ValImag(i, j);
290  }
291 
292 
294 
301  template <class T, class Prop, class Storage, class Allocator>
303  ::AddInteraction(int i, int j, const entry_type& val)
304  {
305  if (real(val) != value_type(0))
306  GetReal(i, j) += real(val);
307 
308  if (imag(val) != value_type(0))
309  GetImag(i, j) += imag(val);
310  }
311 
312 
314  template <class T, class Prop, class Storage, class Allocator>
316  ::AddInteractionRow(int i, int nb, const Vector<int>& col,
317  const Vector<entry_type>& val, bool sorted)
318  {
319  throw Undefined("AddInteractionRow", "Not implemented");
320  }
321 
322 
324 
329  template <class T, class Prop, class Storage, class Allocator>
331  ::Set(int i, int j, const entry_type& val)
332  {
333  GetReal(i, j) = real(val);
334  GetImag(i, j) = imag(val);
335  }
336 
337 
339 
344  template <class T, class Prop, class Storage, class Allocator>
348  {
349  this->Copy(A);
350 
351  return *this;
352  }
353 
354 
355 #ifdef SELDON_WITH_VIRTUAL
356  template <class T, class Prop, class Storage, class Allocator>
358  ::ApplySor(const SeldonTranspose& trans, Vector<Treal>& x, const Vector<Treal>& r,
359  const typename ClassComplexType<T>::Treal& omega,
360  int nb_iter, int stage_ssor) const
361  {
362  SOR(trans, static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
363  x, r, omega, nb_iter, stage_ssor);
364  }
365 
366  template <class T, class Prop, class Storage, class Allocator>
367  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
368  ::ApplySor(const SeldonTranspose& trans, Vector<Tcplx>& x, const Vector<Tcplx>& r,
369  const typename ClassComplexType<T>::Treal& omega,
370  int nb_iter, int stage_ssor) const
371  {
372  SOR(trans,
373  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
374  x, r, omega, nb_iter, stage_ssor);
375  }
376 
377  template <class T, class Prop, class Storage, class Allocator>
378  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
379  ::MltAddVector(const Treal& alpha, const Vector<Treal>& x,
380  const Treal& beta, Vector<Treal>& y) const
381  {
382  cout << "Not defined for real numbers" << endl;
383  abort();
384  }
385 
386  template <class T, class Prop, class Storage, class Allocator>
387  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
388  ::MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
389  const Tcplx& beta, Vector<Tcplx>& y) const
390  {
391  MltAdd(alpha,
392  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
393  x, beta, y);
394  }
395 
396  template <class T, class Prop, class Storage, class Allocator>
397  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
398  ::MltAddVector(const Treal& alpha, const SeldonTranspose& trans,
399  const Vector<Treal>& x,
400  const Treal& beta, Vector<Treal>& y) const
401  {
402  cout << "Not defined for real numbers" << endl;
403  abort();
404  }
405 
406  template <class T, class Prop, class Storage, class Allocator>
407  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
408  ::MltAddVector(const Tcplx& alpha, const SeldonTranspose& trans,
409  const Vector<Tcplx>& x,
410  const Tcplx& beta, Vector<Tcplx>& y) const
411  {
412  MltAdd(alpha, trans,
413  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
414  x, beta, y);
415  }
416 
417  template <class T, class Prop, class Storage, class Allocator>
418  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
419  ::MltVector(const Vector<Treal>& x, Vector<Treal>& y) const
420  {
421  cout << "Not defined for real numbers" << endl;
422  abort();
423  }
424 
425  template <class T, class Prop, class Storage, class Allocator>
426  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
427  ::MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const
428  {
429  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
430  }
431 
432  template <class T, class Prop, class Storage, class Allocator>
433  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
434  ::MltVector(const SeldonTranspose& trans,
435  const Vector<Treal>& x, Vector<Treal>& y) const
436  {
437  cout << "Not defined for real numbers" << endl;
438  abort();
439  }
440 
441  template <class T, class Prop, class Storage, class Allocator>
442  inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>
443  ::MltVector(const SeldonTranspose& trans,
444  const Vector<Tcplx>& x, Vector<Tcplx>& y) const
445  {
446  Mlt(trans,
447  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
448  }
449 
450  template <class T, class Prop, class Storage, class Allocator>
451  inline bool Matrix_ComplexSparse<T, Prop, Storage, Allocator>
452  ::IsSymmetric() const
453  {
454  return false;
455  }
456 #endif
457 
458 
460  // MATRIX<COLCOMPLEXSPARSE> //
462 
463 
464  /****************
465  * CONSTRUCTORS *
466  ****************/
467 
469 
472  template <class T, class Prop, class Allocator>
474  Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>()
475  {
476  }
477 
478 
480 
484  template <class T, class Prop, class Allocator>
486  Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>(i, j, 0, 0)
487  {
488  }
489 
490 
492 
500  template <class T, class Prop, class Allocator>
502  long real_nz,
503  long imag_nz):
504  Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>(i, j,
505  real_nz,
506  imag_nz)
507  {
508  }
509 
510 
512 
530  template <class T, class Prop, class Allocator>
531  template <class Storage0, class Allocator0,
532  class Storage1, class Allocator1,
533  class Storage2, class Allocator2>
535  Matrix(int i, int j,
542  Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>(i, j,
543  real_values,
544  real_ptr,
545  real_ind,
546  imag_values,
547  imag_ptr,
548  imag_ind)
549  {
550  }
551 
552 
553 
555  // MATRIX<ROWCOMPLEXSPARSE> //
557 
558 
559  /****************
560  * CONSTRUCTORS *
561  ****************/
562 
564 
567  template <class T, class Prop, class Allocator>
569  Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>()
570  {
571  }
572 
573 
575 
579  template <class T, class Prop, class Allocator> inline
581  Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>(i, j, 0, 0)
582  {
583  }
584 
585 
594  template <class T, class Prop, class Allocator> inline
596  long real_nz,
597  long imag_nz):
598  Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>(i, j,
599  real_nz,
600  imag_nz)
601  {
602  }
603 
604 
606 
624  template <class T, class Prop, class Allocator>
625  template <class Storage0, class Allocator0,
626  class Storage1, class Allocator1,
627  class Storage2, class Allocator2>
629  Matrix(int i, int j,
636  Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>(i, j,
637  real_values,
638  real_ptr,
639  real_ind,
640  imag_values,
641  imag_ptr,
642  imag_ind)
643  {
644  }
645 
646 
647 } // namespace Seldon.
648 
649 #define SELDON_FILE_MATRIX_COMPLEXSPARSE_INLINE_CXX
650 #endif
Seldon::Matrix_ComplexSparse::GetImag
value_type & GetImag(int i, int j)
Access method.
Definition: Matrix_ComplexSparse.cxx:2255
Seldon::Matrix_ComplexSparse::GetRealIndSize
long GetRealIndSize() const
Returns the length of the array of (column or row) indices for the real part.
Definition: Matrix_ComplexSparseInline.cxx:167
Seldon::Matrix_ComplexSparse
Complex sparse-matrix class.
Definition: Matrix_ComplexSparse.hxx:112
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_ComplexSparse::~Matrix_ComplexSparse
~Matrix_ComplexSparse()
Destructor.
Definition: Matrix_ComplexSparseInline.cxx:36
Seldon::RowComplexSparse
Definition: Storage.hxx:416
Seldon::Matrix_ComplexSparse::GetRealPtrSize
int GetRealPtrSize() const
Returns the length of the array of start indices for the real part.
Definition: Matrix_ComplexSparseInline.cxx:136
Seldon::Matrix_ComplexSparse::GetImagInd
int * GetImagInd() const
Returns (row or column) indices of non-zero entries for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:124
Seldon::Vector< int >
Seldon::Matrix_ComplexSparse::GetImagData
value_type * GetImagData() const
Returns the array of values of the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:248
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix_ComplexSparse::Set
void Set(int i, int j, const entry_type &x)
Sets an element (i, j) to a value.
Definition: Matrix_ComplexSparseInline.cxx:331
Seldon::Matrix_ComplexSparse::GetImagPtr
long * GetImagPtr() const
Returns (row or column) start indices for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:93
Seldon::ColComplexSparse
Definition: Storage.hxx:406
Seldon::Matrix_ComplexSparse::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: Matrix_ComplexSparseInline.cxx:69
Seldon::Matrix_ComplexSparse::GetRealDataSize
long GetRealDataSize() const
Returns the length of the array of (column or row) indices for the real part.
Definition: Matrix_ComplexSparseInline.cxx:205
Seldon::Matrix_ComplexSparse::GetNonZeros
long GetNonZeros() const
Returns the number of elements stored in memory.
Definition: Matrix_ComplexSparseInline.cxx:55
Seldon::Undefined
Definition: Errors.hxx:62
Seldon::Matrix_ComplexSparse::GetImagPtrSize
int GetImagPtrSize() const
Returns the length of the array of start indices for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:148
Seldon::Matrix_ComplexSparse::AddInteraction
void AddInteraction(int i, int j, const entry_type &x)
Add a value to a non-zero entry.
Definition: Matrix_ComplexSparseInline.cxx:303
Seldon::Matrix_ComplexSparse::GetImagIndSize
long GetImagIndSize() const
Returns the length of the array of (column or row) indices for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:186
Seldon::Matrix_ComplexSparse::GetRealData
value_type * GetRealData() const
Returns the array of values of the real part.
Definition: Matrix_ComplexSparseInline.cxx:236
Seldon::Matrix_ComplexSparse::GetRealPtr
long * GetRealPtr() const
Returns (row or column) start indices for the real part.
Definition: Matrix_ComplexSparseInline.cxx:81
Seldon::Matrix_ComplexSparse::GetReal
value_type & GetReal(int i, int j)
Access method.
Definition: Matrix_ComplexSparse.cxx:2190
Seldon::Matrix_ComplexSparse::GetRealInd
int * GetRealInd() const
Returns (row or column) indices of non-zero entries for the real part.
Definition: Matrix_ComplexSparseInline.cxx:108
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Matrix_ComplexSparse::operator=
Matrix_ComplexSparse< T, Prop, Storage, Allocator > & operator=(const Matrix_ComplexSparse< T, Prop, Storage, Allocator > &A)
Duplicates a matrix (assignment operator).
Definition: Matrix_ComplexSparseInline.cxx:347
Seldon::Matrix_ComplexSparse::GetImagDataSize
long GetImagDataSize() const
Returns the length of the array of (column or row) indices for the imaginary part.
Definition: Matrix_ComplexSparseInline.cxx:224
Seldon::Matrix_ComplexSparse::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_ComplexSparseInline.cxx:316