CLHEP  2.4.7.2
C++ Class Library for High Energy Physics
DiagMatrix.icc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // ---------------------------------------------------------------------------
3 //
4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
5 //
6 // This software written by Nobu Katayama and Mike Smyth, Cornell University.
7 //
8 #include <stdexcept>
9 namespace CLHEP {
10 
11 inline HepDiagMatrix::HepDiagMatrix()
12  : m(0), nrow(0)
13 {}
14 
15 inline int HepDiagMatrix::num_row() const { return nrow;}
16 inline int HepDiagMatrix::num_col() const { return nrow;}
17 inline int HepDiagMatrix::num_size() const { return nrow;}
18 
19 inline double & HepDiagMatrix::fast(int row,int col)
20 {
21 #ifdef MATRIX_BOUND_CHECK
22  if (row<1 || row>nrow || col<1 || col>nrow)
23  error("Range error in HepDiagMatrix::fast()");
24 #endif
25  if (row != col)
26  error("Index error in HepDiagMatrix::fast(i,j): i != j");
27 
28  return *(m.begin()+(col-1));
29 }
30 
31 inline const double & HepDiagMatrix::fast(int row,int col) const
32 {
33 #ifdef MATRIX_BOUND_CHECK
34  if (row<1 || row>nrow || col<1 || col>nrow)
35  error("Range error in HepDiagMatrix::fast()");
36 #endif
37  if (row == col) {
38  return *(m.begin()+(col-1));
39  } else {
40 #if defined(__sun) || !defined(__GNUG__)
41 //
42 // Sun CC 4.0.1 has this bug.
43 //
44  zero = 0;
45 #endif
46  return zero;
47  }
48 }
49 
50 inline double & HepDiagMatrix::operator()(int row, int col)
51 {
52  return fast(col,row);
53 }
54 
55 inline const double & HepDiagMatrix::operator()(int row, int col) const
56 {
57  return fast(col,row);
58 }
59 
60 inline void HepDiagMatrix::assign(const HepDiagMatrix &hm2) {(*this)=hm2;}
61 
62 inline HepDiagMatrix HepDiagMatrix::T() const {return HepDiagMatrix(*this);}
63 
64 inline HepDiagMatrix::HepDiagMatrix_row HepDiagMatrix::operator[] (int r)
65 #ifdef HEP_GNU_OPTIMIZED_RETURN
66  return b(*this,r);
67 {
68 #else
69 {
70  HepDiagMatrix_row b(*this,r);
71 #endif
72  return b;
73 }
74 
75 inline HepDiagMatrix::HepDiagMatrix_row_const HepDiagMatrix::operator[] (int r) const
76 #ifdef HEP_GNU_OPTIMIZED_RETURN
77  return b(*this,r);
78 {
79 #else
80 {
81  const HepDiagMatrix_row_const b(*this,r);
82 #endif
83  return b;
84 }
85 
86 inline double &HepDiagMatrix::HepDiagMatrix_row::operator[](int c)
87 {
88  return _a.fast(_r+1, c+1);
89 }
90 
91 inline const double&
92 HepDiagMatrix::HepDiagMatrix_row_const::operator[](int c) const
93 {
94  return _a.fast(_r+1,c+1);
95 }
96 
97 inline HepDiagMatrix::HepDiagMatrix_row::HepDiagMatrix_row
98 (HepDiagMatrix& a, int r)
99  : _a(a), _r(r)
100 {}
101 
102 inline HepDiagMatrix::HepDiagMatrix_row_const::HepDiagMatrix_row_const
103 (const HepDiagMatrix& a, int r)
104  : _a(a), _r(r)
105 {}
106 
107 inline HepDiagMatrix HepDiagMatrix::inverse(int &ierr) const
108 #ifdef HEP_GNU_OPTIMIZED_RETURN
109  return mTmp(*this);
110 {
111 #else
112 {
113  HepDiagMatrix mTmp(*this);
114 #endif
115  mTmp.invert(ierr);
116  return mTmp;
117 }
118 
119 inline HepDiagMatrix HepDiagMatrix::inverse() const {
120  int ierr;
121  HepDiagMatrix mt=inverse(ierr);
122  if (ierr) throw std::runtime_error("Error in HepDiagMatrix inversion");
123  return mt;
124 }
125 
126 inline void HepDiagMatrix::invert() {
127  int ierr;
128  invert(ierr);
129  if (ierr) throw std::runtime_error("Error in HepDiagMatrix inversion");
130 }
131 
132 } // namespace CLHEP