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

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

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

File size: 3.9 KB
RevLine 
[813]1// $Id: tvector.cc,v 1.3 2000-04-05 15:44:17 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]11template <class T>
[804]12TVector<T>::TVector()
13 : TMatrix<T>()
[762]14{
15}
16
17template <class T>
[804]18TVector<T>::TVector(uint_4 n, short lcv, short mm)
19// Constructeur
[813]20 : TMatrix<T>(1,1,mm)
[762]21{
[813]22 lcv = SelectVectorType(lcv);
23 ReSize(n,lcv);
[762]24}
25
[804]26
[762]27template <class T>
[804]28TVector<T>::TVector(const TVector<T>& a)
29// Constructeur par copie (partage si "a" temporaire).
30 : TMatrix<T>(a)
[762]31{
32}
33
34template <class T>
[804]35TVector<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
41template <class T>
[804]42TVector<T>::TVector(const TArray<T>& a)
[762]43: TMatrix<T>(a)
44{
[813]45 if ( (size_[0] != 1) && (size_[1] != 1) )
46 throw SzMismatchError("TVector<T>::TVector(const TArray<T>& a) NRows()!=1 && NCols()!=1 ");
[762]47}
48
49
50template <class T>
[813]51TVector<T>::TVector(const TArray<T>& a, bool share, short mm, short lcv )
[804]52: TMatrix<T>(a, share, mm)
[762]53{
[813]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_;
[804]60 }
[762]61}
62
63template <class T>
[804]64TVector<T>::~TVector()
65// Destructeur
[762]66{
67
68}
69
70template <class T>
[804]71void TVector<T>::ReSize(uint_4 n, short lcv)
[762]72{
[804]73 if( n == 0 )
74 throw(SzMismatchError("TVector::ReSize() n = 0 "));
75 uint_4 r,c;
[813]76 if (lcv == SameVectorType) lcv = GetVectorType();
77 else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
[804]78 if (lcv == ColumnVector) { r = n; c = 1; }
79 else { c = n; r = 1; }
80 TMatrix<T>::ReSize(r,c);
[813]81 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
[762]82}
83
84template <class T>
[804]85void TVector<T>::Realloc(uint_4 n, short lcv, bool force)
[762]86{
[804]87 if( n == 0 )
88 throw(SzMismatchError("TVector::Realloc() n = 0 "));
89 uint_4 r,c;
[813]90 if (lcv == SameVectorType) lcv = GetVectorType();
91 else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
[804]92 if (lcv == ColumnVector) { r = n; c = 1; }
93 else { c = n; r = 1; }
94 TMatrix<T>::Realloc(r,c,SameMemoryMapping,force);
[813]95 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
[762]96}
97
[804]98// $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
[762]99template <class T>
[813]100TVector<T> TVector<T>::SubVector(Range relt) const
[762]101{
[804]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);
[762]109}
110
111template <class T>
[804]112T TVector<T>::Norm2() const
[762]113{
[804]114 T ret = 0;
115 for(uint_8 k=0; k<Size(); k++) ret += (*this)(k)*(*this)(k);
116 return ret;
[762]117}
118
[813]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);
[804]128
[813]129}
130
[762]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
[804]151
Note: See TracBrowser for help on using the repository browser.