[804] | 1 | // $Id: tvector.cc,v 1.2 2000-04-03 17:35:59 ansari Exp $
|
---|
[762] | 2 | // C.Magneville 04/99
|
---|
| 3 | #include "machdefs.h"
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 | #include "pexceptions.h"
|
---|
| 6 | #include "tvector.h"
|
---|
| 7 |
|
---|
[804] | 8 | ////////////////////////////////////////////////////////////////
|
---|
| 9 | //**** Createur, Destructeur
|
---|
| 10 |
|
---|
[762] | 11 | template <class T>
|
---|
[804] | 12 | TVector<T>::TVector()
|
---|
| 13 | : TMatrix<T>()
|
---|
[762] | 14 | {
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | template <class T>
|
---|
[804] | 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)
|
---|
[762] | 21 | {
|
---|
[804] | 22 | if (lcv == ColumnVector) veceli_ = marowi_;
|
---|
| 23 | else veceli_ = macoli_;
|
---|
[762] | 24 | }
|
---|
| 25 |
|
---|
[804] | 26 |
|
---|
[762] | 27 | template <class T>
|
---|
[804] | 28 | TVector<T>::TVector(const TVector<T>& a)
|
---|
| 29 | // Constructeur par copie (partage si "a" temporaire).
|
---|
| 30 | : TMatrix<T>(a)
|
---|
[762] | 31 | {
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | template <class T>
|
---|
[804] | 35 | TVector<T>::TVector(const TVector<T>& a, bool share)
|
---|
[762] | 36 | // Constructeur par copie avec possibilite de forcer le partage ou non.
|
---|
[804] | 37 | : TMatrix<T>(a, share)
|
---|
[762] | 38 | {
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | template <class T>
|
---|
[804] | 42 | TVector<T>::TVector(const TArray<T>& a)
|
---|
[762] | 43 | : TMatrix<T>(a)
|
---|
| 44 | {
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | template <class T>
|
---|
[804] | 49 | TVector<T>::TVector(const TArray<T>& a, bool share, short lcv, short mm )
|
---|
| 50 | : TMatrix<T>(a, share, mm)
|
---|
[762] | 51 | {
|
---|
[804] | 52 | if (lcv == SameTypeVector) veceli_ = a.VectKA();
|
---|
| 53 | else {
|
---|
| 54 | if (lcv == ColumnVector) veceli_ = marowi_;
|
---|
| 55 | else veceli_ = macoli_;
|
---|
| 56 | }
|
---|
[762] | 57 | }
|
---|
| 58 |
|
---|
| 59 | template <class T>
|
---|
[804] | 60 | TVector<T>::~TVector()
|
---|
| 61 | // Destructeur
|
---|
[762] | 62 | {
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | template <class T>
|
---|
[804] | 67 | void TVector<T>::ReSize(uint_4 n, short lcv)
|
---|
[762] | 68 | {
|
---|
[804] | 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);
|
---|
[762] | 76 | }
|
---|
| 77 |
|
---|
| 78 | template <class T>
|
---|
[804] | 79 | void TVector<T>::Realloc(uint_4 n, short lcv, bool force)
|
---|
[762] | 80 | {
|
---|
[804] | 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);
|
---|
[762] | 88 | }
|
---|
| 89 |
|
---|
[804] | 90 | // $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
|
---|
[762] | 91 | template <class T>
|
---|
[804] | 92 | TVector<T> TVector<T>::operator () (Range relt) const
|
---|
[762] | 93 | {
|
---|
[804] | 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);
|
---|
[762] | 101 | }
|
---|
| 102 |
|
---|
| 103 | template <class T>
|
---|
[804] | 104 | T TVector<T>::Norm2() const
|
---|
[762] | 105 | {
|
---|
[804] | 106 | T ret = 0;
|
---|
| 107 | for(uint_8 k=0; k<Size(); k++) ret += (*this)(k)*(*this)(k);
|
---|
| 108 | return ret;
|
---|
[762] | 109 | }
|
---|
| 110 |
|
---|
[804] | 111 |
|
---|
[762] | 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
|
---|
[804] | 132 |
|
---|