Matrix_TriangularInline.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_TRIANGULAR_INLINE_CXX
22 
23 #include "Matrix_Triangular.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  me_ = NULL;
43  }
44 
45 
46  /**************
47  * DESTRUCTOR *
48  **************/
49 
50 
52  template <class T, class Prop, class Storage, class Allocator>
54  {
55  this->Clear();
56  }
57 
58 
59  /*******************
60  * BASIC FUNCTIONS *
61  *******************/
62 
63 
65 
71  template <class T, class Prop, class Storage, class Allocator>
73  {
74  return long(this->m_) * long(this->n_);
75  }
76 
77 
79  template <class T, class Prop, class Storage, class Allocator>
81  {
82  size_t taille = sizeof(*this) + size_t(GetDataSize())*sizeof(T);
83  taille += sizeof(pointer)*this->m_;
84  return taille;
85  }
86 
87 
88  /**********************************
89  * ELEMENT ACCESS AND AFFECTATION *
90  **********************************/
91 
92 
94 
100  template <class T, class Prop, class Storage, class Allocator>
101  inline const typename
102  Matrix_Triangular<T, Prop, Storage, Allocator>::value_type
104  ::operator() (int i, int j) const
105  {
106 
107 #ifdef SELDON_CHECK_BOUNDS
108  CheckBounds(i, j, this->m_, this->n_, "Matrix_Triangular");
109 #endif
110 
111  T zero;
112  SetComplexZero(zero);
113 
114  if (Storage::UpLo())
115  {
116  if (i > j)
117  return zero;
118  else
119  return me_[Storage::GetFirst(i, j)][Storage::GetSecond(i, j)];
120  }
121  else
122  {
123  if (i < j)
124  return zero;
125  else
126  return me_[Storage::GetFirst(i, j)][Storage::GetSecond(i, j)];
127  }
128  }
129 
130 
132 
141  template <class T, class Prop, class Storage, class Allocator>
143  ::const_reference
145  {
146 
147 #ifdef SELDON_CHECK_BOUNDS
148  CheckBoundsTriang(i, j, this->m_, this->n_,
149  Storage::UpLo(), "Matrix_Triangular");
150 #endif
151 
152  return me_[Storage::GetFirst(i, j)][Storage::GetSecond(i, j)];
153  }
154 
155 
157 
166  template <class T, class Prop, class Storage, class Allocator>
167  inline typename Matrix_Triangular<T, Prop, Storage, Allocator>::reference
169  {
170 
171 #ifdef SELDON_CHECK_BOUNDS
172  CheckBoundsTriang(i, j, this->m_, this->n_,
173  Storage::UpLo(), "Matrix_Triangular");
174 #endif
175 
176  return me_[Storage::GetFirst(i, j)][Storage::GetSecond(i, j)];
177  }
178 
179 
181 
187  template <class T, class Prop, class Storage, class Allocator>
189  ::const_reference
191  {
192  return this->Val(i, j);
193  }
194 
195 
197 
203  template <class T, class Prop, class Storage, class Allocator>
204  inline typename Matrix_Triangular<T, Prop, Storage, Allocator>::reference
206  {
207  return this->Val(i, j);
208  }
209 
210 
212 
217  template <class T, class Prop, class Storage, class Allocator>
218  inline typename Matrix_Triangular<T, Prop, Storage, Allocator>::reference
220  {
221 
222 #ifdef SELDON_CHECK_BOUNDS
223  CheckBounds(i, this->GetDataSize(), "Matrix_Triangular");
224 #endif
225 
226  return this->data_[i];
227  }
228 
229 
231 
236  template <class T, class Prop, class Storage, class Allocator>
238  ::const_reference
240  {
241 
242 #ifdef SELDON_CHECK_BOUNDS
243  CheckBounds(i, this->GetDataSize(), "Matrix_Triangular");
244 #endif
245 
246  return this->data_[i];
247  }
248 
249 
251 
256  template <class T, class Prop, class Storage, class Allocator>
260  {
261  this->Copy(A);
262 
263  return *this;
264  }
265 
266 
268 
273  template <class T, class Prop, class Storage, class Allocator>
275  ::Set(int i, int j, const T& x)
276  {
277  this->Val(i, j) = x;
278  }
279 
280 
282 
287  template <class T, class Prop, class Storage, class Allocator>
290  {
291  this->Reallocate(A.GetM(), A.GetN());
292 
293  Allocator::memorycpy(this->data_, A.GetData(), this->GetDataSize());
294  }
295 
296 
297 #ifdef SELDON_WITH_VIRTUAL
298  template <class T, class Prop, class Storage, class Allocator>
300  ::MltAddVector(const Treal& alpha, const Vector<Treal>& x,
301  const Treal& beta, Vector<Treal>& y) const
302  {
303  MltAdd(alpha,
304  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
305  x, beta, y);
306  }
307 
308  template <class T, class Prop, class Storage, class Allocator>
309  inline void Matrix_Triangular<T, Prop, Storage, Allocator>
310  ::MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
311  const Tcplx& beta, Vector<Tcplx>& y) const
312  {
313  MltAdd(alpha,
314  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
315  x, beta, y);
316  }
317 
318  template <class T, class Prop, class Storage, class Allocator>
319  inline void Matrix_Triangular<T, Prop, Storage, Allocator>
320  ::MltAddVector(const Treal& alpha, const SeldonTranspose& trans,
321  const Vector<Treal>& x,
322  const Treal& beta, Vector<Treal>& y) const
323  {
324  MltAdd(alpha, trans,
325  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
326  x, beta, y);
327  }
328 
329  template <class T, class Prop, class Storage, class Allocator>
330  inline void Matrix_Triangular<T, Prop, Storage, Allocator>
331  ::MltAddVector(const Tcplx& alpha, const SeldonTranspose& trans,
332  const Vector<Tcplx>& x,
333  const Tcplx& beta, Vector<Tcplx>& y) const
334  {
335  MltAdd(alpha, trans,
336  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this),
337  x, beta, y);
338  }
339 
340  template <class T, class Prop, class Storage, class Allocator>
341  inline void Matrix_Triangular<T, Prop, Storage, Allocator>
342  ::MltVector(const Vector<Treal>& x, Vector<Treal>& y) const
343  {
344  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
345  }
346 
347  template <class T, class Prop, class Storage, class Allocator>
348  inline void Matrix_Triangular<T, Prop, Storage, Allocator>
349  ::MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const
350  {
351  Mlt(static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
352  }
353 
354  template <class T, class Prop, class Storage, class Allocator>
355  inline void Matrix_Triangular<T, Prop, Storage, Allocator>
356  ::MltVector(const SeldonTranspose& trans,
357  const Vector<Treal>& x, Vector<Treal>& y) const
358  {
359  Mlt(trans,
360  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
361  }
362 
363  template <class T, class Prop, class Storage, class Allocator>
364  inline void Matrix_Triangular<T, Prop, Storage, Allocator>
365  ::MltVector(const SeldonTranspose& trans,
366  const Vector<Tcplx>& x, Vector<Tcplx>& y) const
367  {
368  Mlt(trans,
369  static_cast<const Matrix<T, Prop, Storage, Allocator>& >(*this), x, y);
370  }
371 
372  template <class T, class Prop, class Storage, class Allocator>
373  inline bool Matrix_Triangular<T, Prop, Storage, Allocator>
374  ::IsSymmetric() const
375  {
376  return false;
377  }
378 #endif
379 
380 
382  // MATRIX<COLUPTRIANG> //
384 
385 
386  /****************
387  * CONSTRUCTORS *
388  ****************/
389 
390 
392 
395  template <class T, class Prop, class Allocator>
397  Matrix_Triangular<T, Prop, ColUpTriang, Allocator>()
398  {
399  }
400 
401 
403 
407  template <class T, class Prop, class Allocator>
409  Matrix_Triangular<T, Prop, ColUpTriang, Allocator>(i, j)
410  {
411  }
412 
413 
414  /*****************
415  * OTHER METHODS *
416  *****************/
417 
418 
420 
424  template <class T, class Prop, class Allocator>
425  template <class T0>
428  {
429  this->Fill(x);
430 
431  return *this;
432  }
433 
434 
436 
441  template <class T, class Prop, class Allocator>
445  {
446  this->Copy(A);
447  return *this;
448  }
449 
450 
452 
455  template <class T, class Prop, class Allocator>
456  template <class T0>
459  {
460  for (long i = 0; i < this->GetDataSize();i++)
461  this->data_[i] *= x;
462 
463  return *this;
464  }
465 
466 
467 
469  // MATRIX<COLLOTRIANG> //
471 
472 
473  /****************
474  * CONSTRUCTORS *
475  ****************/
476 
477 
479 
482  template <class T, class Prop, class Allocator>
484  Matrix_Triangular<T, Prop, ColLoTriang, Allocator>()
485  {
486  }
487 
488 
490 
494  template <class T, class Prop, class Allocator>
496  Matrix_Triangular<T, Prop, ColLoTriang, Allocator>(i, j)
497  {
498  }
499 
500 
501  /*****************
502  * OTHER METHODS *
503  *****************/
504 
505 
507 
511  template <class T, class Prop, class Allocator>
512  template <class T0>
515  {
516  this->Fill(x);
517 
518  return *this;
519  }
520 
521 
523 
528  template <class T, class Prop, class Allocator>
532  {
533  this->Copy(A);
534  return *this;
535  }
536 
537 
539 
542  template <class T, class Prop, class Allocator>
543  template <class T0>
546  {
547  for (long i = 0; i < this->GetDataSize();i++)
548  this->data_[i] *= x;
549 
550  return *this;
551  }
552 
553 
554 
556  // MATRIX<ROWUPTRIANG> //
558 
559 
560  /****************
561  * CONSTRUCTORS *
562  ****************/
563 
564 
566 
569  template <class T, class Prop, class Allocator>
571  Matrix_Triangular<T, Prop, RowUpTriang, Allocator>()
572  {
573  }
574 
575 
577 
581  template <class T, class Prop, class Allocator>
583  Matrix_Triangular<T, Prop, RowUpTriang, Allocator>(i, j)
584  {
585  }
586 
587 
588  /*****************
589  * OTHER METHODS *
590  *****************/
591 
592 
594 
598  template <class T, class Prop, class Allocator>
599  template <class T0>
602  {
603  this->Fill(x);
604 
605  return *this;
606  }
607 
608 
610 
615  template <class T, class Prop, class Allocator>
619  {
620  this->Copy(A);
621  return *this;
622  }
623 
624 
626 
629  template <class T, class Prop, class Allocator>
630  template <class T0>
633  {
634  for (long i = 0; i < this->GetDataSize();i++)
635  this->data_[i] *= x;
636 
637  return *this;
638  }
639 
640 
641 
643  // MATRIX<ROWLOTRIANG> //
645 
646 
647  /****************
648  * CONSTRUCTORS *
649  ****************/
650 
651 
653 
656  template <class T, class Prop, class Allocator>
658  Matrix_Triangular<T, Prop, RowLoTriang, Allocator>()
659  {
660  }
661 
662 
664 
668  template <class T, class Prop, class Allocator>
670  Matrix_Triangular<T, Prop, RowLoTriang, Allocator>(i, j)
671  {
672  }
673 
674 
675  /*****************
676  * OTHER METHODS *
677  *****************/
678 
679 
681 
685  template <class T, class Prop, class Allocator>
686  template <class T0>
689  {
690  this->Fill(x);
691 
692  return *this;
693  }
694 
695 
697 
702  template <class T, class Prop, class Allocator>
706  {
707  this->Copy(A);
708  return *this;
709  }
710 
711 
713 
716  template <class T, class Prop, class Allocator>
717  template <class T0>
720  {
721  for (long i = 0; i < this->GetDataSize();i++)
722  this->data_[i] *= x;
723 
724  return *this;
725  }
726 
727 
728 } // namespace Seldon.
729 
730 #define SELDON_FILE_MATRIX_TRIANGULAR_INLINE_CXX
731 #endif
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Vector< Treal >
Seldon::ColLoTriang
Definition: Storage.hxx:258
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix< T, Prop, ColLoTriang, Allocator >
Column-major lower-triangular full-matrix class.
Definition: Matrix_Triangular.hxx:176
Seldon::Matrix_Triangular::Matrix_Triangular
Matrix_Triangular()
Default constructor.
Definition: Matrix_TriangularInline.cxx:39
Seldon::Matrix< T, Prop, RowLoTriang, Allocator >
Row-major lower-triangular full-matrix class.
Definition: Matrix_Triangular.hxx:228
Seldon::ColUpTriang
Definition: Storage.hxx:246
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::RowLoTriang
Definition: Storage.hxx:282
Seldon::Matrix< T, Prop, RowUpTriang, Allocator >
Row-major upper-triangular full-matrix class.
Definition: Matrix_Triangular.hxx:202
Seldon::Matrix< T, Prop, ColUpTriang, Allocator >
Column-major upper-triangular full-matrix class.
Definition: Matrix_Triangular.hxx:150
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::RowUpTriang
Definition: Storage.hxx:270
Seldon::Matrix_Triangular
Triangular matrix stored in a full matrix.
Definition: Matrix_Triangular.hxx:38