diagonalMatrix.cc
Go to the documentation of this file.
1 
10 #include "diagonalMatrix.h"
12 
13 using namespace oBLAS;
14 
15 
16 /*****************************************************
17  *
18  * constructor of diagonalMatrix
19  *
20  *****************************************************/
22  ublas::banded_matrix<double>(i, i, 0, 0)
23 {
24  Init();
25  //std::cout << " diag1 " << this << " " << fInverse << std::endl;
26 }
27 
28 
29 /*****************************************************
30  *
31  * copy constructor from ublas::matrix
32  *
33  *****************************************************/
34 diagonalMatrix::diagonalMatrix(const ublas::matrix<double>& r) :
35  ublas::banded_matrix<double>(r.size1(), r.size1(), 0, 0)
36 {
37  const unsigned int size = this->size1();
38  for (unsigned int i = 0; i < size; ++i)
39  (*this)(i, i) = r(i, i);
40  Init();
41  //std::cout << " diag2 " << this << " " << fInverse << std::endl;
42 }
43 
44 
45 /*****************************************************
46  *
47  * initialize
48  *
49  *****************************************************/
50 void
52 {
53  fInverse = NULL;
54 }
55 
56 
57 /*****************************************************
58  *
59  * destructor of diagonalMatrix
60  *
61  *****************************************************/
63 {
64  //std::cout << " ~diag " << this << " " << fInverse << std::endl;
65  delete fInverse;
66 }
67 
68 
69 /*****************************************************
70  *
71  * assignment to boost matrix
72  *
73  *****************************************************/
74 void
75 diagonalMatrix::operator=(const ublas::matrix<double>& r)
76 {
77  const unsigned int size = this->size1();
78  for (unsigned int i = 0; i < size; ++i)
79  (*this)(i, i) = r(i, i);
80 }
81 
82 
83 /*****************************************************
84  *
85  * calculate and return inverse of matrix
86  *
87  *****************************************************/
88 const diagonalMatrix*
90 {
91  //std::cout << "dinv " << this << " " << fInverse << std::endl;
92  const unsigned int size = this->size1();
93  if (fInverse == NULL)
94  fInverse = new diagonalMatrix(size);
95 
96  const double epsilon = std::numeric_limits<double>::epsilon();
97 
98  for (unsigned int i = 0; i < size; ++i) {
99  const double tmp = (*this)(i, i);
100  if (fabs(tmp) > epsilon)
101  (*fInverse)(i, i) = 1/tmp;
102  else
103  throw SingularMatrixException();
104  }
105  return fInverse;
106 }
diagonalMatrix * fInverse
void operator=(const ublas::matrix< double > &r)
const diagonalMatrix * GetInverse()

, generated on Tue Sep 26 2023.