source: Sophya/trunk/SophyaLib/TArray/triangmtx.h@ 920

Last change on this file since 920 was 920, checked in by ansari, 25 years ago

define module HiStats in Doc cmv 13/4/00

File size: 2.1 KB
Line 
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
9namespace 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*/
17template <class T>
18class TriangularMatrix {
19public :
20
21//! Default constructor
22TriangularMatrix() {};
23//! instanciate a triangular matrix from the number of rows
24TriangularMatrix(int rowSize) : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
25//! Copy constructor (possibility of sharing datas)
26TriangularMatrix(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
29inline 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
37inline 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
45inline 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
50inline T const& operator()(int l, int m) const
51 {
52 return *(elem_.Begin()+ adr_ij(l,m));
53 }
54
55//! Return number of rows
56inline int_4 rowNumber() const {return (int_4)long_diag_;}
57
58private:
59//! compute the address of an element in the single array representing the matrix
60inline 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
71uint_4 long_diag_; //!< size of the square matrix
72NDataBlock<T> elem_; //!< Data block
73
74 };
75
76} // namespace SOPHYA
77
78#endif
Note: See TracBrowser for help on using the repository browser.