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

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

documentation cmv 12/4/00

File size: 5.8 KB
RevLine 
[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
9namespace SOPHYA {
10
[894]11//! Class of matrixes
12/*!
13 \sa TArray
14 */
15
[762]16template <class T>
[804]17class TMatrix : public TArray<T> {
[762]18public:
19 // Creation / destruction
20 TMatrix();
[804]21 TMatrix(uint_4 r,uint_4 c, short mm=AutoMemoryMapping);
[762]22 TMatrix(const TMatrix<T>& a);
[804]23 TMatrix(const TMatrix<T>& a, bool share);
24 TMatrix(const TArray<T>& a);
25 TMatrix(const TArray<T>& a, bool share, short mm=CMemoryMapping);
[762]26 virtual ~TMatrix();
27
[804]28 // Pour verifiez la compatibilite de dimensions lors de l'affectation
29 virtual TArray<T>& Set(const TArray<T>& a);
[894]30 //! Operator = between matrices
[804]31 inline TMatrix<T>& operator = (const TMatrix<T>& a)
[894]32 { Set(a); return(*this); }
[762]33
[804]34 // Size - Changing the Size
[894]35 //! return number of rows
[804]36 inline uint_4 NRows() const {return Size(marowi_); }
[894]37 //! return number of columns
[804]38 inline uint_4 NCols() const {return Size(macoli_); }
[894]39 //! return number of columns
[804]40 inline uint_4 NCol() const {return Size(macoli_); } // back-compat Peida
[762]41
[804]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);
[762]44
[813]45 // Sub-matrix extraction $CHECK$ Reza 03/2000 Doit-on declarer ces methode const ?
46 TMatrix<T> SubMatrix(Range rline, Range rcol) const ;
[894]47 //! () : Return submatrix define by \b Range \b rline and \b rcol
[813]48 inline TMatrix<T> operator () (Range rline, Range rcol) const
49 { return SubMatrix(rline, rcol); }
50 // Lignes et colonnes de la matrice
[894]51 //! Return submatrix define by line \b ir (line vector)
[813]52 inline TMatrix<T> Row(uint_4 ir) const
53 { return SubMatrix(Range(ir,ir), Range(0,NCols()-1)); }
[894]54 //! Return submatrix define by column \b ic (column vector)
[813]55 inline TMatrix<T> Column(uint_4 ic) const
56 { return SubMatrix(Range(0,NRows()-1), Range(ic,ic)); }
[804]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
[762]62 // Operations matricielles
[804]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);
[762]68
69 // Operateur d'affectation
[804]70 // A = x (matrice diagonale Identite)
71 virtual TMatrix<T>& SetIdentity(IdentityMatrix imx);
[894]72 // = : fill matrix with an identity matrix \b imx
[804]73 inline TMatrix<T>& operator = (IdentityMatrix imx) { return SetIdentity(imx); }
[762]74
[894]75 // = : fill matrix with a Sequence \b seq
[813]76 inline TMatrix<T>& operator = (Sequence seq) { SetSeq(seq); return(*this); }
77
[804]78 // Operations diverses avec une constante
[894]79 //! = : fill matrix with constant value \b x
[813]80 inline TMatrix<T>& operator = (T x) { SetT(x); return(*this); }
[894]81 //! += : add constant value \b x to matrix
[804]82 inline TMatrix<T>& operator += (T x) { Add(x); return(*this); }
[894]83 //! -= : substract constant value \b x to matrix
[804]84 inline TMatrix<T>& operator -= (T x) { Sub(x); return(*this); }
[894]85 //! *= : multiply matrix by constant value \b x
[804]86 inline TMatrix<T>& operator *= (T x) { Mul(x); return(*this); }
[894]87 //! /= : divide matrix by constant value \b x
[804]88 inline TMatrix<T>& operator /= (T x) { Div(x); return(*this); }
[762]89
[804]90 // operations avec matrices
[894]91 //! += : add a matrix
[813]92 inline TMatrix<T>& operator += (const TMatrix<T>& a) { AddElt(a); return(*this); }
[894]93 //! -= : substract a matrix
[813]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;
[894]96 //! *= : matrix product : C = (*this)*B
[813]97 inline TMatrix<T>& operator *= (const TMatrix<T>& b)
98 { this->Set(Multiply(b)); return(*this); }
[762]99
[813]100 // I/O print, ...
101 virtual string InfoString() const;
[804]102 virtual void Print(ostream& os, int_4 maxprt=-1, bool si=false) const ;
[762]103
104protected:
105};
106
[804]107// ---- inline acces methods ------
[894]108 //! () : return element for line \b r and column \b c
[804]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}
[762]119
[894]120//! () : return element for line \b r and column \b c
[762]121template <class T>
[804]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}
[762]131
132
[813]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
[894]138//! + : add matrixes \b a and \b b
[813]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
[894]143//! - : substract matrixes \b a and \b b
[813]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
[804]148// Surcharge d'operateurs C = A * B
[894]149//! - : multiply matrixes \b a and \b b
[804]150template <class T> inline TMatrix<T> operator * (const TMatrix<T>& a, const TMatrix<T>& b)
[813]151{ TMatrix<T> result(a); result.SetTemp(true); return(result.Multiply(b)); }
[762]152
[894]153//! Define Matrix to be TMatrix<r_8>
[762]154typedef TMatrix<r_8> Matrix;
155
156} // Fin du namespace
157
158#endif
Note: See TracBrowser for help on using the repository browser.