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

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

doc pour preparation inverse logique de NDataBlock cmv 21/4/00

File size: 5.2 KB
RevLine 
[967]1// $Id: tvector.cc,v 1.7 2000-04-21 16:31:26 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
[926]8/*!
9 \class SOPHYA::TVector
10 \ingroup TArray
11 Class of vector (line or column)
12 \sa TMatrix TArray
13 */
14
[804]15////////////////////////////////////////////////////////////////
16//**** Createur, Destructeur
17
[894]18//! Default constructor
[762]19template <class T>
[804]20TVector<T>::TVector()
21 : TMatrix<T>()
[762]22{
23}
24
[894]25//! construct a vector
26/*!
27 \param n : number of elements
28 \param lcv : line or column vector ?
29 \param mm : memory mapping type
30 \sa SelectVectorType
31 */
[762]32template <class T>
[804]33TVector<T>::TVector(uint_4 n, short lcv, short mm)
34// Constructeur
[813]35 : TMatrix<T>(1,1,mm)
[762]36{
[813]37 lcv = SelectVectorType(lcv);
38 ReSize(n,lcv);
[762]39}
40
[967]41//! Constructor by copy
42/*! \sa NDataBlock::NDataBlock(const NDataBlock<T>&) */
[762]43template <class T>
[804]44TVector<T>::TVector(const TVector<T>& a)
[967]45// Constructeur par copie
[804]46 : TMatrix<T>(a)
[762]47{
48}
49
[894]50//! Constructor by copy
51/*!
52 \param share : if true, share data. If false copy data
53 */
[762]54template <class T>
[804]55TVector<T>::TVector(const TVector<T>& a, bool share)
[762]56// Constructeur par copie avec possibilite de forcer le partage ou non.
[804]57: TMatrix<T>(a, share)
[762]58{
59}
60
[894]61//! Constructor from a TArray
[762]62template <class T>
[804]63TVector<T>::TVector(const TArray<T>& a)
[762]64: TMatrix<T>(a)
65{
[813]66 if ( (size_[0] != 1) && (size_[1] != 1) )
67 throw SzMismatchError("TVector<T>::TVector(const TArray<T>& a) NRows()!=1 && NCols()!=1 ");
[762]68}
69
70
[894]71//! Constructor of a vector from a TArray \b a
72/*!
73 \param a : TArray to be copied or shared
74 \param share : if true, share data. If false copy data
75 \param mm : define the memory mapping type
76 \param lcv : line or column vector ?
77 \sa SelectVectorType
78 */
[762]79template <class T>
[914]80TVector<T>::TVector(const TArray<T>& a, bool share, short lcv, short mm)
[804]81: TMatrix<T>(a, share, mm)
[762]82{
[813]83 if ( (size_[0] != 1) && (size_[1] != 1) )
84 throw SzMismatchError("TVector<T>::TVector(const TArray<T>& a) NRows()!=1 && NCols()!=1 ");
85 if ( (size_[0] == 1) && (size_[1] == 1) ) {
86 if (lcv == SameVectorType) lcv = a.GetVectorType();
87 if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
88 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
[804]89 }
[762]90}
91
[894]92//! Destructor
[762]93template <class T>
[804]94TVector<T>::~TVector()
[762]95{
96}
97
[894]98//! Resize the vector
99/*!
100 \param n : number of elements
101 \param lcv : line or column vector ?
102 \sa SelectVectorType
103 */
[762]104template <class T>
[804]105void TVector<T>::ReSize(uint_4 n, short lcv)
[762]106{
[804]107 if( n == 0 )
108 throw(SzMismatchError("TVector::ReSize() n = 0 "));
109 uint_4 r,c;
[813]110 if (lcv == SameVectorType) lcv = GetVectorType();
111 else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
[804]112 if (lcv == ColumnVector) { r = n; c = 1; }
113 else { c = n; r = 1; }
114 TMatrix<T>::ReSize(r,c);
[813]115 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
[762]116}
117
[894]118//! Re-allocate space for the vector
119/*!
120 \param n : number of elements
121 \param lcv : line or column vector ?
122 \param force : if true re-allocation is forced, if not it occurs
123 only if the required space is greater than the old one.
124 \sa ReSize SelectVectorType
125 */
[762]126template <class T>
[804]127void TVector<T>::Realloc(uint_4 n, short lcv, bool force)
[762]128{
[804]129 if( n == 0 )
130 throw(SzMismatchError("TVector::Realloc() n = 0 "));
131 uint_4 r,c;
[813]132 if (lcv == SameVectorType) lcv = GetVectorType();
133 else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType();
[804]134 if (lcv == ColumnVector) { r = n; c = 1; }
135 else { c = n; r = 1; }
136 TMatrix<T>::Realloc(r,c,SameMemoryMapping,force);
[813]137 veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_;
[762]138}
139
[804]140// $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
[894]141//! Return a subvector define by \b Range \b relt
[762]142template <class T>
[813]143TVector<T> TVector<T>::SubVector(Range relt) const
[762]144{
[804]145 Range rr, cr;
146 if (GetVectorType() == ColumnVector ) rr = relt;
147 else cr = relt;
148 TMatrix<T> const & mtx = (*this);
149 TVector sv( mtx(rr, cr) , true, GetVectorType(), GetMemoryMapping() );
150 sv.SetTemp(true);
151 return(sv);
[762]152}
153
[894]154//! Return the norm \f$ \sum{V(i)^2} \f$
[762]155template <class T>
[804]156T TVector<T>::Norm2() const
[762]157{
[804]158 T ret = 0;
159 for(uint_8 k=0; k<Size(); k++) ret += (*this)(k)*(*this)(k);
160 return ret;
[762]161}
162
[894]163//! Return info on number of rows, column and type \b T
[813]164template <class T>
165string TVector<T>::InfoString() const
166{
167 string rs = "TVector<";
168 rs += typeid(T).name();
169 char buff[64];
170 sprintf(buff, ">(%ld) (nr=%ld, nc=%ld)", (long)NElts(), (long)NRows(), (long)NCols());
171 rs += buff;
172 return(rs);
[804]173
[813]174}
175
[762]176///////////////////////////////////////////////////////////////
177#ifdef __CXX_PRAGMA_TEMPLATES__
178#pragma define_template TVector<uint_2>
179#pragma define_template TVector<int_4>
180#pragma define_template TVector<int_8>
181#pragma define_template TVector<r_4>
182#pragma define_template TVector<r_8>
183#pragma define_template TVector< complex<r_4> >
184#pragma define_template TVector< complex<r_8> >
185#endif
186
187#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
188template class TVector<uint_2>;
189template class TVector<int_4>;
190template class TVector<int_8>;
191template class TVector<r_4>;
192template class TVector<r_8>;
193template class TVector< complex<r_4> >;
194template class TVector< complex<r_8> >;
195#endif
[804]196
Note: See TracBrowser for help on using the repository browser.