CLHEP  2.4.7.2
C++ Class Library for High Energy Physics
SymMatrix.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 is the definitions of the inline member functions of the
7 // HepSymMatrix class
8 //
9 #include <stdexcept>
10 namespace CLHEP {
11 
12 inline HepSymMatrix::HepSymMatrix()
13  : m(0), nrow(0), size_(0)
14 {}
15 
16 inline int HepSymMatrix::num_row() const { return nrow;}
17 inline int HepSymMatrix::num_col() const { return nrow;}
18 inline int HepSymMatrix::num_size() const { return size_;}
19 
20 inline double & HepSymMatrix::fast(int row,int col)
21 {
22 #ifdef MATRIX_BOUND_CHECK
23  if(row<1||row>num_row() || col<1||col>num_col())
24  error("Range error in HepSymMatrix::fast()");
25 #endif
26  return *(m.begin()+(row*(row-1))/2+(col-1));
27 }
28 inline const double & HepSymMatrix::fast(int row,int col) const
29 {
30 #ifdef MATRIX_BOUND_CHECK
31  if(row<1||row>num_row() || col<1||col>num_col())
32  error("Range error in HepSymMatrix::fast()");
33 #endif
34  return *(m.begin()+(row*(row-1))/2+(col-1));
35 }
36 
37 inline double & HepSymMatrix::operator()(int row, int col)
38  {return (row>=col? fast(row,col) : fast(col,row));}
39 inline const double & HepSymMatrix::operator()(int row, int col) const
40  {return (row>=col? fast(row,col) : fast(col,row));}
41 
42 inline void HepSymMatrix::assign(const HepSymMatrix &hm2)
43  {(*this)=hm2;}
44 
45 inline HepSymMatrix HepSymMatrix::T() const {return HepSymMatrix(*this);}
46 
47 inline HepSymMatrix::HepSymMatrix_row HepSymMatrix::operator[] (int r)
48 #ifdef HEP_GNU_OPTIMIZED_RETURN
49  return b(*this,r);
50 {
51 #else
52 {
53  HepSymMatrix_row b(*this,r);
54 #endif
55  return b;
56 }
57 
58 inline HepSymMatrix::HepSymMatrix_row_const HepSymMatrix::operator[] (int r) const
59 #ifdef HEP_GNU_OPTIMIZED_RETURN
60  return b(*this,r);
61 {
62 #else
63 {
64  const HepSymMatrix_row_const b(*this,r);
65 #endif
66  return b;
67 }
68 
69 inline double &HepSymMatrix::HepSymMatrix_row::operator[](int c)
70 {
71 #ifdef MATRIX_BOUND_CHECK
72  if(_r<0||_r>=_a.nrow || c<0||c>=_a.nrow)
73  error("Range error in HepSymMatrix::operator[][]");
74 #endif
75  if (_r >= c ) {
76  return *(_a.m.begin() + (_r+1)*_r/2 + c);
77  } else {
78  return *(_a.m.begin() + (c+1)*c/2 + _r);
79  }
80 }
81 
82 inline const double &
83 HepSymMatrix::HepSymMatrix_row_const::operator[](int c) const
84 {
85 #ifdef MATRIX_BOUND_CHECK
86  if(_r<0||_r>=_a.nrow || c<0||c>=_a.nrow)
87  error("Range error in HepSymMatrix::operator[][]");
88 #endif
89  if (_r >= c ) {
90  return *(_a.m.begin() + (_r+1)*_r/2 + c);
91  } else {
92  return *(_a.m.begin() + (c+1)*c/2 + _r);
93  }
94 }
95 
96 inline HepSymMatrix::HepSymMatrix_row::HepSymMatrix_row(HepSymMatrix &a,
97  int r)
98  : _a(a), _r(r)
99 {}
100 
101 inline HepSymMatrix::HepSymMatrix_row_const::HepSymMatrix_row_const
102 (const HepSymMatrix&a,int r)
103  : _a(a), _r(r)
104 {}
105 
106 inline HepSymMatrix HepSymMatrix::inverse(int &ifail) const
107 #ifdef HEP_GNU_OPTIMIZED_RETURN
108  return mTmp(*this);
109 {
110 #else
111 {
112  HepSymMatrix mTmp(*this);
113 #endif
114  mTmp.invert(ifail);
115  return mTmp;
116 }
117 
118 inline HepSymMatrix HepSymMatrix::inverse() const {
119  int ierr;
120  HepSymMatrix mt=inverse(ierr);
121  if (ierr) throw std::runtime_error("Error in HepSymMatrix inversion");
122  return mt;
123 }
124 
125 inline void HepSymMatrix::invert() {
126  int ierr;
127  invert(ierr);
128  if (ierr) throw std::runtime_error("Error in HepSymMatrix inversion");
129 }
130 
131 } // namespace CLHEP
132 
133