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

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

define module HiStats in Doc cmv 13/4/00

File size: 2.1 KB
RevLine 
[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
9namespace SOPHYA {
10
[914]11//! Class for inferior triangular matrix (base class for the class Alm)
[920]12/*!
13 \class SOPHYA::TriangularMatrix
14 \ingroup TArray
15 Class for triangular matrices
16*/
[762]17template <class T>
[914]18class TriangularMatrix {
19public :
[762]20
[914]21//! Default constructor
[762]22TriangularMatrix() {};
[914]23//! instanciate a triangular matrix from the number of rows
[762]24TriangularMatrix(int rowSize) : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
[914]25//! Copy constructor (possibility of sharing datas)
[762]26TriangularMatrix(const TriangularMatrix<T>& a, bool share=false) : elem_(a.elem_, share), long_diag_(a.long_diag_) {;}
[914]27
28//! resize the matrix with a new number of rows
[762]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
[914]36//! Equal operator
[762]37inline TriangularMatrix<T>& operator = (const TriangularMatrix<T>& a)
38{
39 elem_=a.elem_;
40 long_diag_ = a.long_diag_;
41 return *this;
42}
[914]43
44//! () operator : access to elements row \b l and column \b m
[762]45inline T& operator()(int l, int m)
46 {
47 return elem_(adr_ij(l,m));
48 }
[914]49//! () operator : access to elements row \b l and column \b m
[762]50inline T const& operator()(int l, int m) const
51 {
52 return *(elem_.Begin()+ adr_ij(l,m));
53 }
[914]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
[762]60inline uint_4 adr_ij(int i,int j) const
61{
62 int adr= i*(i+1)/2+j;
[862]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 //}
[762]68 return(i*(i+1)/2+j);
69}
70
[914]71uint_4 long_diag_; //!< size of the square matrix
72NDataBlock<T> elem_; //!< Data block
[762]73
74 };
75
76} // namespace SOPHYA
77
78#endif
Note: See TracBrowser for help on using the repository browser.