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

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

modifs doc cmv 27/4/00

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