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

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

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