| 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #ifndef TRIANGMTX_H_SEEN
 | 
|---|
| 4 | #define TRIANGMTX_H_SEEN
 | 
|---|
| 5 | 
 | 
|---|
| 6 | #include "ndatablock.h"
 | 
|---|
| 7 | #include "pexceptions.h"
 | 
|---|
| 8 | 
 | 
|---|
| 9 | // doit etre mis en dehors du namespace
 | 
|---|
| 10 | /*!
 | 
|---|
| 11 |   \class SOPHYA::TriangularMatrix
 | 
|---|
| 12 |   \ingroup TArray
 | 
|---|
| 13 |   Class for inferior triangular matrix (base class for the class Alm)
 | 
|---|
| 14 | */
 | 
|---|
| 15 | 
 | 
|---|
| 16 | namespace SOPHYA {
 | 
|---|
| 17 | 
 | 
|---|
| 18 | //! Class for inferior triangular matrix (base class for the class Alm)
 | 
|---|
| 19 | template <class T>
 | 
|---|
| 20 | class TriangularMatrix {
 | 
|---|
| 21 | public :
 | 
|---|
| 22 | 
 | 
|---|
| 23 | //! Default constructor
 | 
|---|
| 24 | TriangularMatrix()   {};
 | 
|---|
| 25 | //! instanciate a triangular matrix from the number of rows
 | 
|---|
| 26 | TriangularMatrix(int rowSize)  : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
 | 
|---|
| 27 | //! Copy constructor (possibility of sharing datas)
 | 
|---|
| 28 | TriangularMatrix(const TriangularMatrix<T>& a,  bool share=false)  : elem_(a.elem_, share),  long_diag_(a.long_diag_) {;}
 | 
|---|
| 29 | 
 | 
|---|
| 30 | //! resize the matrix with a new number of rows
 | 
|---|
| 31 | inline void ReSizeRow(int rowSize) 
 | 
|---|
| 32 |   {
 | 
|---|
| 33 |     long_diag_=(uint_4)rowSize;
 | 
|---|
| 34 |     elem_.ReSize(long_diag_*(long_diag_+1)/2);
 | 
|---|
| 35 |   }
 | 
|---|
| 36 |  inline void SetTemp(bool temp=false) const {elem_.SetTemp(temp);}
 | 
|---|
| 37 | 
 | 
|---|
| 38 | //! Equal operator
 | 
|---|
| 39 | inline TriangularMatrix<T>& operator = (const TriangularMatrix<T>& a)
 | 
|---|
| 40 | {
 | 
|---|
| 41 |   elem_=a.elem_;
 | 
|---|
| 42 |   long_diag_ = a.long_diag_;
 | 
|---|
| 43 |   return *this;
 | 
|---|
| 44 | }
 | 
|---|
| 45 | 
 | 
|---|
| 46 | //! () operator : access to elements row \b l and column \b m
 | 
|---|
| 47 | inline T& operator()(int l, int m) 
 | 
|---|
| 48 |   {
 | 
|---|
| 49 |       return  elem_(adr_ij(l,m));
 | 
|---|
| 50 |   }
 | 
|---|
| 51 | //! () operator : access to elements row \b l and column \b m
 | 
|---|
| 52 | inline T const& operator()(int l, int m) const 
 | 
|---|
| 53 |   {
 | 
|---|
| 54 |       return *(elem_.Begin()+ adr_ij(l,m));
 | 
|---|
| 55 |   }
 | 
|---|
| 56 | 
 | 
|---|
| 57 | //! Return number of rows
 | 
|---|
| 58 | inline  int_4  rowNumber() const {return (int_4)long_diag_;}
 | 
|---|
| 59 | 
 | 
|---|
| 60 | private: 
 | 
|---|
| 61 | //! compute the address of an element in the single array representing the matrix
 | 
|---|
| 62 | inline uint_4 adr_ij(int i,int j) const 
 | 
|---|
| 63 | {
 | 
|---|
| 64 |   //  int adr= i*(i+1)/2+j;
 | 
|---|
| 65 |   //  if ( adr >= elem_.Size() || adr <0 )
 | 
|---|
| 66 |   //{
 | 
|---|
| 67 |   // cout << " attention depassement dans triangularMatrix " << endl;
 | 
|---|
| 68 |   // cout << " l= " << i << " m= " << j << " tableau reserve longueur " << elem_.Size() << endl; 
 | 
|---|
| 69 |   //}
 | 
|---|
| 70 |   return(i*(i+1)/2+j);
 | 
|---|
| 71 | }
 | 
|---|
| 72 | 
 | 
|---|
| 73 | uint_4 long_diag_;    //!< size of the square matrix
 | 
|---|
| 74 | NDataBlock<T> elem_;  //!< Data block
 | 
|---|
| 75 | 
 | 
|---|
| 76 |   };
 | 
|---|
| 77 | 
 | 
|---|
| 78 | }   // namespace SOPHYA
 | 
|---|
| 79 | 
 | 
|---|
| 80 | #endif
 | 
|---|