source: Sophya/trunk/SophyaLib/TArray/tvector.cc@ 813

Last change on this file since 813 was 813, checked in by ansari, 25 years ago

Correction bug/amelioarions TArray,TMatrix,TVector - Reza 5/4/2000

File size: 3.9 KB
Line 
1// $Id: tvector.cc,v 1.3 2000-04-05 15:44:17 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
11template <class T>
12TVector<T>::TVector()
13 : TMatrix<T>()
14{
15}
16
17template <class T>
18TVector<T>::TVector(uint_4 n, short lcv, short mm)
19// Constructeur
20 : TMatrix<T>(1,1,mm)
21{
22 lcv = SelectVectorType(lcv);
23 ReSize(n,lcv);
24}
25
26
27template <class T>
28TVector<T>::TVector(const TVector<T>& a)
29// Constructeur par copie (partage si "a" temporaire).
30 : TMatrix<T>(a)
31{
32}
33
34template <class T>
35TVector<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
41template <class T>
42TVector<T>::TVector(const TArray<T>& a)
43: TMatrix<T>(a)
44{
45 if ( (size_[0] != 1) && (size_[1] != 1) )
46 throw SzMismatchError("TVector<T>::TVector(const TArray<T>& a) NRows()!=1 && NCols()!=1 ");
47}
48
49
50template <class T>
51TVector<T>::TVector(const TArray<T>& a, bool share, short mm, short lcv )
52: TMatrix<T>(a, share, mm)
53{
54 if ( (size_[0] != 1) && (size_[1] != 1) )
55 throw SzMismatchError("TVector<T>::TVector(const TArray<T>& a) NRows()!=1 && NCols()!=1 ");
56 if ( (size_[0] == 1) && (size_[1] == 1) ) {
57 if (lcv == SameVectorType) lcv = a.GetVectorType();
58 if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
59 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
60 }
61}
62
63template <class T>
64TVector<T>::~TVector()
65// Destructeur
66{
67
68}
69
70template <class T>
71void TVector<T>::ReSize(uint_4 n, short lcv)
72{
73 if( n == 0 )
74 throw(SzMismatchError("TVector::ReSize() n = 0 "));
75 uint_4 r,c;
76 if (lcv == SameVectorType) lcv = GetVectorType();
77 else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
78 if (lcv == ColumnVector) { r = n; c = 1; }
79 else { c = n; r = 1; }
80 TMatrix<T>::ReSize(r,c);
81 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
82}
83
84template <class T>
85void TVector<T>::Realloc(uint_4 n, short lcv, bool force)
86{
87 if( n == 0 )
88 throw(SzMismatchError("TVector::Realloc() n = 0 "));
89 uint_4 r,c;
90 if (lcv == SameVectorType) lcv = GetVectorType();
91 else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
92 if (lcv == ColumnVector) { r = n; c = 1; }
93 else { c = n; r = 1; }
94 TMatrix<T>::Realloc(r,c,SameMemoryMapping,force);
95 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
96}
97
98// $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
99template <class T>
100TVector<T> TVector<T>::SubVector(Range relt) const
101{
102 Range rr, cr;
103 if (GetVectorType() == ColumnVector ) rr = relt;
104 else cr = relt;
105 TMatrix<T> const & mtx = (*this);
106 TVector sv( mtx(rr, cr) , true, GetVectorType(), GetMemoryMapping() );
107 sv.SetTemp(true);
108 return(sv);
109}
110
111template <class T>
112T TVector<T>::Norm2() const
113{
114 T ret = 0;
115 for(uint_8 k=0; k<Size(); k++) ret += (*this)(k)*(*this)(k);
116 return ret;
117}
118
119template <class T>
120string TVector<T>::InfoString() const
121{
122 string rs = "TVector<";
123 rs += typeid(T).name();
124 char buff[64];
125 sprintf(buff, ">(%ld) (nr=%ld, nc=%ld)", (long)NElts(), (long)NRows(), (long)NCols());
126 rs += buff;
127 return(rs);
128
129}
130
131///////////////////////////////////////////////////////////////
132#ifdef __CXX_PRAGMA_TEMPLATES__
133#pragma define_template TVector<uint_2>
134#pragma define_template TVector<int_4>
135#pragma define_template TVector<int_8>
136#pragma define_template TVector<r_4>
137#pragma define_template TVector<r_8>
138#pragma define_template TVector< complex<r_4> >
139#pragma define_template TVector< complex<r_8> >
140#endif
141
142#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
143template class TVector<uint_2>;
144template class TVector<int_4>;
145template class TVector<int_8>;
146template class TVector<r_4>;
147template class TVector<r_8>;
148template class TVector< complex<r_4> >;
149template class TVector< complex<r_8> >;
150#endif
151
Note: See TracBrowser for help on using the repository browser.