| 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
| 2 | //                         C.Magneville          04/99
 | 
|---|
| 3 | #ifndef TMatrix_SEEN
 | 
|---|
| 4 | #define TMatrix_SEEN
 | 
|---|
| 5 | 
 | 
|---|
| 6 | #include "machdefs.h"
 | 
|---|
| 7 | #include "tarray.h"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | namespace SOPHYA {
 | 
|---|
| 10 | 
 | 
|---|
| 11 | template <class T>
 | 
|---|
| 12 | class TMatrix : public TArray<T> {
 | 
|---|
| 13 | public:
 | 
|---|
| 14 |   // Creation / destruction 
 | 
|---|
| 15 |   TMatrix();
 | 
|---|
| 16 |   TMatrix(uint_4 r,uint_4 c, short mm=AutoMemoryMapping);
 | 
|---|
| 17 |   TMatrix(const TMatrix<T>& a);
 | 
|---|
| 18 |   TMatrix(const TMatrix<T>& a, bool share);
 | 
|---|
| 19 |   TMatrix(const TArray<T>& a); 
 | 
|---|
| 20 |   TMatrix(const TArray<T>& a,  bool share, short mm=CMemoryMapping);
 | 
|---|
| 21 |   virtual ~TMatrix();
 | 
|---|
| 22 | 
 | 
|---|
| 23 |   //  Pour verifiez la compatibilite de dimensions lors de l'affectation
 | 
|---|
| 24 |   virtual TArray<T>& Set(const TArray<T>& a);
 | 
|---|
| 25 |   inline  TMatrix<T>& operator = (const TMatrix<T>& a)
 | 
|---|
| 26 |                        { Set(a);  return(*this); }
 | 
|---|
| 27 | 
 | 
|---|
| 28 |   // Size - Changing the Size 
 | 
|---|
| 29 |   inline uint_4 NRows() const {return Size(marowi_); }
 | 
|---|
| 30 |   inline uint_4 NCols() const {return Size(macoli_); }
 | 
|---|
| 31 |   inline uint_4 NCol()  const {return Size(macoli_); } // back-compat Peida
 | 
|---|
| 32 | 
 | 
|---|
| 33 |   void ReSize(uint_4 r,uint_4 c, short mm=SameMemoryMapping);  // Reallocation de place
 | 
|---|
| 34 |   void Realloc(uint_4 r,uint_4 c, short mm=SameMemoryMapping, bool force=false);
 | 
|---|
| 35 | 
 | 
|---|
| 36 |   // Sub-matrix extraction $CHECK$ Reza 03/2000  Doit-on declarer cette methode const ?
 | 
|---|
| 37 |   TMatrix<T> operator () (Range rline, Range rcol) const ;
 | 
|---|
| 38 | 
 | 
|---|
| 39 |   // Inline element acces methods 
 | 
|---|
| 40 |   inline T const& operator()(uint_4 r,uint_4 c) const;
 | 
|---|
| 41 |   inline T&       operator()(uint_4 r,uint_4 c);
 | 
|---|
| 42 | 
 | 
|---|
| 43 |   // Operations matricielles
 | 
|---|
| 44 |   TMatrix<T>& Transpose();
 | 
|---|
| 45 |   //mm = SameMemoryMapping or CMemoryMapping or FortranMemoryMapping 
 | 
|---|
| 46 |   TMatrix<T>  Transpose(short mm); 
 | 
|---|
| 47 |   // Rearranging Matrix Elements
 | 
|---|
| 48 |   TMatrix<T>  Rearrange(short mm);
 | 
|---|
| 49 | 
 | 
|---|
| 50 |   // Operateur d'affectation
 | 
|---|
| 51 |   // A = x (matrice diagonale Identite)
 | 
|---|
| 52 |   virtual TMatrix<T>& SetIdentity(IdentityMatrix imx);
 | 
|---|
| 53 |   inline  TMatrix<T>& operator = (IdentityMatrix imx) { return SetIdentity(imx); }
 | 
|---|
| 54 | 
 | 
|---|
| 55 |   // Operations diverses  avec une constante
 | 
|---|
| 56 |   inline  TMatrix<T>&  operator = (T x)             { Set(x); return(*this); }
 | 
|---|
| 57 |   inline  TMatrix<T>&  operator += (T x)            { Add(x); return(*this); }
 | 
|---|
| 58 |   inline  TMatrix<T>&  operator -= (T x)            { Sub(x); return(*this); }
 | 
|---|
| 59 |   inline  TMatrix<T>&  operator *= (T x)            { Mul(x); return(*this); }
 | 
|---|
| 60 |   inline  TMatrix<T>&  operator /= (T x)            { Div(x); return(*this); }
 | 
|---|
| 61 | 
 | 
|---|
| 62 |   //  operations avec matrices 
 | 
|---|
| 63 |   inline  TMatrix<T>&  operator += (const TMatrix<T>& a)  { return AddElt(a); }
 | 
|---|
| 64 |   inline  TMatrix<T>&  operator -= (const TMatrix<T>& a)  { return SubElt(a); }
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   // Input-Output
 | 
|---|
| 67 |   virtual void  Print(ostream& os, int_4 maxprt=-1, bool si=false) const ;
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   // Produit matriciel 
 | 
|---|
| 70 |   TMatrix<T>  Multiply(const TMatrix<T>& b, short mm=SameMemoryMapping) const;
 | 
|---|
| 71 |   //  inline TMatrix<T>& operator *= (const TMatrix<T>& b) 
 | 
|---|
| 72 | 
 | 
|---|
| 73 | protected:
 | 
|---|
| 74 | };
 | 
|---|
| 75 | 
 | 
|---|
| 76 | //  ---- inline acces methods ------
 | 
|---|
| 77 | template <class T>
 | 
|---|
| 78 | inline T const& TMatrix<T>::operator()(uint_4 r, uint_4 c) const
 | 
|---|
| 79 | {
 | 
|---|
| 80 | #ifdef SO_BOUNDCHECKING
 | 
|---|
| 81 |   if (marowi_ == 0)   CheckBound(r, c, 0, 0, 0, 4);
 | 
|---|
| 82 |   else   CheckBound(c, r, 0, 0, 0, 4);
 | 
|---|
| 83 | #endif
 | 
|---|
| 84 |   return ( *( mNDBlock.Begin()+ offset_+ 
 | 
|---|
| 85 |               r*step_[marowi_] + c*step_[macoli_] ) );
 | 
|---|
| 86 | }
 | 
|---|
| 87 | 
 | 
|---|
| 88 | template <class T>
 | 
|---|
| 89 | inline T & TMatrix<T>::operator()(uint_4 r, uint_4 c) 
 | 
|---|
| 90 | {
 | 
|---|
| 91 | #ifdef SO_BOUNDCHECKING
 | 
|---|
| 92 |   if (marowi_ == 0)   CheckBound(r, c, 0, 0, 0, 4);
 | 
|---|
| 93 |   else   CheckBound(c, r, 0, 0, 0, 4);
 | 
|---|
| 94 | #endif
 | 
|---|
| 95 |   return ( *( mNDBlock.Begin()+ offset_+ 
 | 
|---|
| 96 |               r*step_[marowi_] + c*step_[macoli_] ) );
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | 
 | 
|---|
| 100 | // Surcharge d'operateurs C = A * B
 | 
|---|
| 101 | 
 | 
|---|
| 102 | template <class T> inline TMatrix<T> operator * (const TMatrix<T>& a, const TMatrix<T>& b)
 | 
|---|
| 103 | { TMatrix<T> result(a); result.SetTemp(true); result.Multiply(b);  return result;}
 | 
|---|
| 104 | 
 | 
|---|
| 105 | typedef TMatrix<r_8> Matrix;
 | 
|---|
| 106 | 
 | 
|---|
| 107 | } // Fin du namespace
 | 
|---|
| 108 | 
 | 
|---|
| 109 | #endif
 | 
|---|