Changeset 508 in Sophya for trunk/SophyaLib/NTools/matrix.h
- Timestamp:
- Oct 25, 1999, 12:36:22 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/matrix.h
r494 r508 18 18 // <summary> Operations matricielles </summary> 19 19 // Operations matricielles, algebre lineaire... 20 class Matrix : public PPersist, public AnyDataObj {21 friend class Vector;22 friend class MatrixRC;20 class OMatrix : public PPersist, public AnyDataObj { 21 friend class OVector; 22 friend class OMatrixRC; 23 23 friend class TMatrix<r_8>; 24 24 public: 25 Matrix();25 OMatrix(); 26 26 // Constructeur, matrice a zero 27 Matrix(int r, int c);27 OMatrix(int r, int c); 28 28 // Constructeur avec des valeurs. Pas d'allocation, juste pointe. 29 Matrix(int r, int c, double* values);29 OMatrix(int r, int c, double* values); 30 30 // Constructeur par copie 31 Matrix(constMatrix& a);31 OMatrix(const OMatrix& a); 32 32 // Constructeur par copie a partir d'une TMatrix<r_8> 33 Matrix(const TMatrix<r_8>& a);33 OMatrix(const TMatrix<r_8>& a); 34 34 // Destructeur 35 virtual ~ Matrix();35 virtual ~OMatrix(); 36 36 37 37 // Construction automatique pour PPF … … 39 39 enum {classId = ClassId_Matrix}; 40 40 int_4 ClassId() const { return classId; } 41 static PPersist* Create() {return new Matrix(1,1);}41 static PPersist* Create() {return new OMatrix(1,1);} 42 42 // </group> 43 43 … … 49 49 50 50 // Operateur d'affectation 51 Matrix& operator = (constMatrix& a);51 OMatrix& operator = (const OMatrix& a); 52 52 // Affectation depuis scalaire : identite * scalaire 53 Matrix& operator = (double x);53 OMatrix& operator = (double x); 54 54 55 55 // Impression 56 friend ostream& operator << (ostream& s, const Matrix& a);56 friend ostream& operator << (ostream& s, const OMatrix& a); 57 57 58 58 // Acces aux elements … … 74 74 // Operations matricielles avec scalaire, allocation d'une nouvelle matrice 75 75 // <group> 76 friend Matrix operator * (constMatrix& a, double b);77 friend Matrix operator * (double b, constMatrix& a);78 friend Matrix operator + (constMatrix& a, double b);79 friend Matrix operator + (double b, constMatrix& a);80 friend Matrix operator - (constMatrix& a, double b);81 friend Matrix operator - (double b, constMatrix& a);82 friend Matrix operator / (constMatrix& a, double b);76 friend OMatrix operator * (const OMatrix& a, double b); 77 friend OMatrix operator * (double b, const OMatrix& a); 78 friend OMatrix operator + (const OMatrix& a, double b); 79 friend OMatrix operator + (double b, const OMatrix& a); 80 friend OMatrix operator - (const OMatrix& a, double b); 81 friend OMatrix operator - (double b, const OMatrix& a); 82 friend OMatrix operator / (const OMatrix& a, double b); 83 83 // </group> 84 84 85 85 // Operations matricielles avec scalaires entiers, pour eviter l'appel 86 86 // du constructeur de vecteur a partir d'un entier... 87 // sinon v*2 = v * Vector(2), BUG !88 // <group> 89 friend Matrix operator * (constMatrix& a, int b);90 friend Matrix operator * (int b, constMatrix& a);91 friend Matrix operator + (constMatrix& a, int b);92 friend Matrix operator + (int b, constMatrix& a);93 friend Matrix operator - (constMatrix& a, int b);94 friend Matrix operator - (int b, constMatrix& a);95 friend Matrix operator / (constMatrix& a, int b);87 // sinon v*2 = v * OVector(2), BUG ! 88 // <group> 89 friend OMatrix operator * (const OMatrix& a, int b); 90 friend OMatrix operator * (int b, const OMatrix& a); 91 friend OMatrix operator + (const OMatrix& a, int b); 92 friend OMatrix operator + (int b, const OMatrix& a); 93 friend OMatrix operator - (const OMatrix& a, int b); 94 friend OMatrix operator - (int b, const OMatrix& a); 95 friend OMatrix operator / (const OMatrix& a, int b); 96 96 // </group> 97 97 98 98 // Operations matricielles "en place", avec scalaire 99 99 // <group> 100 Matrix& operator *= (double b);101 Matrix& operator += (double b);102 Matrix& operator -= (double b);103 Matrix& operator /= (double b);100 OMatrix& operator *= (double b); 101 OMatrix& operator += (double b); 102 OMatrix& operator -= (double b); 103 OMatrix& operator /= (double b); 104 104 // </group> 105 105 106 106 // Operations matricielles 107 107 // <group> 108 friend Matrix operator * (const Matrix& a, constMatrix& b);109 friend Matrix operator + (const Matrix& a, constMatrix& b);110 friend Matrix operator - (const Matrix& a, constMatrix& b);111 112 Matrix& operator *= (constMatrix& a);113 Matrix& operator += (constMatrix& b);114 Matrix& operator -= (constMatrix& b);108 friend OMatrix operator * (const OMatrix& a, const OMatrix& b); 109 friend OMatrix operator + (const OMatrix& a, const OMatrix& b); 110 friend OMatrix operator - (const OMatrix& a, const OMatrix& b); 111 112 OMatrix& operator *= (const OMatrix& a); 113 OMatrix& operator += (const OMatrix& b); 114 OMatrix& operator -= (const OMatrix& b); 115 115 // </group> 116 116 117 117 // Matrice transposee 118 Matrix Transpose() const;118 OMatrix Transpose() const; 119 119 // Matrice inverse 120 120 // <thrown> singMatxErr </thrown> 121 Matrix Inverse() const;121 OMatrix Inverse() const; 122 122 123 123 // Nombre de lignes … … 134 134 // Acces aux rangees et colonnes 135 135 // <group> 136 MatrixRC Row(int r) const;137 MatrixRC Col(int c) const;138 MatrixRC Diag() const;139 // </group> 140 /* Versions const ? Alors il faut constructeur const pour MatrixRC, */141 /* mais MatrixRC contient unMatrix* qui detruit const.... */136 OMatrixRC Row(int r) const; 137 OMatrixRC Col(int c) const; 138 OMatrixRC Diag() const; 139 // </group> 140 /* Versions const ? Alors il faut constructeur const pour OMatrixRC, */ 141 /* mais OMatrixRC contient un OMatrix* qui detruit const.... */ 142 142 /* mais en eux-meme, ils ne modifient pas la matrice. Ils permettent */ 143 143 /* de le faire... */ … … 145 145 // Pivot de Gauss : diagonalise la matrice A, en effectuant les memes 146 146 // operations sur la matrice B 147 static double GausPiv( Matrix& A,Matrix& B);147 static double GausPiv(OMatrix& A, OMatrix& B); 148 148 149 149 // Residus et fonction fittees. 150 Matrix FitResidus(GeneralFit& gfit150 OMatrix FitResidus(GeneralFit& gfit 151 151 ,double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 152 Matrix FitFunction(GeneralFit& gfit152 OMatrix FitFunction(GeneralFit& gfit 153 153 ,double xorg=0.,double yorg=0.,double dx=1.,double dy=1.); 154 154 … … 163 163 164 164 165 inline r_8& Matrix::operator()(int r, int c)165 inline r_8& OMatrix::operator()(int r, int c) 166 166 { 167 167 #ifdef RGCHECK … … 172 172 173 173 174 inline r_8 const& Matrix::operator()(int r, int c) const174 inline r_8 const& OMatrix::operator()(int r, int c) const 175 175 { 176 176 #ifdef RGCHECK … … 186 186 // Permet d'acceder a une ligne ou colonne d'une matrice, en place, comme 187 187 // avec un vecteur. 188 class MatrixRC EXC_AWARE {189 friend class Vector;190 friend class Matrix;188 class OMatrixRC EXC_AWARE { 189 friend class OVector; 190 friend class OMatrix; 191 191 public: 192 MatrixRC();193 194 virtual ~ MatrixRC() {}192 OMatrixRC(); 193 194 virtual ~OMatrixRC() {} 195 195 196 196 int Next(); … … 200 200 int SetDiag(); 201 201 202 static int Step(const Matrix& m, RCKind rckind);203 static double* Org(const Matrix&, RCKind rckind, int ind=0);202 static int Step(const OMatrix& m, RCKind rckind); 203 static double* Org(const OMatrix&, RCKind rckind, int ind=0); 204 204 205 205 int NElts() const; … … 207 207 r_8 operator()(int i) const; 208 208 209 MatrixRC& operator = (constMatrixRC& rc);210 //operator Vector() const;211 Vector GetVect() const;212 213 MatrixRC& operator += (constMatrixRC& rc);214 MatrixRC& operator -= (constMatrixRC& rc);215 216 MatrixRC& operator *= (double x);217 MatrixRC& operator /= (double x);218 MatrixRC& operator -= (double x);219 MatrixRC& operator += (double x);220 221 friend double operator * (const MatrixRC& a, constMatrixRC& b);222 223 MatrixRC& LinComb(double a, double b, constMatrixRC& rc, int first=0);224 MatrixRC& LinComb(double b, constMatrixRC& rc, int first=0);209 OMatrixRC& operator = (const OMatrixRC& rc); 210 //operator OVector() const; 211 OVector GetVect() const; 212 213 OMatrixRC& operator += (const OMatrixRC& rc); 214 OMatrixRC& operator -= (const OMatrixRC& rc); 215 216 OMatrixRC& operator *= (double x); 217 OMatrixRC& operator /= (double x); 218 OMatrixRC& operator -= (double x); 219 OMatrixRC& operator += (double x); 220 221 friend double operator * (const OMatrixRC& a, const OMatrixRC& b); 222 223 OMatrixRC& LinComb(double a, double b, const OMatrixRC& rc, int first=0); 224 OMatrixRC& LinComb(double b, const OMatrixRC& rc, int first=0); 225 225 226 226 int IMaxAbs(int first=0); 227 227 228 static void Swap( MatrixRC& rc1,MatrixRC& rc2);229 // comme c'est symetrique, soit c'est static MatrixRC, soit staticMatrix,230 // soit Matrix avec verification qu'on parle bien de la meme...228 static void Swap(OMatrixRC& rc1, OMatrixRC& rc2); 229 // comme c'est symetrique, soit c'est static OMatrixRC, soit static OMatrix, 230 // soit OMatrix avec verification qu'on parle bien de la meme... 231 231 232 232 protected: 233 MatrixRC(Matrix& m, RCKind kind, int index=0);234 Matrix* matrix;233 OMatrixRC(OMatrix& m, RCKind kind, int index=0); 234 OMatrix* matrix; 235 235 r_8* data; 236 236 int index; … … 240 240 241 241 242 inline int MatrixRC::Step(constMatrix& m, RCKind rckind)242 inline int OMatrixRC::Step(const OMatrix& m, RCKind rckind) 243 243 { 244 244 switch (rckind) … … 255 255 256 256 257 inline double* MatrixRC::Org(constMatrix& m, RCKind rckind, int index)257 inline double* OMatrixRC::Org(const OMatrix& m, RCKind rckind, int index) 258 258 { 259 259 switch (rckind) … … 270 270 271 271 272 inline int MatrixRC::NElts() const272 inline int OMatrixRC::NElts() const 273 273 { 274 274 if (!matrix) return -1; // Failure ? … … 287 287 288 288 289 inline double& MatrixRC::operator()(int i)289 inline double& OMatrixRC::operator()(int i) 290 290 { 291 291 return data[i*step]; … … 293 293 294 294 295 inline double MatrixRC::operator()(int i) const295 inline double OMatrixRC::operator()(int i) const 296 296 { 297 297 return data[i*step];
Note:
See TracChangeset
for help on using the changeset viewer.