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

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

documentation cmv 13/4/00

File size: 2.0 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)
12template <class T>
13class TriangularMatrix {
14public :
15
16//! Default constructor
17TriangularMatrix() {};
18//! instanciate a triangular matrix from the number of rows
19TriangularMatrix(int rowSize) : long_diag_((uint_4)rowSize) {elem_.ReSize((uint_4) (rowSize*(rowSize+1)/2) ); };
20//! Copy constructor (possibility of sharing datas)
21TriangularMatrix(const TriangularMatrix<T>& a, bool share=false) : elem_(a.elem_, share), long_diag_(a.long_diag_) {;}
22
23//! resize the matrix with a new number of rows
24inline 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
31//! Equal operator
32inline TriangularMatrix<T>& operator = (const TriangularMatrix<T>& a)
33{
34 elem_=a.elem_;
35 long_diag_ = a.long_diag_;
36 return *this;
37}
38
39//! () operator : access to elements row \b l and column \b m
40inline T& operator()(int l, int m)
41 {
42 return elem_(adr_ij(l,m));
43 }
44//! () operator : access to elements row \b l and column \b m
45inline T const& operator()(int l, int m) const
46 {
47 return *(elem_.Begin()+ adr_ij(l,m));
48 }
49
50//! Return number of rows
51inline int_4 rowNumber() const {return (int_4)long_diag_;}
52
53private:
54//! compute the address of an element in the single array representing the matrix
55inline uint_4 adr_ij(int i,int j) const
56{
57 int adr= i*(i+1)/2+j;
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 //}
63 return(i*(i+1)/2+j);
64}
65
66uint_4 long_diag_; //!< size of the square matrix
67NDataBlock<T> elem_; //!< Data block
68
69 };
70
71} // namespace SOPHYA
72
73#endif
Note: See TracBrowser for help on using the repository browser.