Matrix_HermPackedInline.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_HERMPACKED_INLINE_CXX
22 
23 #include "Matrix_HermPacked.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  }
43 
44 
45  /**************
46  * DESTRUCTOR *
47  **************/
48 
49 
51  template <class T, class Prop, class Storage, class Allocator>
53  {
54  Clear();
55  }
56 
57 
58  /*******************
59  * BASIC FUNCTIONS *
60  *******************/
61 
62 
64 
67  template <class T, class Prop, class Storage, class Allocator>
69  {
70  return (long(this->m_) * long(this->m_ + 1)) / 2;
71  }
72 
73 
75  template <class T, class Prop, class Storage, class Allocator>
77  {
78  size_t taille = sizeof(*this) + size_t(GetDataSize())*sizeof(T);
79  return taille;
80  }
81 
82 
83  /**********************************
84  * ELEMENT ACCESS AND AFFECTATION *
85  **********************************/
86 
87 
89 
95  template <class T, class Prop, class Storage, class Allocator>
96  inline const typename
97  Matrix_HermPacked<T, Prop, Storage, Allocator>::value_type
99  ::operator() (int i, int j) const
100  {
101 
102 #ifdef SELDON_CHECK_BOUNDS
103  CheckBounds(i, j, this->m_, this->n_, "Matrix_HermPacked");
104 #endif
105 
106  if (i > j)
107  return conj(this->data_[Storage::GetFirst(j * this->m_
108  - (j*(j+1)) / 2 + i,
109  (i*(i+1)) / 2 + j)]);
110  else
111  return this->data_[Storage::GetFirst(i * this->n_ - (i*(i+1)) / 2 + j,
112  (j*(j+1)) / 2 + i)];
113  }
114 
115 
117 
124  template <class T, class Prop, class Storage, class Allocator>
125  inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>::reference
127  {
128 
129 #ifdef SELDON_CHECK_BOUNDS
130  CheckBoundsSym(i, j, this->m_, this->n_, "Matrix_HermPacked");
131 #endif
132 
133  return this->data_[Storage::GetFirst(i * this->n_ - (i*(i+1)) / 2 + j,
134  (j*(j+1)) / 2 + i)];
135  }
136 
137 
139 
146  template <class T, class Prop, class Storage, class Allocator>
148  ::const_reference
150  {
151 
152 #ifdef SELDON_CHECK_BOUNDS
153  CheckBoundsSym(i, j, this->m_, this->n_, "Matrix_HermPacked");
154 #endif
155 
156  return this->data_[Storage::GetFirst(i * this->n_ - (i*(i+1)) / 2 + j,
157  (j*(j+1)) / 2 + i)];
158  }
159 
160 
162 
167  template <class T, class Prop, class Storage, class Allocator>
168  inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>::reference
170  {
171  return this->Val(i, j);
172  }
173 
174 
176 
181  template <class T, class Prop, class Storage, class Allocator>
183  ::const_reference
185  {
186  return this->Val(i, j);
187  }
188 
189 
191 
196  template <class T, class Prop, class Storage, class Allocator>
197  inline typename Matrix_HermPacked<T, Prop, Storage, Allocator>::reference
199  {
200 
201 #ifdef SELDON_CHECK_BOUNDS
202  CheckBounds(i, this->GetDataSize(), "Matrix_HermPacked");
203 #endif
204 
205  return this->data_[i];
206  }
207 
208 
210 
215  template <class T, class Prop, class Storage, class Allocator>
217  ::const_reference
219  {
220 
221 #ifdef SELDON_CHECK_BOUNDS
222  CheckBounds(i, this->GetDataSize(), "Matrix_HermPacked");
223 #endif
224 
225  return this->data_[i];
226  }
227 
228 
230 
235  template <class T, class Prop, class Storage, class Allocator>
239  {
240  this->Copy(A);
241 
242  return *this;
243  }
244 
245 
247 
252  template <class T, class Prop, class Storage, class Allocator>
254  ::Set(int i, int j, const T& x)
255  {
256  if (i > j)
257  this->Val(j, i) = conj(x);
258  else
259  this->Val(i, j) = x;
260  }
261 
262 
264 
269  template <class T, class Prop, class Storage, class Allocator>
272  {
273  this->Reallocate(A.GetM(), A.GetN());
274 
275  Allocator::memorycpy(this->data_, A.GetData(), this->GetDataSize());
276  }
277 
278 
279 #ifdef SELDON_WITH_VIRTUAL
280  template <class T, class Prop, class Storage, class Allocator>
283  ::AddInteraction(int i, int j, const T& val)
284  {
285  if (i <= j)
286  this->Val(i, j) += val;
287  }
288 
289 
291  template <class T, class Prop, class Storage, class Allocator>
292  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
293  ::AddInteractionRow(int i, int n, const Vector<int>& col,
294  const Vector<T>& val, bool sorted)
295  {
296  for (int k = 0; k < n; k++)
297  if (i <= col(k))
298  this->Val(i, col(k)) += val(k);
299  }
300 
301 
303  template <class T, class Prop, class Storage, class Allocator>
304  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
305  ::AddInteractionColumn(int i, int n, const Vector<int>& row,
306  const Vector<T>& val, bool sorted)
307  {
308  for (int k = 0; k < n; k++)
309  if (row(k) <= i)
310  this->Val(row(k), i) += val(k);
311  }
312 
313 
315  template <class T, class Prop, class Storage, class Allocator>
316  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
317  ::ClearRow(int i)
318  {
319  for (int k = 0; k < this->n_; k++)
320  SetComplexZero(this->Val(i, k));
321  }
322 
323 
324  template <class T, class Prop, class Storage, class Allocator>
325  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
326  ::ApplySor(const SeldonTranspose& trans, Vector<Treal>& x, const Vector<Treal>& r,
327  const typename ClassComplexType<T>::Treal& omega,
328  int nb_iter, int stage_ssor) const
329  {
330  SOR(trans, static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
331  x, r, omega, nb_iter, stage_ssor);
332  }
333 
334  template <class T, class Prop, class Storage, class Allocator>
335  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
336  ::ApplySor(const SeldonTranspose& trans, Vector<Tcplx>& x, const Vector<Tcplx>& r,
337  const typename ClassComplexType<T>::Treal& omega,
338  int nb_iter, int stage_ssor) const
339  {
340  SOR(trans,
341  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
342  x, r, omega, nb_iter, stage_ssor);
343  }
344 
345  template <class T, class Prop, class Storage, class Allocator>
346  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
347  ::MltAddVector(const Treal& alpha, const Vector<Treal>& x,
348  const Treal& beta, Vector<Treal>& y) const
349  {
350  cout << "Not defined for real numbers" << endl;
351  abort();
352  }
353 
354  template <class T, class Prop, class Storage, class Allocator>
355  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
356  ::MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
357  const Tcplx& beta, Vector<Tcplx>& y) const
358  {
359  MltAdd(alpha,
360  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
361  x, beta, y);
362  }
363 
364  template <class T, class Prop, class Storage, class Allocator>
365  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
366  ::MltAddVector(const Treal& alpha, const SeldonTranspose& trans,
367  const Vector<Treal>& x,
368  const Treal& beta, Vector<Treal>& y) const
369  {
370  cout << "Not defined for real numbers" << endl;
371  abort();
372  }
373 
374  template <class T, class Prop, class Storage, class Allocator>
375  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
376  ::MltAddVector(const Tcplx& alpha, const SeldonTranspose& trans,
377  const Vector<Tcplx>& x,
378  const Tcplx& beta, Vector<Tcplx>& y) const
379  {
380  MltAdd(alpha, trans,
381  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
382  x, beta, y);
383  }
384 
385  template <class T, class Prop, class Storage, class Allocator>
386  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
387  ::MltVector(const Vector<Treal>& x, Vector<Treal>& y) const
388  {
389  cout << "Not defined for real numbers" << endl;
390  abort();
391  }
392 
393  template <class T, class Prop, class Storage, class Allocator>
394  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
395  ::MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const
396  {
397  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
398  }
399 
400  template <class T, class Prop, class Storage, class Allocator>
401  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
402  ::MltVector(const SeldonTranspose& trans,
403  const Vector<Treal>& x, Vector<Treal>& y) const
404  {
405  cout << "Not defined for real numbers" << endl;
406  abort();
407  }
408 
409  template <class T, class Prop, class Storage, class Allocator>
410  inline void Matrix_HermPacked<T, Prop, Storage, Allocator>
411  ::MltVector(const SeldonTranspose& trans,
412  const Vector<Tcplx>& x, Vector<Tcplx>& y) const
413  {
414  Mlt(trans,
415  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
416  }
417 
418  template <class T, class Prop, class Storage, class Allocator>
419  inline bool Matrix_HermPacked<T, Prop, Storage, Allocator>
420  ::IsSymmetric() const
421  {
422  return false;
423  }
424 #endif
425 
426 
428  // MATRIX<COLHERMPACKED> //
430 
431 
432  /****************
433  * CONSTRUCTORS *
434  ****************/
435 
436 
438 
441  template <class T, class Prop, class Allocator>
443  Matrix_HermPacked<T, Prop, ColHermPacked, Allocator>()
444  {
445  }
446 
447 
449 
454  template <class T, class Prop, class Allocator>
456  Matrix_HermPacked<T, Prop, ColHermPacked, Allocator>(i, j)
457  {
458  }
459 
460 
461  /*******************
462  * OTHER FUNCTIONS *
463  *******************/
464 
465 
467 
470  template <class T, class Prop, class Allocator>
471  template <class T0>
474  ::operator= (const T0& x)
475  {
476  this->Fill(x);
477 
478  return *this;
479  }
480 
481 
483 
488  template <class T, class Prop, class Allocator>
492  Allocator>& A)
493  {
494  this->Copy(A);
495  return *this;
496  }
497 
498 
499 
501  // MATRIX<ROWHERMPACKED> //
503 
504 
505  /****************
506  * CONSTRUCTORS *
507  ****************/
508 
509 
511 
514  template <class T, class Prop, class Allocator>
516  Matrix_HermPacked<T, Prop, RowHermPacked, Allocator>()
517  {
518  }
519 
520 
522 
527  template <class T, class Prop, class Allocator>
529  Matrix_HermPacked<T, Prop, RowHermPacked, Allocator>(i, j)
530  {
531  }
532 
533 
534  /*******************
535  * OTHER FUNCTIONS *
536  *******************/
537 
538 
540 
543  template <class T, class Prop, class Allocator>
544  template <class T0>
547  ::operator= (const T0& x)
548  {
549  this->Fill(x);
550 
551  return *this;
552  }
553 
554 
556 
561  template <class T, class Prop, class Allocator>
565  Allocator>& A)
566  {
567  this->Copy(A);
568  return *this;
569  }
570 
571 
572 } // namespace Seldon.
573 
574 #define SELDON_FILE_MATRIX_HERMPACKED_INLINE_CXX
575 #endif
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Matrix_HermPacked::Matrix_HermPacked
Matrix_HermPacked()
Default constructor.
Definition: Matrix_HermPackedInline.cxx:39
Seldon::Matrix_HermPacked
Hermitian packed matrix class.
Definition: Matrix_HermPacked.hxx:38
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix< T, Prop, ColHermPacked, Allocator >
Column-major hermitian packed matrix class.
Definition: Matrix_HermPacked.hxx:160
Seldon::Matrix_Base< T, typename SeldonDefaultAllocator< Storage, T >::allocator >::GetData
pointer GetData() const
Returns a pointer to the data array.
Definition: Matrix_BaseInline.cxx:241
Seldon::Matrix< T, Prop, RowHermPacked, Allocator >
Row-major hermitian packed matrix class.
Definition: Matrix_HermPacked.hxx:189
Seldon::VirtualMatrix::GetN
int GetN() const
Returns the number of columns.
Definition: Matrix_BaseInline.cxx:80
Seldon::VirtualMatrix::GetM
int GetM() const
Returns the number of rows.
Definition: Matrix_BaseInline.cxx:69
Seldon::ColHermPacked
Definition: Storage.hxx:218
Seldon::RowHermPacked
Definition: Storage.hxx:229
Seldon
Seldon namespace.
Definition: Array.cxx:24