[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 |
|
---|
[926] | 9 | // doit etre mis en dehors du namespace
|
---|
[920] | 10 | /*!
|
---|
| 11 | \class SOPHYA::TriangularMatrix
|
---|
| 12 | \ingroup TArray
|
---|
[926] | 13 | Class for inferior triangular matrix (base class for the class Alm)
|
---|
[920] | 14 | */
|
---|
[926] | 15 |
|
---|
| 16 | namespace SOPHYA {
|
---|
[1683] | 17 |
|
---|
[926] | 18 | //! Class for inferior triangular matrix (base class for the class Alm)
|
---|
[762] | 19 | template <class T>
|
---|
[914] | 20 | class TriangularMatrix {
|
---|
| 21 | public :
|
---|
[762] | 22 |
|
---|
[914] | 23 | //! Default constructor
|
---|
[762] | 24 | TriangularMatrix() {};
|
---|
[914] | 25 | //! instanciate a triangular matrix from the number of rows
|
---|
[762] | 26 | TriangularMatrix(int rowSize) : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
|
---|
[914] | 27 | //! Copy constructor (possibility of sharing datas)
|
---|
[762] | 28 | TriangularMatrix(const TriangularMatrix<T>& a, bool share=false) : elem_(a.elem_, share), long_diag_(a.long_diag_) {;}
|
---|
[914] | 29 |
|
---|
| 30 | //! resize the matrix with a new number of rows
|
---|
[762] | 31 | inline void ReSizeRow(int rowSize)
|
---|
| 32 | {
|
---|
| 33 | long_diag_=(uint_4)rowSize;
|
---|
| 34 | elem_.ReSize(long_diag_*(long_diag_+1)/2);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[1683] | 37 | TriangularMatrix<T>& SetT(T a)
|
---|
| 38 | {
|
---|
| 39 | if (long_diag_ < 1)
|
---|
| 40 | throw RangeCheckError("TriangularMatrix<T>::SetT(T ) - TriangularMatrix not dimensionned ! ");
|
---|
| 41 | elem_ = a;
|
---|
| 42 | return (*this);
|
---|
| 43 | }
|
---|
[914] | 44 |
|
---|
| 45 | //! () operator : access to elements row \b l and column \b m
|
---|
[762] | 46 | inline T& operator()(int l, int m)
|
---|
| 47 | {
|
---|
[1683] | 48 | return elem_(indexOfElement(l,m));
|
---|
[762] | 49 | }
|
---|
[1683] | 50 |
|
---|
| 51 | inline T& operator()(int index)
|
---|
| 52 | {
|
---|
| 53 | return elem_(index);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
[914] | 57 | //! () operator : access to elements row \b l and column \b m
|
---|
[762] | 58 | inline T const& operator()(int l, int m) const
|
---|
| 59 | {
|
---|
[1683] | 60 | return *(elem_.Begin()+ indexOfElement(l,m));
|
---|
[762] | 61 | }
|
---|
[914] | 62 |
|
---|
[1683] | 63 | inline T const& operator()(int index) const
|
---|
| 64 | {
|
---|
| 65 | return *(elem_.Begin()+ index);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 |
|
---|
[914] | 69 | //! Return number of rows
|
---|
| 70 | inline int_4 rowNumber() const {return (int_4)long_diag_;}
|
---|
| 71 |
|
---|
[1683] | 72 | void Print(int nbLignes=0)
|
---|
| 73 | {
|
---|
| 74 | if (nbLignes == 0 ) nbLignes = long_diag_;
|
---|
| 75 | cout << " ***** matrice triangulaire : ********* " << endl;
|
---|
| 76 | for (int k=0; k < nbLignes; k++)
|
---|
| 77 | {
|
---|
| 78 | for (int kc = 0; kc <= k ; kc++)
|
---|
| 79 | {
|
---|
| 80 | cout << " " << elem_(indexOfElement(k,kc));
|
---|
| 81 | }
|
---|
| 82 | cout << endl;
|
---|
| 83 | }
|
---|
| 84 | cout << "---------------- fin matrice ------------" << endl;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | //Return pointer to first element address
|
---|
| 88 | //inline T* Data() {return elem_.Begin();}
|
---|
| 89 |
|
---|
[914] | 90 | //! compute the address of an element in the single array representing the matrix
|
---|
[1683] | 91 | inline uint_4 indexOfElement(int i,int j) const
|
---|
[762] | 92 | {
|
---|
[1683] | 93 | // return(i*(i+1)/2+j);
|
---|
| 94 | // the (inferior triangular )matrix is stored column by column
|
---|
| 95 | return(i+ long_diag_*j-j*(j+1)/2);
|
---|
[762] | 96 | }
|
---|
| 97 |
|
---|
[1683] | 98 | private:
|
---|
| 99 |
|
---|
[914] | 100 | uint_4 long_diag_; //!< size of the square matrix
|
---|
| 101 | NDataBlock<T> elem_; //!< Data block
|
---|
[762] | 102 |
|
---|
| 103 | };
|
---|
[1683] | 104 |
|
---|
[762] | 105 | } // namespace SOPHYA
|
---|
| 106 |
|
---|
| 107 | #endif
|
---|