Changeset 508 in Sophya for trunk/SophyaLib/NTools/matrix.h


Ignore:
Timestamp:
Oct 25, 1999, 12:36:22 PM (26 years ago)
Author:
ansari
Message:

Vector/Matrix OVector/OMatrix cmv 25/10/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/matrix.h

    r494 r508  
    1818// <summary> Operations matricielles </summary>
    1919// Operations matricielles, algebre lineaire...
    20 class Matrix : public PPersist, public AnyDataObj {
    21   friend class Vector;
    22   friend class MatrixRC;
     20class OMatrix : public PPersist, public AnyDataObj {
     21  friend class OVector;
     22  friend class OMatrixRC;
    2323  friend class TMatrix<r_8>;
    2424public:
    25   Matrix();
     25  OMatrix();
    2626  // Constructeur, matrice a zero
    27   Matrix(int r, int c);
     27  OMatrix(int r, int c);
    2828  // 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);
    3030  // Constructeur par copie
    31   Matrix(const Matrix& a);
     31  OMatrix(const OMatrix& a);
    3232  // Constructeur par copie a partir d'une TMatrix<r_8>
    33   Matrix(const TMatrix<r_8>& a);
     33  OMatrix(const TMatrix<r_8>& a);
    3434  // Destructeur
    35   virtual ~Matrix();
     35  virtual ~OMatrix();
    3636
    3737  // Construction automatique pour PPF
     
    3939  enum {classId = ClassId_Matrix};
    4040  int_4                 ClassId() const         { return classId; }
    41   static PPersist*      Create() {return new Matrix(1,1);}
     41  static PPersist*      Create() {return new OMatrix(1,1);}
    4242  // </group>
    4343
     
    4949
    5050  // Operateur d'affectation
    51   Matrix& operator = (const Matrix& a);
     51  OMatrix& operator = (const OMatrix& a);
    5252  // Affectation depuis scalaire : identite * scalaire
    53   Matrix& operator = (double x);
     53  OMatrix& operator = (double x);
    5454
    5555  // Impression
    56   friend ostream& operator << (ostream& s, const Matrix& a);
     56  friend ostream& operator << (ostream& s, const OMatrix& a);
    5757
    5858  // Acces aux elements
     
    7474  // Operations matricielles avec scalaire, allocation d'une nouvelle matrice
    7575  // <group>
    76   friend Matrix operator * (const Matrix& a, double b);
    77   friend Matrix operator * (double b, const Matrix& a);
    78   friend Matrix operator + (const Matrix& a, double b);
    79   friend Matrix operator + (double b, const Matrix& a);
    80   friend Matrix operator - (const Matrix& a, double b);
    81   friend Matrix operator - (double b, const Matrix& a);
    82   friend Matrix operator / (const Matrix& 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);
    8383  // </group>
    8484
    8585  // Operations matricielles avec scalaires entiers, pour eviter l'appel
    8686  // du constructeur de vecteur a partir d'un entier...
    87   // sinon v*2 = v * Vector(2), BUG !
    88   // <group>
    89   friend Matrix operator * (const Matrix& a, int b);
    90   friend Matrix operator * (int b, const Matrix& a);
    91   friend Matrix operator + (const Matrix& a, int b);
    92   friend Matrix operator + (int b, const Matrix& a);
    93   friend Matrix operator - (const Matrix& a, int b);
    94   friend Matrix operator - (int b, const Matrix& a);
    95   friend Matrix operator / (const Matrix& 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);
    9696  // </group>
    9797
    9898  // Operations matricielles "en place", avec scalaire
    9999  // <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);
    104104  // </group>
    105105
    106106  // Operations matricielles
    107107  // <group>
    108   friend Matrix operator * (const Matrix& a, const Matrix& b);
    109   friend Matrix operator + (const Matrix& a, const Matrix& b);
    110   friend Matrix operator - (const Matrix& a, const Matrix& b);
    111 
    112   Matrix& operator *= (const Matrix& a);
    113   Matrix& operator += (const Matrix& b);
    114   Matrix& operator -= (const Matrix& 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);
    115115  // </group>
    116116
    117117  // Matrice transposee
    118   Matrix Transpose() const;
     118  OMatrix Transpose() const;
    119119  // Matrice inverse
    120120  // <thrown> singMatxErr </thrown>
    121   Matrix Inverse() const;
     121  OMatrix Inverse() const;
    122122
    123123  // Nombre de lignes
     
    134134  // Acces aux rangees et colonnes
    135135  // <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 un Matrix* 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....             */
    142142  /* mais en eux-meme, ils ne modifient pas la matrice. Ils permettent   */
    143143  /* de le faire...                                                      */
     
    145145  // Pivot de Gauss : diagonalise la matrice A, en effectuant les memes
    146146  // operations sur la matrice B
    147   static double GausPiv(Matrix& A, Matrix& B);
     147  static double GausPiv(OMatrix& A, OMatrix& B);
    148148
    149149  // Residus et fonction fittees.
    150   Matrix FitResidus(GeneralFit& gfit
     150  OMatrix FitResidus(GeneralFit& gfit
    151151            ,double xorg=0.,double yorg=0.,double dx=1.,double dy=1.);
    152   Matrix FitFunction(GeneralFit& gfit
     152  OMatrix FitFunction(GeneralFit& gfit
    153153            ,double xorg=0.,double yorg=0.,double dx=1.,double dy=1.);
    154154
     
    163163
    164164
    165 inline r_8& Matrix::operator()(int r, int c)
     165inline r_8& OMatrix::operator()(int r, int c)
    166166{
    167167#ifdef RGCHECK
     
    172172
    173173
    174 inline r_8 const& Matrix::operator()(int r, int c) const
     174inline r_8 const& OMatrix::operator()(int r, int c) const
    175175{
    176176#ifdef RGCHECK
     
    186186// Permet d'acceder a une ligne ou colonne d'une matrice, en place, comme
    187187// avec un vecteur.
    188 class MatrixRC EXC_AWARE {
    189 friend class Vector;
    190 friend class Matrix;
     188class OMatrixRC EXC_AWARE {
     189friend class OVector;
     190friend class OMatrix;
    191191public:
    192   MatrixRC();
    193 
    194   virtual ~MatrixRC() {}
     192  OMatrixRC();
     193
     194  virtual ~OMatrixRC() {}
    195195
    196196  int Next();
     
    200200  int SetDiag();
    201201
    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);
    204204
    205205  int NElts() const;
     
    207207  r_8  operator()(int i) const;
    208208
    209   MatrixRC& operator = (const MatrixRC& rc);
    210   //operator Vector() const;
    211   Vector GetVect() const;
    212 
    213   MatrixRC& operator += (const MatrixRC& rc);
    214   MatrixRC& operator -= (const MatrixRC& 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, const MatrixRC& b);
    222 
    223   MatrixRC& LinComb(double a, double b, const MatrixRC& rc, int first=0);
    224   MatrixRC& LinComb(double b, const MatrixRC& 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);
    225225
    226226  int IMaxAbs(int first=0);
    227227
    228   static void Swap(MatrixRC& rc1, MatrixRC& rc2);
    229   // comme c'est symetrique, soit c'est static MatrixRC, soit static Matrix,
    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...
    231231
    232232protected:
    233   MatrixRC(Matrix& m, RCKind kind, int index=0);
    234   Matrix* matrix;
     233  OMatrixRC(OMatrix& m, RCKind kind, int index=0);
     234  OMatrix* matrix;
    235235  r_8*    data;
    236236  int     index;
     
    240240
    241241
    242 inline int MatrixRC::Step(const Matrix& m, RCKind rckind)
     242inline int OMatrixRC::Step(const OMatrix& m, RCKind rckind)
    243243{
    244244  switch (rckind)
     
    255255
    256256
    257 inline double* MatrixRC::Org(const Matrix& m, RCKind rckind, int index)
     257inline double* OMatrixRC::Org(const OMatrix& m, RCKind rckind, int index)
    258258{
    259259  switch (rckind)
     
    270270
    271271
    272 inline int MatrixRC::NElts() const
     272inline int OMatrixRC::NElts() const
    273273{
    274274  if (!matrix) return -1;             // Failure ?
     
    287287
    288288
    289 inline  double& MatrixRC::operator()(int i)
     289inline  double& OMatrixRC::operator()(int i)
    290290{
    291291  return data[i*step];
     
    293293
    294294
    295 inline  double MatrixRC::operator()(int i) const
     295inline  double OMatrixRC::operator()(int i) const
    296296{
    297297  return data[i*step];
Note: See TracChangeset for help on using the changeset viewer.