// $Id: tvector.cc,v 1.5 2000-04-13 16:04:49 ansari Exp $ // C.Magneville 04/99 #include "machdefs.h" #include #include "pexceptions.h" #include "tvector.h" //////////////////////////////////////////////////////////////// //**** Createur, Destructeur //! Default constructor template TVector::TVector() : TMatrix() { } //! construct a vector /*! \param n : number of elements \param lcv : line or column vector ? \param mm : memory mapping type \sa SelectVectorType */ template TVector::TVector(uint_4 n, short lcv, short mm) // Constructeur : TMatrix(1,1,mm) { lcv = SelectVectorType(lcv); ReSize(n,lcv); } //! Constructor by copy (share if \b a is temporary) template TVector::TVector(const TVector& a) // Constructeur par copie (partage si "a" temporaire). : TMatrix(a) { } //! Constructor by copy /*! \param share : if true, share data. If false copy data */ template TVector::TVector(const TVector& a, bool share) // Constructeur par copie avec possibilite de forcer le partage ou non. : TMatrix(a, share) { } //! Constructor from a TArray template TVector::TVector(const TArray& a) : TMatrix(a) { if ( (size_[0] != 1) && (size_[1] != 1) ) throw SzMismatchError("TVector::TVector(const TArray& a) NRows()!=1 && NCols()!=1 "); } //! Constructor of a vector from a TArray \b a /*! \param a : TArray to be copied or shared \param share : if true, share data. If false copy data \param mm : define the memory mapping type \param lcv : line or column vector ? \sa SelectVectorType */ template TVector::TVector(const TArray& a, bool share, short lcv, short mm) : TMatrix(a, share, mm) { if ( (size_[0] != 1) && (size_[1] != 1) ) throw SzMismatchError("TVector::TVector(const TArray& a) NRows()!=1 && NCols()!=1 "); if ( (size_[0] == 1) && (size_[1] == 1) ) { if (lcv == SameVectorType) lcv = a.GetVectorType(); if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType(); veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_; } } //! Destructor template TVector::~TVector() { } //! Resize the vector /*! \param n : number of elements \param lcv : line or column vector ? \sa SelectVectorType */ template void TVector::ReSize(uint_4 n, short lcv) { if( n == 0 ) throw(SzMismatchError("TVector::ReSize() n = 0 ")); uint_4 r,c; if (lcv == SameVectorType) lcv = GetVectorType(); else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType(); if (lcv == ColumnVector) { r = n; c = 1; } else { c = n; r = 1; } TMatrix::ReSize(r,c); veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_; } //! Re-allocate space for the vector /*! \param n : number of elements \param lcv : line or column vector ? \param force : if true re-allocation is forced, if not it occurs only if the required space is greater than the old one. \sa ReSize SelectVectorType */ template void TVector::Realloc(uint_4 n, short lcv, bool force) { if( n == 0 ) throw(SzMismatchError("TVector::Realloc() n = 0 ")); uint_4 r,c; if (lcv == SameVectorType) lcv = GetVectorType(); else if ( (lcv != ColumnVector) && (lcv != RowVector) ) lcv = GetDefaultVectorType(); if (lcv == ColumnVector) { r = n; c = 1; } else { c = n; r = 1; } TMatrix::Realloc(r,c,SameMemoryMapping,force); veceli_ = (lcv == ColumnVector ) ? marowi_ : macoli_; } // $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ? //! Return a subvector define by \b Range \b relt template TVector TVector::SubVector(Range relt) const { Range rr, cr; if (GetVectorType() == ColumnVector ) rr = relt; else cr = relt; TMatrix const & mtx = (*this); TVector sv( mtx(rr, cr) , true, GetVectorType(), GetMemoryMapping() ); sv.SetTemp(true); return(sv); } //! Return the norm \f$ \sum{V(i)^2} \f$ template T TVector::Norm2() const { T ret = 0; for(uint_8 k=0; k string TVector::InfoString() const { string rs = "TVector<"; rs += typeid(T).name(); char buff[64]; sprintf(buff, ">(%ld) (nr=%ld, nc=%ld)", (long)NElts(), (long)NRows(), (long)NCols()); rs += buff; return(rs); } /////////////////////////////////////////////////////////////// #ifdef __CXX_PRAGMA_TEMPLATES__ #pragma define_template TVector #pragma define_template TVector #pragma define_template TVector #pragma define_template TVector #pragma define_template TVector #pragma define_template TVector< complex > #pragma define_template TVector< complex > #endif #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) template class TVector; template class TVector; template class TVector; template class TVector; template class TVector; template class TVector< complex >; template class TVector< complex >; #endif