| 1 | // $Id: tvector.cc,v 1.2 2000-04-03 17:35:59 ansari Exp $
 | 
|---|
| 2 | //                         C.Magneville          04/99
 | 
|---|
| 3 | #include "machdefs.h"
 | 
|---|
| 4 | #include <stdlib.h>
 | 
|---|
| 5 | #include "pexceptions.h"
 | 
|---|
| 6 | #include "tvector.h"
 | 
|---|
| 7 | 
 | 
|---|
| 8 | ////////////////////////////////////////////////////////////////
 | 
|---|
| 9 | //**** Createur, Destructeur
 | 
|---|
| 10 | 
 | 
|---|
| 11 | template <class T>
 | 
|---|
| 12 | TVector<T>::TVector()
 | 
|---|
| 13 |   : TMatrix<T>()
 | 
|---|
| 14 | {
 | 
|---|
| 15 | }
 | 
|---|
| 16 | 
 | 
|---|
| 17 | template <class T>
 | 
|---|
| 18 | TVector<T>::TVector(uint_4 n, short lcv, short mm)
 | 
|---|
| 19 | // Constructeur 
 | 
|---|
| 20 |   : TMatrix<T>((lcv == ColumnVector) ? n : 1,(lcv == ColumnVector) ? 1 : 0, mm)
 | 
|---|
| 21 | {
 | 
|---|
| 22 |   if (lcv == ColumnVector) veceli_ = marowi_;
 | 
|---|
| 23 |   else veceli_ = macoli_;
 | 
|---|
| 24 | }
 | 
|---|
| 25 | 
 | 
|---|
| 26 | 
 | 
|---|
| 27 | template <class T>
 | 
|---|
| 28 | TVector<T>::TVector(const TVector<T>& a)
 | 
|---|
| 29 | // Constructeur par copie (partage si "a" temporaire).
 | 
|---|
| 30 |   : TMatrix<T>(a)
 | 
|---|
| 31 | {
 | 
|---|
| 32 | }
 | 
|---|
| 33 | 
 | 
|---|
| 34 | template <class T>
 | 
|---|
| 35 | TVector<T>::TVector(const TVector<T>& a, bool share)
 | 
|---|
| 36 | // Constructeur par copie avec possibilite de forcer le partage ou non.
 | 
|---|
| 37 | : TMatrix<T>(a, share)
 | 
|---|
| 38 | {
 | 
|---|
| 39 | }
 | 
|---|
| 40 | 
 | 
|---|
| 41 | template <class T>
 | 
|---|
| 42 | TVector<T>::TVector(const TArray<T>& a)
 | 
|---|
| 43 | : TMatrix<T>(a)
 | 
|---|
| 44 | {
 | 
|---|
| 45 | }
 | 
|---|
| 46 | 
 | 
|---|
| 47 | 
 | 
|---|
| 48 | template <class T>
 | 
|---|
| 49 | TVector<T>::TVector(const TArray<T>& a, bool share, short lcv, short mm )
 | 
|---|
| 50 | : TMatrix<T>(a, share, mm)
 | 
|---|
| 51 | {
 | 
|---|
| 52 |   if (lcv == SameTypeVector) veceli_ = a.VectKA();
 | 
|---|
| 53 |   else {
 | 
|---|
| 54 |     if (lcv == ColumnVector) veceli_ = marowi_;
 | 
|---|
| 55 |     else veceli_ = macoli_;
 | 
|---|
| 56 |   }
 | 
|---|
| 57 | }
 | 
|---|
| 58 | 
 | 
|---|
| 59 | template <class T>
 | 
|---|
| 60 | TVector<T>::~TVector()
 | 
|---|
| 61 | // Destructeur
 | 
|---|
| 62 | {
 | 
|---|
| 63 | 
 | 
|---|
| 64 | }
 | 
|---|
| 65 | 
 | 
|---|
| 66 | template <class T>
 | 
|---|
| 67 | void TVector<T>::ReSize(uint_4 n, short lcv)
 | 
|---|
| 68 | {
 | 
|---|
| 69 |   if( n == 0 ) 
 | 
|---|
| 70 |     throw(SzMismatchError("TVector::ReSize() n = 0 "));
 | 
|---|
| 71 |   uint_4 r,c;
 | 
|---|
| 72 |   if (lcv == SameTypeVector)  lcv = GetVectorType();
 | 
|---|
| 73 |   if (lcv == ColumnVector) { r = n;  c = 1; }
 | 
|---|
| 74 |   else { c = n; r = 1; }
 | 
|---|
| 75 |   TMatrix<T>::ReSize(r,c);
 | 
|---|
| 76 | }
 | 
|---|
| 77 | 
 | 
|---|
| 78 | template <class T>
 | 
|---|
| 79 | void TVector<T>::Realloc(uint_4 n, short lcv, bool force)
 | 
|---|
| 80 | {
 | 
|---|
| 81 |   if( n == 0 ) 
 | 
|---|
| 82 |     throw(SzMismatchError("TVector::Realloc() n = 0 "));
 | 
|---|
| 83 |   uint_4 r,c;
 | 
|---|
| 84 |   if (lcv == SameTypeVector)  lcv = GetVectorType();
 | 
|---|
| 85 |   if (lcv == ColumnVector) { r = n;  c = 1; }
 | 
|---|
| 86 |   else { c = n; r = 1; }
 | 
|---|
| 87 |   TMatrix<T>::Realloc(r,c,SameMemoryMapping,force);
 | 
|---|
| 88 | }
 | 
|---|
| 89 | 
 | 
|---|
| 90 | // $CHECK$ Reza 03/2000  Doit-on declarer cette methode const ?
 | 
|---|
| 91 | template <class T>
 | 
|---|
| 92 | TVector<T> TVector<T>::operator () (Range relt) const
 | 
|---|
| 93 | {
 | 
|---|
| 94 |   Range rr, cr;
 | 
|---|
| 95 |   if (GetVectorType() == ColumnVector )  rr = relt; 
 | 
|---|
| 96 |   else cr = relt;
 | 
|---|
| 97 |   TMatrix<T> const & mtx = (*this);
 | 
|---|
| 98 |   TVector sv( mtx(rr, cr) , true, GetVectorType(), GetMemoryMapping() );
 | 
|---|
| 99 |   sv.SetTemp(true);
 | 
|---|
| 100 |   return(sv);  
 | 
|---|
| 101 | }
 | 
|---|
| 102 | 
 | 
|---|
| 103 | template <class T>
 | 
|---|
| 104 | T TVector<T>::Norm2() const
 | 
|---|
| 105 | {
 | 
|---|
| 106 |   T ret = 0;
 | 
|---|
| 107 |   for(uint_8 k=0; k<Size(); k++)   ret += (*this)(k)*(*this)(k);
 | 
|---|
| 108 |   return ret;
 | 
|---|
| 109 | }
 | 
|---|
| 110 | 
 | 
|---|
| 111 | 
 | 
|---|
| 112 | ///////////////////////////////////////////////////////////////
 | 
|---|
| 113 | #ifdef __CXX_PRAGMA_TEMPLATES__
 | 
|---|
| 114 | #pragma define_template TVector<uint_2>
 | 
|---|
| 115 | #pragma define_template TVector<int_4>
 | 
|---|
| 116 | #pragma define_template TVector<int_8>
 | 
|---|
| 117 | #pragma define_template TVector<r_4>
 | 
|---|
| 118 | #pragma define_template TVector<r_8>
 | 
|---|
| 119 | #pragma define_template TVector< complex<r_4> > 
 | 
|---|
| 120 | #pragma define_template TVector< complex<r_8> > 
 | 
|---|
| 121 | #endif
 | 
|---|
| 122 | 
 | 
|---|
| 123 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
 | 
|---|
| 124 | template class TVector<uint_2>;
 | 
|---|
| 125 | template class TVector<int_4>;
 | 
|---|
| 126 | template class TVector<int_8>;
 | 
|---|
| 127 | template class TVector<r_4>;
 | 
|---|
| 128 | template class TVector<r_8>;
 | 
|---|
| 129 | template class TVector< complex<r_4> >;
 | 
|---|
| 130 | template class TVector< complex<r_8> >;
 | 
|---|
| 131 | #endif
 | 
|---|
| 132 | 
 | 
|---|