source: Sophya/trunk/SophyaLib/TArray/tmatrix.h@ 956

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

encore de la doc cmv 17/04/00

File size: 5.9 KB
Line 
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
9namespace SOPHYA {
10
11//! Class of matrices
12template <class T>
13class TMatrix : public TArray<T> {
14public:
15 // Creation / destruction
16 TMatrix();
17 TMatrix(uint_4 r,uint_4 c, short mm=AutoMemoryMapping);
18 TMatrix(const TMatrix<T>& a);
19 TMatrix(const TMatrix<T>& a, bool share);
20 TMatrix(const TArray<T>& a);
21 TMatrix(const TArray<T>& a, bool share, short mm=AutoMemoryMapping);
22 virtual ~TMatrix();
23
24 // Pour verifiez la compatibilite de dimensions lors de l'affectation
25 virtual TArray<T>& Set(const TArray<T>& a);
26 //! Operator = between matrices
27 inline TMatrix<T>& operator = (const TMatrix<T>& a)
28 { Set(a); return(*this); }
29
30 // Size - Changing the Size
31 //! return number of rows
32 inline uint_4 NRows() const {return Size(marowi_); }
33 //! return number of columns
34 inline uint_4 NCols() const {return Size(macoli_); }
35 //! return number of columns
36 inline uint_4 NCol() const {return Size(macoli_); } // back-compat Peida
37
38 void ReSize(uint_4 r,uint_4 c, short mm=SameMemoryMapping); // Reallocation de place
39 void Realloc(uint_4 r,uint_4 c, short mm=SameMemoryMapping, bool force=false);
40
41 // Sub-matrix extraction $CHECK$ Reza 03/2000 Doit-on declarer ces methode const ?
42 TMatrix<T> SubMatrix(Range rline, Range rcol) const ;
43 //! () : Return submatrix define by \b Range \b rline and \b rcol
44 inline TMatrix<T> operator () (Range rline, Range rcol) const
45 { return SubMatrix(rline, rcol); }
46 // Lignes et colonnes de la matrice
47 //! Return submatrix define by line \b ir (line vector)
48 inline TMatrix<T> Row(uint_4 ir) const
49 { return SubMatrix(Range(ir,ir), Range(0,NCols()-1)); }
50 //! Return submatrix define by column \b ic (column vector)
51 inline TMatrix<T> Column(uint_4 ic) const
52 { return SubMatrix(Range(0,NRows()-1), Range(ic,ic)); }
53
54 // Inline element acces methods
55 inline T const& operator()(uint_4 r,uint_4 c) const;
56 inline T& operator()(uint_4 r,uint_4 c);
57
58 // Operations matricielles
59 TMatrix<T>& Transpose();
60 //mm = SameMemoryMapping or CMemoryMapping or FortranMemoryMapping
61 TMatrix<T> Transpose(short mm);
62 // Rearranging Matrix Elements
63 TMatrix<T> Rearrange(short mm);
64
65 // Operateur d'affectation
66 // A = x (matrice diagonale Identite)
67 virtual TMatrix<T>& SetIdentity(IdentityMatrix imx);
68 // = : fill matrix with an identity matrix \b imx
69 inline TMatrix<T>& operator = (IdentityMatrix imx) { return SetIdentity(imx); }
70
71 // = : fill matrix with a Sequence \b seq
72 inline TMatrix<T>& operator = (Sequence seq) { SetSeq(seq); return(*this); }
73
74 // Operations diverses avec une constante
75 //! = : fill matrix with constant value \b x
76 inline TMatrix<T>& operator = (T x) { SetT(x); return(*this); }
77 //! += : add constant value \b x to matrix
78 inline TMatrix<T>& operator += (T x) { Add(x); return(*this); }
79 //! -= : substract constant value \b x to matrix
80 inline TMatrix<T>& operator -= (T x) { Sub(x); return(*this); }
81 //! *= : multiply matrix by constant value \b x
82 inline TMatrix<T>& operator *= (T x) { Mul(x); return(*this); }
83 //! /= : divide matrix by constant value \b x
84 inline TMatrix<T>& operator /= (T x) { Div(x); return(*this); }
85
86 // operations avec matrices
87 //! += : add a matrix
88 inline TMatrix<T>& operator += (const TMatrix<T>& a) { AddElt(a); return(*this); }
89 //! -= : substract a matrix
90 inline TMatrix<T>& operator -= (const TMatrix<T>& a) { SubElt(a); return(*this); }
91 TMatrix<T> Multiply(const TMatrix<T>& b, short mm=SameMemoryMapping) const;
92 //! *= : matrix product : C = (*this)*B
93 inline TMatrix<T>& operator *= (const TMatrix<T>& b)
94 { this->Set(Multiply(b)); return(*this); }
95
96 // I/O print, ...
97 virtual string InfoString() const;
98 virtual void Print(ostream& os, int_4 maxprt=-1, bool si=false) const ;
99
100protected:
101};
102
103// ---- inline acces methods ------
104 //! () : return element for line \b r and column \b c
105template <class T>
106inline T const& TMatrix<T>::operator()(uint_4 r, uint_4 c) const
107{
108#ifdef SO_BOUNDCHECKING
109 if (marowi_ == 0) CheckBound(r, c, 0, 0, 0, 4);
110 else CheckBound(c, r, 0, 0, 0, 4);
111#endif
112 return ( *( mNDBlock.Begin()+ offset_+
113 r*step_[marowi_] + c*step_[macoli_] ) );
114}
115
116//! () : return element for line \b r and column \b c
117template <class T>
118inline T & TMatrix<T>::operator()(uint_4 r, uint_4 c)
119{
120#ifdef SO_BOUNDCHECKING
121 if (marowi_ == 0) CheckBound(r, c, 0, 0, 0, 4);
122 else CheckBound(c, r, 0, 0, 0, 4);
123#endif
124 return ( *( mNDBlock.Begin()+ offset_+
125 r*step_[marowi_] + c*step_[macoli_] ) );
126}
127
128
129// Surcharge d'operateurs C = A (+,-) B
130// $CHECK$ Reza 3/4/2000 Pas necessaire de redefinir les operateurs
131// Defini au niveau de TArray<T> - Pour ameliorer l'efficacite
132// Doit-on le faire aussi pour les constantes ? - Fin de $CHECK$ Reza 3/4/2000
133
134//! + : add matrixes \b a and \b b
135template <class T>
136inline TMatrix<T> operator + (const TMatrix<T>& a,const TMatrix<T>& b)
137 {TMatrix<T> result(a); result.SetTemp(true); result.AddElt(b); return result;}
138
139//! - : substract matrixes \b a and \b b
140template <class T>
141inline TMatrix<T> operator - (const TMatrix<T>& a,const TMatrix<T>& b)
142 {TMatrix<T> result(a); result.SetTemp(true); result.SubElt(b); return result;}
143
144// Surcharge d'operateurs C = A * B
145//! - : multiply matrixes \b a and \b b
146template <class T> inline TMatrix<T> operator * (const TMatrix<T>& a, const TMatrix<T>& b)
147{ TMatrix<T> result(a); result.SetTemp(true); return(result.Multiply(b)); }
148
149// Typedef pour simplifier et compatibilite Peida
150/*! \ingroup TArray
151 \typedef Matrix
152 \brief To simplified TMatrix<r_8> writing
153*/
154typedef TMatrix<r_8> Matrix;
155
156} // Fin du namespace
157
158#endif
Note: See TracBrowser for help on using the repository browser.