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

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

documentation cmv 13/4/00

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