Changeset 2957 in Sophya


Ignore:
Timestamp:
Jun 1, 2006, 1:32:00 PM (19 years ago)
Author:
ansari
Message:

classe TriangularMatrix<T> complete (methode columnData() + passage en sa_size_t au lieu de int - Reza 1/06/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/TArray/triangmtx.h

    r2291 r2957  
    1111  \class SOPHYA::TriangularMatrix
    1212  \ingroup TArray
    13   Class for inferior triangular matrix (base class for the class Alm)
     13  \brief Class for inferior triangular matrix (base class for the class Alm)
     14  The inferior triangular matrix is represented in memory as column packed,
     15  as illustrated below for a 5x5 triangular matrix.
     16  \verbatim
     17  5x5 Inf.Triang.Matrix, Size= 15 elements (0 ... 14)
     18  | 0                  |
     19  | 1   5              |
     20  | 2   6   9          |
     21  | 3   7   10  12     |
     22  | 4   8   11  13  14 |
     23  \endverbatim
    1424*/
    1525
     
    2434TriangularMatrix()   {;};
    2535//! instanciate a triangular matrix from the number of rows
    26 TriangularMatrix(int rowSize)  : long_diag_((uint_4)rowSize)
     36TriangularMatrix(sa_size_t rowSize)  : long_diag_(rowSize)
    2737  {
    28     elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) );
     38    elem_.ReSize((rowSize*(rowSize+1)/2) );
    2939  }
    3040//! Copy constructor (possibility of sharing datas)
     
    3242
    3343//! resize the matrix with a new number of rows
    34 inline void ReSizeRow(int rowSize)
     44inline void ReSizeRow(sa_size_t rowSize)
    3545  {
    3646    long_diag_=(uint_4)rowSize;
     
    4757
    4858//! () operator : access to elements row \b l and column \b m
    49 inline T& operator()(int l, int m)
     59inline T& operator()(sa_size_t l, sa_size_t m)
    5060  {
    5161      return  elem_(indexOfElement(l,m));
    5262  }
    5363
    54 inline T& operator()(int index)
     64inline T& operator()(sa_size_t index)
    5565  {
    5666      return  elem_(index);
     
    5969
    6070//! () operator : access to elements row \b l and column \b m
    61 inline T const& operator()(int l, int m) const
     71inline T const& operator()(sa_size_t l, sa_size_t m) const
    6272  {
    6373      return *(elem_.Begin()+ indexOfElement(l,m));
    6474  }
    6575
    66 inline T const& operator()(int index) const
     76inline T const& operator()(sa_size_t index) const
    6777  {
    6878      return *(elem_.Begin()+ index);
     
    91101      throw(SzMismatchError("TriangularMatrix<T>::CopyElt(const TriangularMatrix<T>&) SizeMismatch")) ;
    92102    long_diag_ = a.long_diag_;
    93     int k;
     103    sa_size_t k;
    94104    for (k=0; k< Size(); k++) elem_(k) = a.elem_(k);
    95105    return(*this);
     
    104114
    105115//! Return number of rows
    106 inline  int_4 rowNumber() const {return (int_4)long_diag_;}
     116inline  sa_size_t rowNumber() const {return (int_4)long_diag_;}
    107117
    108118//! Return size of the total array
    109   inline int_4 Size() const {return elem_.Size();}
     119  inline sa_size_t Size() const {return elem_.Size();}
    110120
    111   inline bool CheckRelativeIndices(int_4 l, int_4 m) const
     121  inline bool CheckRelativeIndices(sa_size_t l, sa_size_t m) const
    112122   {
    113123     if ( l < m )
     
    117127     return true;
    118128   }
    119   inline bool CheckAbsoluteIndice(int_4 l, int_4 m) const
     129  inline bool CheckAbsoluteIndice(sa_size_t l, sa_size_t m) const
    120130   {
    121131     if ( indexOfElement(l,m) >= elem_.Size() )
     
    124134       }
    125135   }
    126   inline bool CheckAbsoluteIndice(int_4 ind) const
     136  inline bool CheckAbsoluteIndice(sa_size_t ind) const
    127137   {
    128138     if ( ind >= elem_.Size() )
     
    132142   }
    133143
    134 void Print(int nbLignes=0)
     144  //! ASCII dump of the matrix (set nbLignes=-1) for dumping the complete matrix
     145void Print(ostream& os, sa_size_t nbLignes=0) const
    135146  {
    136     if (nbLignes == 0 ) nbLignes = long_diag_;
    137     cout << " ***** matrice triangulaire : ********* " << endl;
    138     for (int k=0; k < nbLignes; k++)
    139       {
    140         for (int kc = 0; kc <= k ; kc++)
    141           {
    142             cout << " " << elem_(indexOfElement(k,kc));
    143           }
    144         cout << endl;
    145       }
    146     cout << "---------------- fin matrice ------------" << endl;
     147    os << "TriangularMatrix< " << typeid(T).name()
     148       << " > NRow=" << long_diag_ << " NbElem<>0 : " << Size() << endl;
     149    if (nbLignes == 0) return;
     150    if (nbLignes < 0 ) nbLignes = long_diag_;
     151    if (nbLignes > long_diag_ ) nbLignes = long_diag_;
     152    for (sa_size_t k=0; k < nbLignes; k++)  {
     153      os << "L[" << k << "]: " ;
     154      for (sa_size_t kc = 0; kc <= k ; kc++)
     155        os << " " << elem_(indexOfElement(k,kc));
     156      os << endl;
     157    }
     158    if (nbLignes < long_diag_)  os << " ... ... ... " << endl;
     159    return;
    147160  }
    148161
    149   //Return pointer to first element address
    150   //inline T* Data()  {return elem_.Begin();}
     162inline void Print(sa_size_t nbLignes=0) const  { Print(cout, nbLignes); }
     163
     164
     165//! Return the pointer to the first non zero element in column \b j = &(tmmtx(j,j))
     166inline const T* columnData(sa_size_t j)  const {return elem_.Begin()+(long_diag_*j-j*(j-1)/2) ;}
     167
     168//! Return the pointer to the first non zero element in column \b j = &(tmmtx(j,j))
     169inline T* columnData(sa_size_t j) {return elem_.Begin()+(long_diag_*j-j*(j-1)/2) ;}
    151170
    152171//! compute the address of an element in the single array representing the matrix
    153 inline uint_4 indexOfElement(int i,int j) const
     172inline sa_size_t indexOfElement(sa_size_t i,sa_size_t j) const
    154173{
    155174  //  return(i*(i+1)/2+j);
     
    160179private:
    161180
    162 uint_4 long_diag_;    //!< size of the square matrix
     181sa_size_t long_diag_;    //!< size of the square matrix
    163182NDataBlock<T> elem_;  //!< Data block
    164183
    165184  };
     185
     186template <class T>
     187inline ostream& operator << (ostream& os, const TriangularMatrix<T>& a)
     188                            { a.Print(os, 0);    return(os);    }
    166189 
    167190}   // namespace SOPHYA
Note: See TracChangeset for help on using the changeset viewer.