Matrix_TriangPackedInline.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_TRIANGPACKED_INLINE_CXX
22 
23 #include "Matrix_TriangPacked.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>
41  {
42  }
43 
44 
45  /**************
46  * DESTRUCTOR *
47  **************/
48 
49 
51  template <class T, class Prop, class Storage, class Allocator>
54  {
55  this->Clear();
56  }
57 
58 
59  /*******************
60  * BASIC FUNCTIONS *
61  *******************/
62 
63 
65 
68  template <class T, class Prop, class Storage, class Allocator>
70  {
71  return (long(this->m_) * long(this->m_ + 1)) / 2;
72  }
73 
74 
76  template <class T, class Prop, class Storage, class Allocator>
78  {
79  size_t taille = sizeof(*this) + size_t(GetDataSize())*sizeof(T);
80  return taille;
81  }
82 
83 
84  /**********************************
85  * ELEMENT ACCESS AND AFFECTATION *
86  **********************************/
87 
88 
90 
96  template <class T, class Prop, class Storage, class Allocator>
97  inline const typename
98  Matrix_TriangPacked<T, Prop, Storage, Allocator>::value_type
100  ::operator() (int i, int j) const
101  {
102 
103 #ifdef SELDON_CHECK_BOUNDS
104  CheckBounds(i, j, this->m_, this->n_, "Matrix_TriangPacked");
105 #endif
106 
107  T zero;
108  SetComplexZero(zero);
109 
110  if (Storage::UpLo())
111  if (i > j)
112  return zero;
113  else
114  return this->data_[Storage::GetFirst(i * long(this->n_)
115  - (i * long(i + 1)) / 2 + j,
116  (j * long(j + 1)) / 2 + i)];
117  else
118  if (i < j)
119  return zero;
120  else
121  return this->data_[Storage::GetFirst((i * long(i + 1)) / 2 + j,
122  j * long(this->m_)
123  - (j * long(j + 1)) / 2 + i)];
124  }
125 
126 
128 
135  template <class T, class Prop, class Storage, class Allocator>
136  inline typename Matrix_TriangPacked<T, Prop, Storage, Allocator>::reference
138  {
139 
140 #ifdef SELDON_CHECK_BOUNDS
141  CheckBoundsTriang(i, j, this->m_, this->n_,
142  Storage::UpLo(), "Matrix_TriangPacked");
143 #endif
144 
145  if (Storage::UpLo())
146  return this->data_[Storage::GetFirst(i * long(this->n_)
147  - (i * long(i + 1)) / 2 + j,
148  (j * long(j + 1)) / 2 + i)];
149  else
150  return this->data_[Storage::GetFirst((i * long(i + 1)) / 2 + j,
151  j * long(this->m_)
152  - (j * long(j + 1)) / 2 + i)];
153  }
154 
155 
157 
164  template <class T, class Prop, class Storage, class Allocator>
166  ::const_reference
168  {
169 
170 #ifdef SELDON_CHECK_BOUNDS
171  CheckBoundsTriang(i, j, this->m_, this->n_,
172  Storage::UpLo(), "Matrix_TriangPacked");
173 #endif
174 
175  if (Storage::UpLo())
176  return this->data_[Storage::GetFirst(i * long(this->n_)
177  - (i * long(i + 1)) / 2 + j,
178  (j * long(j + 1)) / 2 + i)];
179  else
180  return this->data_[Storage::GetFirst((i * long(i + 1)) / 2 + j,
181  j * long(this->m_)
182  - (j * long(j + 1)) / 2 + i)];
183  }
184 
185 
187 
193  template <class T, class Prop, class Storage, class Allocator>
194  inline typename Matrix_TriangPacked<T, Prop, Storage, Allocator>::reference
196  {
197  return this->Val(i, j);
198  }
199 
200 
202 
208  template <class T, class Prop, class Storage, class Allocator>
210  ::const_reference
212  {
213  return this->Val(i, j);
214  }
215 
216 
218 
223  template <class T, class Prop, class Storage, class Allocator>
224  inline typename Matrix_TriangPacked<T, Prop, Storage, Allocator>::reference
226  {
227 
228 #ifdef SELDON_CHECK_BOUNDS
229  CheckBounds(i, this->GetDataSize(), "Matrix_TriangPacked");
230 #endif
231 
232  return this->data_[i];
233  }
234 
235 
237 
242  template <class T, class Prop, class Storage, class Allocator>
244  ::const_reference
246  {
247 
248 #ifdef SELDON_CHECK_BOUNDS
249  CheckBounds(i, this->GetDataSize(), "Matrix_TriangPacked");
250 #endif
251 
252  return this->data_[i];
253  }
254 
255 
257 
262  template <class T, class Prop, class Storage, class Allocator>
266  {
267  this->Copy(A);
268 
269  return *this;
270  }
271 
272 
274 
279  template <class T, class Prop, class Storage, class Allocator>
281  ::Set(int i, int j, const T& x)
282  {
283  this->Val(i, j) = x;
284  }
285 
286 
288 
293  template <class T, class Prop, class Storage, class Allocator>
296  {
297  this->Reallocate(A.GetM(), A.GetN());
298 
299  Allocator::memorycpy(this->data_, A.GetData(), this->GetDataSize());
300  }
301 
302 
303 #ifdef SELDON_WITH_VIRTUAL
304  template <class T, class Prop, class Storage, class Allocator>
306  ::MltAddVector(const Treal& alpha, const Vector<Treal>& x,
307  const Treal& beta, Vector<Treal>& y) const
308  {
309  MltAdd(alpha,
310  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
311  x, beta, y);
312  }
313 
314  template <class T, class Prop, class Storage, class Allocator>
315  inline void Matrix_TriangPacked<T, Prop, Storage, Allocator>
316  ::MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
317  const Tcplx& beta, Vector<Tcplx>& y) const
318  {
319  MltAdd(alpha,
320  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
321  x, beta, y);
322  }
323 
324  template <class T, class Prop, class Storage, class Allocator>
325  inline void Matrix_TriangPacked<T, Prop, Storage, Allocator>
326  ::MltAddVector(const Treal& alpha, const SeldonTranspose& trans,
327  const Vector<Treal>& x,
328  const Treal& beta, Vector<Treal>& y) const
329  {
330  MltAdd(alpha, trans,
331  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
332  x, beta, y);
333  }
334 
335  template <class T, class Prop, class Storage, class Allocator>
336  inline void Matrix_TriangPacked<T, Prop, Storage, Allocator>
337  ::MltAddVector(const Tcplx& alpha, const SeldonTranspose& trans,
338  const Vector<Tcplx>& x,
339  const Tcplx& beta, Vector<Tcplx>& y) const
340  {
341  MltAdd(alpha, trans,
342  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
343  x, beta, y);
344  }
345 
346  template <class T, class Prop, class Storage, class Allocator>
347  inline void Matrix_TriangPacked<T, Prop, Storage, Allocator>
348  ::MltVector(const Vector<Treal>& x, Vector<Treal>& y) const
349  {
350  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
351  }
352 
353  template <class T, class Prop, class Storage, class Allocator>
354  inline void Matrix_TriangPacked<T, Prop, Storage, Allocator>
355  ::MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const
356  {
357  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
358  }
359 
360  template <class T, class Prop, class Storage, class Allocator>
361  inline void Matrix_TriangPacked<T, Prop, Storage, Allocator>
362  ::MltVector(const SeldonTranspose& trans,
363  const Vector<Treal>& x, Vector<Treal>& y) const
364  {
365  Mlt(trans,
366  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
367  }
368 
369  template <class T, class Prop, class Storage, class Allocator>
370  inline void Matrix_TriangPacked<T, Prop, Storage, Allocator>
371  ::MltVector(const SeldonTranspose& trans,
372  const Vector<Tcplx>& x, Vector<Tcplx>& y) const
373  {
374  Mlt(trans,
375  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
376  }
377 
378  template <class T, class Prop, class Storage, class Allocator>
379  inline bool Matrix_TriangPacked<T, Prop, Storage, Allocator>
380  ::IsSymmetric() const
381  {
382  return false;
383  }
384 #endif
385 
386 
388  // MATRIX<COLUPTRIANGPACKED> //
390 
391 
392  /****************
393  * CONSTRUCTORS *
394  ****************/
395 
396 
398 
401  template <class T, class Prop, class Allocator>
403  Matrix_TriangPacked<T, Prop, ColUpTriangPacked, Allocator>()
404  {
405  }
406 
407 
409 
414  template <class T, class Prop, class Allocator>
416  Matrix_TriangPacked<T, Prop, ColUpTriangPacked, Allocator>(i, i)
417  {
418  }
419 
420 
421  /*****************
422  * OTHER METHODS *
423  *****************/
424 
425 
427 
430  template <class T, class Prop, class Allocator>
431  template <class T0>
434  {
435  this->Fill(x);
436 
437  return *this;
438  }
439 
440 
442 
447  template <class T, class Prop, class Allocator>
451  {
452  this->Copy(A);
453  return *this;
454  }
455 
456 
458 
461  template <class T, class Prop, class Allocator>
462  template <class T0>
465  {
466  for (long i = 0; i < this->GetDataSize();i++)
467  this->data_[i] *= x;
468 
469  return *this;
470  }
471 
472 
473 
475  // MATRIX<COLLOTRIANGPACKED> //
477 
478 
479  /****************
480  * CONSTRUCTORS *
481  ****************/
482 
483 
485 
488  template <class T, class Prop, class Allocator>
490  Matrix_TriangPacked<T, Prop, ColLoTriangPacked, Allocator>()
491  {
492  }
493 
494 
496 
501  template <class T, class Prop, class Allocator>
503  Matrix_TriangPacked<T, Prop, ColLoTriangPacked, Allocator>(i, i)
504  {
505  }
506 
507 
508  /*****************
509  * OTHER METHODS *
510  *****************/
511 
512 
514 
517  template <class T, class Prop, class Allocator>
518  template <class T0>
521  {
522  this->Fill(x);
523 
524  return *this;
525  }
526 
527 
529 
534  template <class T, class Prop, class Allocator>
538  {
539  this->Copy(A);
540  return *this;
541  }
542 
543 
545 
548  template <class T, class Prop, class Allocator>
549  template <class T0>
552  {
553  for (long i = 0; i < this->GetDataSize();i++)
554  this->data_[i] *= x;
555 
556  return *this;
557  }
558 
559 
560 
562  // MATRIX<ROWUPTRIANGPACKED> //
564 
565 
566  /****************
567  * CONSTRUCTORS *
568  ****************/
569 
570 
572 
575  template <class T, class Prop, class Allocator>
577  Matrix_TriangPacked<T, Prop, RowUpTriangPacked, Allocator>()
578  {
579  }
580 
581 
583 
588  template <class T, class Prop, class Allocator>
590  Matrix_TriangPacked<T, Prop, RowUpTriangPacked, Allocator>(i, i)
591  {
592  }
593 
594 
595  /*****************
596  * OTHER METHODS *
597  *****************/
598 
599 
601 
604  template <class T, class Prop, class Allocator>
605  template <class T0>
608  {
609  this->Fill(x);
610 
611  return *this;
612  }
613 
614 
616 
621  template <class T, class Prop, class Allocator>
625  {
626  this->Copy(A);
627  return *this;
628  }
629 
630 
632 
635  template <class T, class Prop, class Allocator>
636  template <class T0>
639  {
640  for (long i = 0; i < this->GetDataSize();i++)
641  this->data_[i] *= x;
642 
643  return *this;
644  }
645 
646 
647 
649  // MATRIX<ROWLOTRIANGPACKED> //
651 
652 
653  /****************
654  * CONSTRUCTORS *
655  ****************/
656 
657 
659 
662  template <class T, class Prop, class Allocator>
664  Matrix_TriangPacked<T, Prop, RowLoTriangPacked, Allocator>()
665  {
666  }
667 
668 
670 
675  template <class T, class Prop, class Allocator>
677  Matrix_TriangPacked<T, Prop, RowLoTriangPacked, Allocator>(i, i)
678  {
679  }
680 
681 
682  /*****************
683  * OTHER METHODS *
684  *****************/
685 
686 
688 
691  template <class T, class Prop, class Allocator>
692  template <class T0>
695  {
696  this->Fill(x);
697 
698  return *this;
699  }
700 
701 
703 
708  template <class T, class Prop, class Allocator>
712  {
713  this->Copy(A);
714  return *this;
715  }
716 
717 
719 
722  template <class T, class Prop, class Allocator>
723  template <class T0>
726  {
727  for (long i = 0; i < this->GetDataSize();i++)
728  this->data_[i] *= x;
729 
730  return *this;
731  }
732 
733 
734 } // namespace Seldon.
735 
736 #define SELDON_FILE_MATRIX_TRIANGPACKED_INLINE_CXX
737 #endif
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Matrix_TriangPacked::GetMemorySize
size_t GetMemorySize() const
Returns size of A in bytes used to store the matrix.
Definition: Matrix_TriangPackedInline.cxx:77
Seldon::Vector< Treal >
Seldon::Matrix_TriangPacked::Val
reference Val(int i, int j)
Direct access method.
Definition: Matrix_TriangPackedInline.cxx:137
Seldon::Matrix_TriangPacked::operator=
Matrix_TriangPacked< T, Prop, Storage, Allocator > & operator=(const Matrix_TriangPacked< T, Prop, Storage, Allocator > &A)
Duplicates a matrix (assignment operator).
Definition: Matrix_TriangPackedInline.cxx:265
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix_TriangPacked::operator()
const value_type operator()(int i, int j) const
Access operator.
Definition: Matrix_TriangPackedInline.cxx:100
Seldon::Matrix_TriangPacked
Triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:38
Seldon::Matrix< T, Prop, RowUpTriangPacked, Allocator >
Row-major upper-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:198
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::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::RowUpTriangPacked
Definition: Storage.hxx:318
Seldon::Matrix_TriangPacked::Copy
void Copy(const Matrix_TriangPacked< T, Prop, Storage, Allocator > &A)
Duplicates a matrix.
Definition: Matrix_TriangPackedInline.cxx:295
Seldon::Matrix< T, Prop, ColUpTriangPacked, Allocator >
Column-major upper-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:146
Seldon::Matrix_TriangPacked::Set
void Set(int i, int j, const T &x)
Sets an element of the matrix.
Definition: Matrix_TriangPackedInline.cxx:281
Seldon::Matrix_TriangPacked::Get
reference Get(int i, int j)
Returns the element (i, j)
Definition: Matrix_TriangPackedInline.cxx:195
Seldon::ColUpTriangPacked
Definition: Storage.hxx:294
Seldon::Matrix_TriangPacked::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: Matrix_TriangPackedInline.cxx:69
Seldon::Matrix_TriangPacked::~Matrix_TriangPacked
~Matrix_TriangPacked()
Destructor.
Definition: Matrix_TriangPackedInline.cxx:53
Seldon::RowLoTriangPacked
Definition: Storage.hxx:330
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Matrix_TriangPacked::Matrix_TriangPacked
Matrix_TriangPacked()
Default constructor.
Definition: Matrix_TriangPackedInline.cxx:40
Seldon::Matrix< T, Prop, RowLoTriangPacked, Allocator >
Row-major lower-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:224
Seldon::ColLoTriangPacked
Definition: Storage.hxx:306
Seldon::Matrix< T, Prop, ColLoTriangPacked, Allocator >
Column-major lower-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:172
Seldon::Matrix_TriangPacked::operator[]
reference operator[](int i)
Access to elements of the data array.
Definition: Matrix_TriangPackedInline.cxx:225