[762] | 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"
|
---|
[804] | 7 | #include "tarray.h"
|
---|
[762] | 8 |
|
---|
| 9 | namespace SOPHYA {
|
---|
| 10 |
|
---|
| 11 | template <class T>
|
---|
[804] | 12 | class TMatrix : public TArray<T> {
|
---|
[762] | 13 | public:
|
---|
| 14 | // Creation / destruction
|
---|
| 15 | TMatrix();
|
---|
[804] | 16 | TMatrix(uint_4 r,uint_4 c, short mm=AutoMemoryMapping);
|
---|
[762] | 17 | TMatrix(const TMatrix<T>& a);
|
---|
[804] | 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);
|
---|
[762] | 21 | virtual ~TMatrix();
|
---|
| 22 |
|
---|
[804] | 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); }
|
---|
[762] | 27 |
|
---|
[804] | 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
|
---|
[762] | 32 |
|
---|
[804] | 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);
|
---|
[762] | 35 |
|
---|
[804] | 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 |
|
---|
[762] | 43 | // Operations matricielles
|
---|
[804] | 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);
|
---|
[762] | 49 |
|
---|
| 50 | // Operateur d'affectation
|
---|
[804] | 51 | // A = x (matrice diagonale Identite)
|
---|
| 52 | virtual TMatrix<T>& SetIdentity(IdentityMatrix imx);
|
---|
| 53 | inline TMatrix<T>& operator = (IdentityMatrix imx) { return SetIdentity(imx); }
|
---|
[762] | 54 |
|
---|
[804] | 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); }
|
---|
[762] | 61 |
|
---|
[804] | 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); }
|
---|
[762] | 65 |
|
---|
[804] | 66 | // Input-Output
|
---|
| 67 | virtual void Print(ostream& os, int_4 maxprt=-1, bool si=false) const ;
|
---|
[762] | 68 |
|
---|
[804] | 69 | // Produit matriciel
|
---|
| 70 | TMatrix<T> Multiply(const TMatrix<T>& b, short mm=SameMemoryMapping) const;
|
---|
| 71 | // inline TMatrix<T>& operator *= (const TMatrix<T>& b)
|
---|
[762] | 72 |
|
---|
| 73 | protected:
|
---|
| 74 | };
|
---|
| 75 |
|
---|
[804] | 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 | }
|
---|
[762] | 87 |
|
---|
| 88 | template <class T>
|
---|
[804] | 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 | }
|
---|
[762] | 98 |
|
---|
| 99 |
|
---|
[804] | 100 | // Surcharge d'operateurs C = A * B
|
---|
[762] | 101 |
|
---|
[804] | 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;}
|
---|
[762] | 104 |
|
---|
| 105 | typedef TMatrix<r_8> Matrix;
|
---|
| 106 |
|
---|
| 107 | } // Fin du namespace
|
---|
| 108 |
|
---|
| 109 | #endif
|
---|