[762] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | /*! Class for inferior triangular matrix (base class for the class Alm) */
|
---|
| 3 |
|
---|
| 4 | #ifndef TRIANGMTX_H_SEEN
|
---|
| 5 | #define TRIANGMTX_H_SEEN
|
---|
| 6 |
|
---|
| 7 | #include "ndatablock.h"
|
---|
| 8 | #include "pexceptions.h"
|
---|
| 9 |
|
---|
| 10 | namespace SOPHYA {
|
---|
| 11 |
|
---|
| 12 | template <class T>
|
---|
| 13 | class TriangularMatrix
|
---|
| 14 | {
|
---|
| 15 |
|
---|
| 16 | public :
|
---|
| 17 |
|
---|
| 18 | TriangularMatrix() {};
|
---|
| 19 | /* instanciate a triangular matrix from the number of rows */
|
---|
| 20 | TriangularMatrix(int rowSize) : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
|
---|
| 21 | TriangularMatrix(const TriangularMatrix<T>& a, bool share=false) : elem_(a.elem_, share), long_diag_(a.long_diag_) {;}
|
---|
| 22 | /*! resize the matrix with a new number of rows */
|
---|
| 23 | inline void ReSizeRow(int rowSize)
|
---|
| 24 | {
|
---|
| 25 | long_diag_=(uint_4)rowSize;
|
---|
| 26 | elem_.ReSize(long_diag_*(long_diag_+1)/2);
|
---|
| 27 | }
|
---|
| 28 | inline void SetTemp(bool temp=false) const {elem_.SetTemp(temp);}
|
---|
| 29 |
|
---|
| 30 | inline TriangularMatrix<T>& operator = (const TriangularMatrix<T>& a)
|
---|
| 31 | {
|
---|
| 32 | elem_=a.elem_;
|
---|
| 33 | long_diag_ = a.long_diag_;
|
---|
| 34 | return *this;
|
---|
| 35 | }
|
---|
| 36 | inline T& operator()(int l, int m)
|
---|
| 37 | {
|
---|
| 38 | return elem_(adr_ij(l,m));
|
---|
| 39 | }
|
---|
| 40 | inline T const& operator()(int l, int m) const
|
---|
| 41 | {
|
---|
| 42 | return *(elem_.Begin()+ adr_ij(l,m));
|
---|
| 43 | }
|
---|
| 44 | inline int_4 rowNumber() const {return (int_4)long_diag_;}
|
---|
| 45 | private:
|
---|
| 46 | /*! compute the address of an element in the single array representing the matrix */
|
---|
| 47 | inline uint_4 adr_ij(int i,int j) const
|
---|
| 48 | {
|
---|
| 49 | int adr= i*(i+1)/2+j;
|
---|
[862] | 50 | // if ( adr >= elem_.Size() || adr <0 )
|
---|
| 51 | //{
|
---|
| 52 | // cout << " attention depassement dans triangularMatrix " << endl;
|
---|
| 53 | // cout << " l= " << i << " m= " << j << " tableau reserve longueur " << elem_.Size() << endl;
|
---|
| 54 | //}
|
---|
[762] | 55 | return(i*(i+1)/2+j);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | uint_4 long_diag_;
|
---|
| 59 | NDataBlock<T> elem_;
|
---|
| 60 |
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | } // namespace SOPHYA
|
---|
| 64 |
|
---|
| 65 | #endif
|
---|