Changeset 2957 in Sophya for trunk/SophyaLib/TArray
- Timestamp:
- Jun 1, 2006, 1:32:00 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/triangmtx.h
r2291 r2957 11 11 \class SOPHYA::TriangularMatrix 12 12 \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 14 24 */ 15 25 … … 24 34 TriangularMatrix() {;}; 25 35 //! instanciate a triangular matrix from the number of rows 26 TriangularMatrix( int rowSize) : long_diag_((uint_4)rowSize)36 TriangularMatrix(sa_size_t rowSize) : long_diag_(rowSize) 27 37 { 28 elem_.ReSize(( uint_4) (rowSize*(rowSize+1)/2) );38 elem_.ReSize((rowSize*(rowSize+1)/2) ); 29 39 } 30 40 //! Copy constructor (possibility of sharing datas) … … 32 42 33 43 //! resize the matrix with a new number of rows 34 inline void ReSizeRow( int rowSize)44 inline void ReSizeRow(sa_size_t rowSize) 35 45 { 36 46 long_diag_=(uint_4)rowSize; … … 47 57 48 58 //! () operator : access to elements row \b l and column \b m 49 inline T& operator()( int l, int m)59 inline T& operator()(sa_size_t l, sa_size_t m) 50 60 { 51 61 return elem_(indexOfElement(l,m)); 52 62 } 53 63 54 inline T& operator()( int index)64 inline T& operator()(sa_size_t index) 55 65 { 56 66 return elem_(index); … … 59 69 60 70 //! () operator : access to elements row \b l and column \b m 61 inline T const& operator()( int l, int m) const71 inline T const& operator()(sa_size_t l, sa_size_t m) const 62 72 { 63 73 return *(elem_.Begin()+ indexOfElement(l,m)); 64 74 } 65 75 66 inline T const& operator()( int index) const76 inline T const& operator()(sa_size_t index) const 67 77 { 68 78 return *(elem_.Begin()+ index); … … 91 101 throw(SzMismatchError("TriangularMatrix<T>::CopyElt(const TriangularMatrix<T>&) SizeMismatch")) ; 92 102 long_diag_ = a.long_diag_; 93 int k;103 sa_size_t k; 94 104 for (k=0; k< Size(); k++) elem_(k) = a.elem_(k); 95 105 return(*this); … … 104 114 105 115 //! Return number of rows 106 inline int_4rowNumber() const {return (int_4)long_diag_;}116 inline sa_size_t rowNumber() const {return (int_4)long_diag_;} 107 117 108 118 //! Return size of the total array 109 inline int_4Size() const {return elem_.Size();}119 inline sa_size_t Size() const {return elem_.Size();} 110 120 111 inline bool CheckRelativeIndices( int_4 l, int_4m) const121 inline bool CheckRelativeIndices(sa_size_t l, sa_size_t m) const 112 122 { 113 123 if ( l < m ) … … 117 127 return true; 118 128 } 119 inline bool CheckAbsoluteIndice( int_4 l, int_4m) const129 inline bool CheckAbsoluteIndice(sa_size_t l, sa_size_t m) const 120 130 { 121 131 if ( indexOfElement(l,m) >= elem_.Size() ) … … 124 134 } 125 135 } 126 inline bool CheckAbsoluteIndice( int_4ind) const136 inline bool CheckAbsoluteIndice(sa_size_t ind) const 127 137 { 128 138 if ( ind >= elem_.Size() ) … … 132 142 } 133 143 134 void Print(int nbLignes=0) 144 //! ASCII dump of the matrix (set nbLignes=-1) for dumping the complete matrix 145 void Print(ostream& os, sa_size_t nbLignes=0) const 135 146 { 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; 147 160 } 148 161 149 //Return pointer to first element address 150 //inline T* Data() {return elem_.Begin();} 162 inline 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)) 166 inline 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)) 169 inline T* columnData(sa_size_t j) {return elem_.Begin()+(long_diag_*j-j*(j-1)/2) ;} 151 170 152 171 //! compute the address of an element in the single array representing the matrix 153 inline uint_4 indexOfElement(int i,int j) const172 inline sa_size_t indexOfElement(sa_size_t i,sa_size_t j) const 154 173 { 155 174 // return(i*(i+1)/2+j); … … 160 179 private: 161 180 162 uint_4long_diag_; //!< size of the square matrix181 sa_size_t long_diag_; //!< size of the square matrix 163 182 NDataBlock<T> elem_; //!< Data block 164 183 165 184 }; 185 186 template <class T> 187 inline ostream& operator << (ostream& os, const TriangularMatrix<T>& a) 188 { a.Print(os, 0); return(os); } 166 189 167 190 } // namespace SOPHYA
Note:
See TracChangeset
for help on using the changeset viewer.