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