Changeset 804 in Sophya for trunk/SophyaLib/TArray/tvector.h


Ignore:
Timestamp:
Apr 3, 2000, 7:36:01 PM (25 years ago)
Author:
ansari
Message:

Amelioation / debugging de la classe TArray<T> - TVector et TMatrix

heritent maintenant de TArray<T> - Classe RCMatrix rendu prive au fichier
sopemtx.cc - linfit.cc integre a sopemtx.cc

Reza 03/04/2000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/tvector.h

    r772 r804  
    1111class TVector : public TMatrix<T> {
    1212public:
     13  enum {SameTypeVector=0, ColumnVector=1, LineVector=2};
     14  // Creation / destruction
     15  TVector();
     16  TVector(uint_4 n, short lcv=ColumnVector, short mm=AutoMemoryMapping);
     17  TVector(const TVector<T>& v);
     18  TVector(const TVector<T>& v, bool share);
     19  TVector(const TArray<T>& a);
     20  TVector(const TArray<T>& a,  bool share, short lcv=ColumnVector, short mm=CMemoryMapping);
    1321
    14   // Creation / destruction
    15   TVector(uint_4 n=1);
    16   TVector(uint_4 n, T* values,Bridge* br=NULL);
    17   TVector(const TVector<T>& v);
    18   TVector(const TVector<T>& v,bool share);
    19   TVector(const TMatrix<T>& a);
     22  virtual ~TVector();
     23
     24  inline  TVector<T>& operator = (const TVector<T>& a)
     25                       { Set(a);  return(*this); }
     26
     27  // Vector type   Line or Column vector
     28  inline short GetVectorType() const
     29               { return((marowi_ == veceli_) ? ColumnVector : LineVector); }
    2030
    2131  // Gestion taille/Remplissage
    22   inline void ReSize(uint_4 n) {TMatrix<T>::ReSize(n,1);} // Reallocation de place
    23   inline void Realloc(uint_4 n,bool force=false) {TMatrix<T>::Realloc(n,1,force);}
     32  void ReSize(uint_4 n, short lcv=SameTypeVector );
     33  void Realloc(uint_4 n, short lcv=SameTypeVector, bool force=false);
     34
     35  // Sub-Vector extraction $CHECK$ Reza 03/2000  Doit-on declarer cette methode const ?
     36  TVector<T> operator () (Range relt) const ;
    2437
    2538  // Informations pointeur/data
    26   inline uint_4 NElts() const {return NRows();}
     39  inline uint_4 NElts() const {return Size(); }
    2740 
    28   // Acces aux elements
    29   inline T& operator()(uint_4 n) {return (*this)[n];}
    30   inline T const& operator()(uint_4 n) const {return (*this)[n];}
    31   inline T& Element(uint_4 n) {return (*this)[n];}
    32   inline T const& Element(uint_4 n) const {return (*this)[n];}
     41  // Inline element acces methods
     42  inline T const& operator()(uint_4 n) const;
     43  inline T&       operator()(uint_4 n);
    3344
    34   // Operateur d'affectation
    35   inline TVector& operator = (const TVector& v)
    36                   {TMatrix<T>::operator =(v); return *this;}
    37   inline TVector& operator = (T x)
    38                   {for(uint_4 i=0;i<NRows();i++) (*this)(i)=x; return *this;}
     45  // Operations diverses  avec une constante
     46  inline  TVector<T>&  operator = (T x)             { Set(x); return(*this); }
     47  inline  TVector<T>&  operator += (T x)            { Add(x); return(*this); }
     48  inline  TVector<T>&  operator -= (T x)            { Sub(x); return(*this); }
     49  inline  TVector<T>&  operator *= (T x)            { Mul(x); return(*this); }
     50  inline  TVector<T>&  operator /= (T x)            { Div(x); return(*this); }
    3951
     52  //  operations avec matrices
     53  inline  TVector<T>&  operator += (const TVector<T>& a)  { AddElt(a); return(*this); }
     54  inline  TVector<T>&  operator -= (const TVector<T>& a)  { SubElt(a); return(*this); }
    4055
     56  // Norme(^2)
     57  T Norm2() const ;
    4158};
    4259
    43 // produit scalaire, matrice*vecteur
     60//  ---- inline acces methods ------
    4461template <class T>
    45 inline T operator* (const TVector<T>& v1, const TVector<T>& v2)
    46   {if(v1.NRows() != v2.NRows())
    47      throw(SzMismatchError("TVector::operator*(TVector& v1,TVector v2) size mismatch"));
    48    T *p = const_cast<T *>(v1.Data()), *pEnd = p+v1.NElts(),
    49      *q = const_cast<T *>(v2.Data()), r = 0;
    50    while (p<pEnd) r += *p++ * *q++;
    51    return r;}
     62inline T const& TVector<T>::operator()(uint_4 n) const
     63{
     64#ifdef SO_BOUNDCHECKING
     65  if (veceli__ == 0)   CheckBound(n, 0, 0, 0, 0, 4);
     66  else   CheckBound(0, n, 0, 0, 0, 4);
     67#endif
     68  return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
     69}
    5270
    5371template <class T>
    54 inline TVector<T> operator* (const TMatrix<T>& a, const TVector<T>& b)
    55    {return TVector<T>(a * ((TMatrix<T> const&)(b)));}
    56 
     72inline T & TVector<T>::operator()(uint_4 n)
     73{
     74#ifdef SO_BOUNDCHECKING
     75  if (veceli__ == 0)   CheckBound(n, 0, 0, 0, 0, 4);
     76  else   CheckBound(0, n, 0, 0, 0, 4);
     77#endif
     78  return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
     79}
    5780
    5881// Typedef pour simplifier et compatibilite Peida
    5982typedef TVector<r_8> Vector;
    6083
    61 /////////////////////////////////////////////////////////////////////////
    62 // Classe pour la gestion de persistance
    63 template <class T>
    64 class FIO_TVector : public  PPersist  {
    65 public:
    66   FIO_TVector();
    67   FIO_TVector(string const & filename);
    68   FIO_TVector(const TVector<T> & obj);
    69   FIO_TVector(TVector<T> * obj);
    70   virtual ~FIO_TVector();
    71   virtual AnyDataObj* DataObj();
    72   virtual void        SetDataObj(AnyDataObj & o);
    73   inline operator TVector<T>() { return(*dobj); }
    74 protected :
    75   virtual void ReadSelf(PInPersist&);           
    76   virtual void WriteSelf(POutPersist&) const; 
    77   TVector<T> * dobj;
    78   bool ownobj;
    79 };
    80 
    81 template <class T>
    82 inline POutPersist& operator << (POutPersist& os, TVector<T> & obj)
    83 { FIO_TVector<T> fio(&obj);  fio.Write(os);  return(os); }
    84 template <class T>
    85 inline PInPersist& operator >> (PInPersist& is, TVector<T> & obj)
    86 { FIO_TVector<T> fio(&obj);  fio.Read(is);  return(is); }
    87 
    8884} // Fin du namespace
    8985
Note: See TracChangeset for help on using the changeset viewer.