Subversion Repositories gelsvn

Rev

Rev 47 | Rev 595 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 47 Rev 125
1
/*!
1
/*!
2
	\file Vector.h
2
	\file Vector.h
3
	\brief The Vector type
3
	\brief The Vector type
4
*/
4
*/
5
#if !defined(VECTOR_H__HAA_AGUST_2001)
5
#if !defined(VECTOR_H__HAA_AGUST_2001)
6
#define VECTOR_H__HAA_AGUST_2001
6
#define VECTOR_H__HAA_AGUST_2001
7
 
7
 
8
#include <cassert>
8
#include <cassert>
9
#include <iostream>
9
#include <iostream>
10
#include <cmath>
10
#include <cmath>
11
#include "CGLA/Vec2f.h"
11
#include "CGLA/Vec2f.h"
12
#include "CGLA/Vec3f.h"
12
#include "CGLA/Vec3f.h"
13
 
13
 
14
namespace LinAlg
14
namespace LinAlg
15
{
15
{
16
	template <class T> class CMatrixType;  
16
	template <class T> class CMatrixType;  
17
 
17
 
18
	/*!
18
	/*!
19
		\brief The Vector type.
19
		\brief The Vector type.
20
	
20
	
21
		This vector teplate is one of the basic linear algebra types. In 
21
		This vector teplate is one of the basic linear algebra types. In 
22
		principle it an overloaded Array of type T. The typedef Vector with 
22
		principle it an overloaded Array of type T. The typedef Vector with 
23
		T set to double
23
		T set to double
24
 
24
 
25
		typedef CVectorType<double> CVector;
25
		typedef CVectorType<double> CVector;
26
	
26
	
27
		is the delclaration intended to be used as the matrix type outside 
27
		is the delclaration intended to be used as the matrix type outside 
28
		the this and related files. The reson for making a template is 
28
		the this and related files. The reson for making a template is 
29
		twofold, first it allows for an esay change of precision in this
29
		twofold, first it allows for an esay change of precision in this
30
		linear algebre package. Secondly it allows for other Vector types 
30
		linear algebre package. Secondly it allows for other Vector types 
31
		in special cases.
31
		in special cases.
32
	
32
	
33
		The pointer to the data area can be obtained by operator [] (int i) 
33
		The pointer to the data area can be obtained by operator [] (int i) 
34
		with i=0, e.g. 
34
		with i=0, e.g. 
35
	
35
	
36
		CVector A;
36
		CVector A;
37
	
37
	
38
		T* pData=A[0];  
38
		T* pData=A[0];  
39
	
39
	
40
		will  make pData point to the data.
40
		will  make pData point to the data.
41
	
41
	
42
		\see LapackFunc.h
42
		\see LapackFunc.h
43
		\see CMatrixType  
43
		\see CMatrixType  
44
		\see Additional vector operators (located in this file Vector.h)
44
		\see Additional vector operators (located in this file Vector.h)
45
		\see CMatrix
45
		\see CMatrix
46
		\see CVector
46
		\see CVector
47
		\author Henrik Aanæs
47
		\author Henrik Aanæs
48
		\version Aug 2001
48
		\version Aug 2001
49
	*/
49
	*/
50
 
50
 
51
	template <class T>
51
	template <class T>
52
	class CVectorType  
52
	class CVectorType  
53
	{
53
	{
54
 
54
 
55
		friend class CMatrixType<T>;
55
		friend class CMatrixType<T>;
56
 
56
 
57
	private:
57
	private:
58
 
58
 
59
		///The number of elements in the vector
59
		///The number of elements in the vector
60
		int nElems;
60
		int nElems;
61
 
61
 
62
		///The pointer to the vector data
62
		///The pointer to the vector data
63
		T*Data;
63
		T*Data;
64
 
64
 
65
		///Sets all the elements in the vector to a scalar
65
		///Sets all the elements in the vector to a scalar
66
		void SetScalar(const T& Scalar) 
66
		void SetScalar(const T& Scalar) 
67
		{
67
		{
68
			T* Itt=Data;
68
			T* Itt=Data;
69
			T* Stop=&(Data[nElems]);
69
			T* Stop=&(Data[nElems]);
70
			while(Itt!=Stop)
70
			while(Itt!=Stop)
71
				{
71
				{
72
					*Itt=Scalar;
72
					*Itt=Scalar;
73
					++Itt;
73
					++Itt;
74
				}
74
				}
75
		}; 
75
		}; 
76
 
76
 
77
		///Frees the used memory
77
		///Frees the used memory
78
		void CleanUp(void)  {if(Data!=NULL) delete [] Data;};
78
		void CleanUp(void)  {if(Data!=NULL) delete [] Data;};
79
		///Allocate the needed memory. Note that nElems should be initialized correctly first.
79
		///Allocate the needed memory. Note that nElems should be initialized correctly first.
80
 
80
 
81
		void Allocate(void) { Data= new T[nElems];};
81
		void Allocate(void) { Data= new T[nElems];};
82
 
82
 
83
 
83
 
84
	public:
84
	public:
85
 
85
 
86
		/// \name Constructurs and Destructors
86
		/// \name Constructurs and Destructors
87
		//@{
87
		//@{
88
		///Creats a vector a size 0.
88
		///Creats a vector a size 0.
89
		CVectorType<T>():nElems(0),Data(NULL) {};
89
		CVectorType<T>():nElems(0),Data(NULL) {};
90
 
90
 
91
		///Creates a vector of the specified Length
91
		///Creates a vector of the specified Length
92
		explicit CVectorType<T>(const int Length): nElems(Length) {Allocate();}
92
		explicit CVectorType<T>(const int Length): nElems(Length) {Allocate();}
93
 
93
 
94
		///Creates a vector of the specified Length, and sets all the values to a scalar.
94
		///Creates a vector of the specified Length, and sets all the values to a scalar.
95
		CVectorType<T>(const int Length,const T& Scalar): nElems(Length) {Allocate();SetScalar(Scalar);}
95
		CVectorType<T>(const int Length,const T& Scalar): nElems(Length) {Allocate();SetScalar(Scalar);}
96
 
96
 
97
		///Copy constructor
97
		///Copy constructor
98
		CVectorType<T>(const CVectorType<T>& Rhs): nElems(Rhs.nElems)
98
		CVectorType<T>(const CVectorType<T>& Rhs): nElems(Rhs.nElems)
99
		{
99
		{
100
			Allocate();
100
			Allocate();
101
			memcpy(Data,Rhs.Data,nElems*sizeof(T));
101
			memcpy(Data,Rhs.Data,nElems*sizeof(T));
102
		}
102
		}
103
 
103
 
104
		///Copy constructor from Vec2Type
104
		///Copy constructor from Vec2Type
105
		template <class TT, class V, unsigned int N> 
105
		template <class TT, class V, unsigned int N> 
106
		CVectorType<T>(const CGLA::ArithVec<TT,V,N>& Rhs):nElems(N)
106
		CVectorType<T>(const CGLA::ArithVec<TT,V,N>& Rhs):nElems(N)
107
		{
107
		{
108
			Allocate(); 
108
			Allocate(); 
109
			for(int i=0;i<N;++i)
109
			for(int i=0;i<N;++i)
110
				Data[i]=Rhs[i];
110
				Data[i]=Rhs[i];
111
		}
111
		}
112
 
112
 
113
		///
113
		///
114
		virtual ~CVectorType<T>(){ CleanUp();};
114
		virtual ~CVectorType<T>(){ CleanUp();};
115
		//@}
115
		//@}
116
 
116
 
117
 
117
 
118
		/*!\name Asignment operators. 
118
		/*!\name Asignment operators. 
119
			Note that the vector is resized if it does not have the correct size.
119
			Note that the vector is resized if it does not have the correct size.
120
		*/
120
		*/
121
		//@{
121
		//@{
122
		CVectorType<T>& operator=(const T& Rhs) {SetScalar(Rhs);return *this;}
122
		CVectorType<T>& operator=(const T& Rhs) {SetScalar(Rhs);return *this;}
123
 
123
 
124
		template <class TT, class V, unsigned int N> 
124
		template <class TT, class V, unsigned int N> 
125
		CVectorType<T>& operator=(const CGLA::ArithVec<TT,V,N>& Rhs)
125
		CVectorType<T>& operator=(const CGLA::ArithVec<TT,V,N>& Rhs)
126
		{
126
		{
127
			Resize(N);
127
			Resize(N);
128
			for(int i=0;i<N;++i)
128
			for(int i=0;i<N;++i)
129
				Data[i]=Rhs[i];
129
				Data[i]=Rhs[i];
130
		}
130
		}
131
 
131
 
132
 
132
 
133
		CVectorType<T>& operator=(const CVectorType<T>& Rhs)
133
		CVectorType<T>& operator=(const CVectorType<T>& Rhs)
134
		{
134
		{
135
			Resize(Rhs.nElems);
135
			Resize(Rhs.nElems);
136
			memcpy(Data,Rhs.Data,nElems*sizeof(T));
136
			memcpy(Data,Rhs.Data,nElems*sizeof(T));
137
			return *this;
137
			return *this;
138
		}
138
		}
139
		//@}
139
		//@}
140
 
140
 
141
		/// \name Dimension functions
141
		/// \name Dimension functions
142
		//@{
142
		//@{
143
		///Returns the length of the vector.
143
		///Returns the length of the vector.
144
		const int Length(void) const {return nElems;}
144
		const int Length(void) const {return nElems;}
145
		///Realocates memory IF the vector does not already hve the correct size.
145
		///Realocates memory IF the vector does not already hve the correct size.
146
		void Resize(const int Length)
146
		void Resize(const int Length)
147
		{
147
		{
148
			if(Length!=nElems)
148
			if(Length!=nElems)
149
				{
149
				{
150
					CleanUp();
150
					CleanUp();
151
					nElems=Length;
151
					nElems=Length;
152
					Data= new T[nElems];
152
					Data= new T[nElems];
153
				}
153
				}
154
		}
154
		}
155
		//@}
155
		//@}
156
 
156
 
157
		/*!
157
		/*!
158
			\name Acces functions and operators.
158
			\name Acces functions and operators.
159
			The [] operators are the ones intaended for usual use. The get 
159
			The [] operators are the ones intaended for usual use. The get 
160
			and set functions are added to allow for genral vector function 
160
			and set functions are added to allow for genral vector function 
161
			templates.
161
			templates.
162
		*/
162
		*/
163
		//@{
163
		//@{
164
		const T& get(const int i)const 
164
		const T& get(const int i)const 
165
		{
165
		{
166
			assert(i>=0);
166
			assert(i>=0);
167
			assert(i<nElems);
167
			assert(i<nElems);
168
 
168
 
169
			return Data[i];
169
			return Data[i];
170
		}
170
		}
171
 
171
 
172
		void set(const int i,const T& val)
172
		void set(const int i,const T& val)
173
		{
173
		{
174
			assert(i>=0);
174
			assert(i>=0);
175
			assert(i<nElems);
175
			assert(i<nElems);
176
 
176
 
177
			Data[i]=val;
177
			Data[i]=val;
178
		}
178
		}
179
 
179
 
180
		T& operator[](const int i) 
180
		T& operator[](const int i) 
181
		{
181
		{
182
			assert(i>=0);
182
			assert(i>=0);
183
			assert(i<nElems);
183
			assert(i<nElems);
184
		
184
		
185
			return Data[i];
185
			return Data[i];
186
		}
186
		}
187
 
187
 
188
		const T& operator[](const int i) const 
188
		const T& operator[](const int i) const 
189
		{
189
		{
190
			assert(i>=0);
190
			assert(i>=0);
191
			assert(i<nElems);
191
			assert(i<nElems);
192
		
192
		
193
			return Data[i];
193
			return Data[i];
194
		}
194
		}
195
		//@}
195
		//@}
196
 
196
 
197
		/// \name aritmethic operators
197
		/// \name aritmethic operators
198
		//@{
198
		//@{
199
		CVectorType<T> operator+(const CVectorType<T>& Rhs) const {CVectorType<T>Ret(*this); return Ret+=Rhs;};
199
		CVectorType<T> operator+(const CVectorType<T>& Rhs) const {CVectorType<T>Ret(*this); return Ret+=Rhs;};
200
		CVectorType<T> operator-(const CVectorType<T>& Rhs) const {CVectorType<T>Ret(*this); return Ret-=Rhs;};
200
		CVectorType<T> operator-(const CVectorType<T>& Rhs) const {CVectorType<T>Ret(*this); return Ret-=Rhs;};
201
		CVectorType<T> operator+(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret+=Rhs;};
201
		CVectorType<T> operator+(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret+=Rhs;};
202
		CVectorType<T> operator-(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret-=Rhs;};
202
		CVectorType<T> operator-(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret-=Rhs;};
203
		CVectorType<T> operator*(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret*=Rhs;};
203
		CVectorType<T> operator*(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret*=Rhs;};
204
		CVectorType<T> operator/(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret/=Rhs;};
204
		CVectorType<T> operator/(const T& Rhs) const {CVectorType<T>Ret(*this); return Ret/=Rhs;};
205
 
205
 
206
		CVectorType<T>& operator+=(const CVectorType<T>& Rhs)
206
		CVectorType<T>& operator+=(const CVectorType<T>& Rhs)
207
		{
207
		{
208
			assert(nElems==Rhs.nElems);
208
			assert(nElems==Rhs.nElems);
209
 
209
 
210
			T* IttRhs=Rhs.Data;
210
			T* IttRhs=Rhs.Data;
211
			T* Itt=Data;
211
			T* Itt=Data;
212
			T* Stop=&(Data[nElems]);
212
			T* Stop=&(Data[nElems]);
213
			while(Itt!=Stop)
213
			while(Itt!=Stop)
214
				{
214
				{
215
					(*Itt)+=(*IttRhs);
215
					(*Itt)+=(*IttRhs);
216
					++Itt;
216
					++Itt;
217
					++IttRhs;
217
					++IttRhs;
218
				}
218
				}
219
			return *this; 
219
			return *this; 
220
		}
220
		}
221
 
221
 
222
		CVectorType<T>& operator-=(const CVectorType<T>& Rhs)
222
		CVectorType<T>& operator-=(const CVectorType<T>& Rhs)
223
		{
223
		{
224
			assert(nElems==Rhs.nElems);
224
			assert(nElems==Rhs.nElems);
225
 
225
 
226
			T* IttRhs=Rhs.Data;
226
			T* IttRhs=Rhs.Data;
227
			T* Itt=Data;
227
			T* Itt=Data;
228
			T* Stop=&(Data[nElems]);
228
			T* Stop=&(Data[nElems]);
229
			while(Itt!=Stop)
229
			while(Itt!=Stop)
230
				{
230
				{
231
					(*Itt)-=(*IttRhs);
231
					(*Itt)-=(*IttRhs);
232
					++Itt;
232
					++Itt;
233
					++IttRhs;
233
					++IttRhs;
234
				}
234
				}
235
			return *this; 
235
			return *this; 
236
		}
236
		}
237
 
237
 
238
		CVectorType<T>& operator+=(const T& Rhs)
238
		CVectorType<T>& operator+=(const T& Rhs)
239
		{
239
		{
240
			T* Itt=Data;
240
			T* Itt=Data;
241
			T* Stop=&(Data[nElems]);
241
			T* Stop=&(Data[nElems]);
242
			while(Itt!=Stop)
242
			while(Itt!=Stop)
243
				{
243
				{
244
					(*Itt)+=Rhs;
244
					(*Itt)+=Rhs;
245
					++Itt;
245
					++Itt;
246
				}
246
				}
247
			return *this; 
247
			return *this; 
248
		}
248
		}
249
 
249
 
250
		CVectorType<T>& operator-=(const T& Rhs)
250
		CVectorType<T>& operator-=(const T& Rhs)
251
		{
251
		{
252
			T* Itt=Data;
252
			T* Itt=Data;
253
			T* Stop=&(Data[nElems]);
253
			T* Stop=&(Data[nElems]);
254
			while(Itt!=Stop)
254
			while(Itt!=Stop)
255
				{
255
				{
256
					(*Itt)-=Rhs;
256
					(*Itt)-=Rhs;
257
					++Itt;
257
					++Itt;
258
				}
258
				}
259
			return *this; 
259
			return *this; 
260
		}
260
		}
261
 
261
 
262
		CVectorType<T>& operator*=(const T& Rhs)
262
		CVectorType<T>& operator*=(const T& Rhs)
263
		{
263
		{
264
			T* Itt=Data;
264
			T* Itt=Data;
265
			T* Stop=&(Data[nElems]);
265
			T* Stop=&(Data[nElems]);
266
			while(Itt!=Stop)
266
			while(Itt!=Stop)
267
				{
267
				{
268
					(*Itt)*=Rhs;
268
					(*Itt)*=Rhs;
269
					++Itt;
269
					++Itt;
270
				}
270
				}
271
			return *this; 
271
			return *this; 
272
		}
272
		}
273
 
273
 
274
		CVectorType<T>& operator/=(const T& Rhs)
274
		CVectorType<T>& operator/=(const T& Rhs)
275
		{
275
		{
276
			T* Itt=Data;
276
			T* Itt=Data;
277
			T* Stop=&(Data[nElems]);
277
			T* Stop=&(Data[nElems]);
278
			while(Itt!=Stop)
278
			while(Itt!=Stop)
279
				{
279
				{
280
					(*Itt)/=Rhs;
280
					(*Itt)/=Rhs;
281
					++Itt;
281
					++Itt;
282
				}
282
				}
283
			return *this; 
283
			return *this; 
284
		}
284
		}
285
 
285
 
286
		T operator*(const CVectorType<T>& Rhs) const
286
		T operator*(const CVectorType<T>& Rhs) const
287
		{
287
		{
288
			assert(nElems==Rhs.nElems);
288
			assert(nElems==Rhs.nElems);
289
			T Ret=0;
289
			T Ret=0;
290
 
290
 
291
			T* IttRhs=Rhs.Data;
291
			T* IttRhs=Rhs.Data;
292
			T* Itt=Data;
292
			T* Itt=Data;
293
			T* Stop=&(Data[nElems]);
293
			T* Stop=&(Data[nElems]);
294
			while(Itt!=Stop)
294
			while(Itt!=Stop)
295
				{
295
				{
296
					Ret+=(*Itt)*(*IttRhs);
296
					Ret+=(*Itt)*(*IttRhs);
297
					++Itt;
297
					++Itt;
298
					++IttRhs;
298
					++IttRhs;
299
				}
299
				}
300
			return Ret; 
300
			return Ret; 
301
		}
301
		}
302
 
302
 
303
		CVectorType<T> operator*(const CMatrixType<T>& Rhs) const
303
		CVectorType<T> operator*(const CMatrixType<T>& Rhs) const
304
		{
304
		{
305
			assert(nElems==Rhs.Rows());
305
			assert(nElems==Rhs.Rows());
306
			CVectorType<T> Ret(Rhs.Cols(),0);
306
			CVectorType<T> Ret(Rhs.Cols(),0);
307
 
307
 
308
			T* ThisItt=Data;
308
			T* ThisItt=Data;
309
			const T* RhsItt=Rhs.Data;
309
			const T* RhsItt=Rhs.Data;
310
			const T* Stop=&(Rhs.Data[Rhs.nElems]);
310
			const T* Stop=&(Rhs.Data[Rhs.nElems]);
311
			T* RetItt;
311
			T* RetItt;
312
 
312
 
313
			while(RhsItt!=Stop)
313
			while(RhsItt!=Stop)
314
				{
314
				{
315
					RetItt=Ret.Data;
315
					RetItt=Ret.Data;
316
					for(int cCol=Rhs.Cols()-1;cCol>=0;--cCol)
316
					for(int cCol=Rhs.Cols()-1;cCol>=0;--cCol)
317
						{
317
						{
318
							(*RetItt)+=(*ThisItt)*(*RhsItt);
318
							(*RetItt)+=(*ThisItt)*(*RhsItt);
319
							++RetItt;
319
							++RetItt;
320
							++RhsItt;
320
							++RhsItt;
321
						}
321
						}
322
					++ThisItt;
322
					++ThisItt;
323
				}
323
				}
324
			return Ret;
324
			return Ret;
325
		}
325
		}
326
		//@}
326
		//@}
327
 
327
 
328
		/// \name Norms
328
		/// \name Norms
329
		//@{
329
		//@{
330
		const T Norm(void) const {return sqrt((*this)*(*this));}
330
		const T Norm(void) const {return sqrt((*this)*(*this));}
331
		const T NormMax(void) const
331
		const T NormMax(void) const
332
		{
332
		{
333
			T Ret=0;
333
			T Ret=0;
334
			T Abs;
334
			T Abs;
335
			const T* Itt=Data;
335
			const T* Itt=Data;
336
			const T* Stop=&(Data[nElems]);
336
			const T* Stop=&(Data[nElems]);
337
			while(Itt!=Stop)
337
			while(Itt!=Stop)
338
				{
338
				{
339
					Abs=(*Itt)>0?(*Itt):-(*Itt);
339
					Abs=(*Itt)>0?(*Itt):-(*Itt);
340
					if(Ret<Abs)
340
					if(Ret<Abs)
341
						Ret=Abs;
341
						Ret=Abs;
342
 
342
 
343
					++Itt;
343
					++Itt;
344
				}
344
				}
345
			return Ret;
345
			return Ret;
346
		}
346
		}
347
		//@}
347
		//@}
348
 
348
 
349
		/// Sum of all the elements in the vector
349
		/// Sum of all the elements in the vector
350
		const T Sum(void) const
350
		const T Sum(void) const
351
		{
351
		{
352
			T Ret=0;
352
			T Ret=0;
353
			const T* Itt=Data;
353
			const T* Itt=Data;
354
			const T* Stop=&(Data[nElems]);
354
			const T* Stop=&(Data[nElems]);
355
			while(Itt!=Stop)
355
			while(Itt!=Stop)
356
				{
356
				{
357
					Ret+=(*Itt);
357
					Ret+=(*Itt);
358
					++Itt;
358
					++Itt;
359
				}
359
				}
360
		}
360
		}
361
 
361
 
362
 
362
 
363
		/*!
363
		/*!
364
			\name Elementwise functions.
364
			\name Elementwise functions.
365
			Functions the perform some elementary operation on each 
365
			Functions the perform some elementary operation on each 
366
			of the elements of the vector.
366
			of the elements of the vector.
367
		*/
367
		*/
368
		//@{
368
		//@{
369
		///The elements of the vector squared. Equvivalent to MatLAb's .^2
369
		///The elements of the vector squared. Equvivalent to MatLAb's .^2
370
		void ElemSqr(void)
370
		void ElemSqr(void)
371
		{
371
		{
372
			T* Itt=Data;
372
			T* Itt=Data;
373
			T* Stop=&(Data[nElems]);
373
			T* Stop=&(Data[nElems]);
374
			while(Itt!=Stop)
374
			while(Itt!=Stop)
375
				{
375
				{
376
					(*Itt)*=(*Itt);
376
					(*Itt)*=(*Itt);
377
					++Itt;
377
					++Itt;
378
				}
378
				}
379
		}
379
		}
380
 
380
 
381
 
381
 
382
	};
382
	};
383
 
383
 
384
 
384
 
385
	/*!
385
	/*!
386
		\name Additional vector operators
386
		\name Additional vector operators
387
		These are operators heavily associated with CVectorType, but not included
387
		These are operators heavily associated with CVectorType, but not included
388
		in the class definition it self.
388
		in the class definition it self.
389
	*/
389
	*/
390
	//@{
390
	//@{
391
	template<class T>
391
	template<class T>
392
	inline CVectorType<T> operator+(const T& Lhs,const CVectorType<T>&Rhs ) 
392
	inline CVectorType<T> operator+(const T& Lhs,const CVectorType<T>&Rhs ) 
393
	{
393
	{
394
		return Rhs+Lhs;
394
		return Rhs+Lhs;
395
	}
395
	}
396
 
396
 
397
	template<class T>
397
	template<class T>
398
	inline CVectorType<T> operator*(const T& Lhs,const CVectorType<T>&Rhs ) 
398
	inline CVectorType<T> operator*(const T& Lhs,const CVectorType<T>&Rhs ) 
399
	{
399
	{
400
		return Rhs*Lhs;
400
		return Rhs*Lhs;
401
	}
401
	}
402
 
402
 
403
	template <class T>
403
	template <class T>
404
	std::ostream& operator<<(std::ostream &s, const CVectorType<T> &a)
404
	std::ostream& operator<<(std::ostream &s, const CVectorType<T> &a)
405
	{
405
	{
406
		int nElems=a.Length();
406
		int nElems=a.Length();
407
	
407
	
408
		for (int cElem=0; cElem<nElems; cElem++)
408
		for (int cElem=0; cElem<nElems; cElem++)
409
			{
409
			{
410
				s << a[cElem] << " ";
410
				s << a[cElem] << " ";
411
			}
411
			}
412
		s << "\n";
412
		s << "\n";
413
	
413
	
414
		return s;
414
		return s;
415
	}
415
	}
416
 
416
 
417
 
417
 
418
	template <class T>
418
	template <class T>
419
	std::istream& operator>>(std::istream &s, CVectorType<T> &a)
419
	std::istream& operator>>(std::istream &s, CVectorType<T> &a)
420
	{
420
	{
421
		int nElems;
421
		int nElems;
422
 
422
 
423
		s >> nElems;
423
		s >> nElems;
424
 
424
 
425
		if ( nEelms!=a.Length())
425
		if ( nElems!=a.Length())
426
			a.Resize(nElems);
426
			a.Resize(nElems);
427
 
427
 
428
 
428
 
429
		for (int cElem=0; cRow<nElems;cElem++)
429
		for (int cElem=0; cElem<a.Length();cElem++)
430
			{
430
			{
431
				s >>  a[cCol];
431
				s >>  a[cElem];
432
			}
432
			}
433
 
433
 
434
		return s;
434
		return s;
435
	}
435
	}
436
	//@}
436
	//@}
437
 
437
 
438
	/// The Vector annotation intended for use.
438
	/// The Vector annotation intended for use.
439
	typedef CVectorType<double> CVector;
439
	typedef CVectorType<double> CVector;
440
}
440
}
441
#endif // !defined(VECTOR_H__HAA_AGUST_2001)
441
#endif // !defined(VECTOR_H__HAA_AGUST_2001)
442
 
442