[762] | 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 | namespace SOPHYA {
|
---|
| 10 |
|
---|
[914] | 11 | //! Class for inferior triangular matrix (base class for the class Alm)
|
---|
[762] | 12 | template <class T>
|
---|
[914] | 13 | class TriangularMatrix {
|
---|
| 14 | public :
|
---|
[762] | 15 |
|
---|
[914] | 16 | //! Default constructor
|
---|
[762] | 17 | TriangularMatrix() {};
|
---|
[914] | 18 | //! instanciate a triangular matrix from the number of rows
|
---|
[762] | 19 | TriangularMatrix(int rowSize) : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
|
---|
[914] | 20 | //! Copy constructor (possibility of sharing datas)
|
---|
[762] | 21 | TriangularMatrix(const TriangularMatrix<T>& a, bool share=false) : elem_(a.elem_, share), long_diag_(a.long_diag_) {;}
|
---|
[914] | 22 |
|
---|
| 23 | //! resize the matrix with a new number of rows
|
---|
[762] | 24 | inline void ReSizeRow(int rowSize)
|
---|
| 25 | {
|
---|
| 26 | long_diag_=(uint_4)rowSize;
|
---|
| 27 | elem_.ReSize(long_diag_*(long_diag_+1)/2);
|
---|
| 28 | }
|
---|
| 29 | inline void SetTemp(bool temp=false) const {elem_.SetTemp(temp);}
|
---|
| 30 |
|
---|
[914] | 31 | //! Equal operator
|
---|
[762] | 32 | inline TriangularMatrix<T>& operator = (const TriangularMatrix<T>& a)
|
---|
| 33 | {
|
---|
| 34 | elem_=a.elem_;
|
---|
| 35 | long_diag_ = a.long_diag_;
|
---|
| 36 | return *this;
|
---|
| 37 | }
|
---|
[914] | 38 |
|
---|
| 39 | //! () operator : access to elements row \b l and column \b m
|
---|
[762] | 40 | inline T& operator()(int l, int m)
|
---|
| 41 | {
|
---|
| 42 | return elem_(adr_ij(l,m));
|
---|
| 43 | }
|
---|
[914] | 44 | //! () operator : access to elements row \b l and column \b m
|
---|
[762] | 45 | inline T const& operator()(int l, int m) const
|
---|
| 46 | {
|
---|
| 47 | return *(elem_.Begin()+ adr_ij(l,m));
|
---|
| 48 | }
|
---|
[914] | 49 |
|
---|
| 50 | //! Return number of rows
|
---|
| 51 | inline int_4 rowNumber() const {return (int_4)long_diag_;}
|
---|
| 52 |
|
---|
| 53 | private:
|
---|
| 54 | //! compute the address of an element in the single array representing the matrix
|
---|
[762] | 55 | inline uint_4 adr_ij(int i,int j) const
|
---|
| 56 | {
|
---|
| 57 | int adr= i*(i+1)/2+j;
|
---|
[862] | 58 | // if ( adr >= elem_.Size() || adr <0 )
|
---|
| 59 | //{
|
---|
| 60 | // cout << " attention depassement dans triangularMatrix " << endl;
|
---|
| 61 | // cout << " l= " << i << " m= " << j << " tableau reserve longueur " << elem_.Size() << endl;
|
---|
| 62 | //}
|
---|
[762] | 63 | return(i*(i+1)/2+j);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[914] | 66 | uint_4 long_diag_; //!< size of the square matrix
|
---|
| 67 | NDataBlock<T> elem_; //!< Data block
|
---|
[762] | 68 |
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | } // namespace SOPHYA
|
---|
| 72 |
|
---|
| 73 | #endif
|
---|