CLHEP  2.4.7.2
C++ Class Library for High Energy Physics
Matrix.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 // This is the definitions of the inline member functions of the
9 // HepMatrix class
10 //
11 #include <stdexcept>
12 namespace CLHEP {
13 
14 inline HepMatrix::HepMatrix()
15  : m(0), nrow(0), ncol(0), size_(0) {}
16 
17 inline HepMatrix::HepMatrix_row HepMatrix::operator[] (int r)
18 #ifdef HEP_GNU_OPTIMIZED_RETURN
19  return b(*this,r);
20 {
21 #else
22 {
23  HepMatrix_row b(*this,r);
24 #endif
25  return b;
26 }
27 
28 inline const HepMatrix::HepMatrix_row_const HepMatrix::operator[] (int r) const
29 #ifdef HEP_GNU_OPTIMIZED_RETURN
30  return b(*this,r);
31 {
32 #else
33 {
34  HepMatrix_row_const b(*this,r);
35 #endif
36  return b;
37 }
38 
39 inline double &HepMatrix::HepMatrix_row::operator[](int c) {
40 #ifdef MATRIX_BOUND_CHECK
41  if (_r<0 || _r>=_a.num_row() || c<0 || c>=_a.num_col())
42  HepGenMatrix::error("Range error in HepMatrix::operator[][]");
43 #endif
44  return *(_a.m.begin()+_r*_a.ncol+c);
45 }
46 
47 inline const double &HepMatrix::HepMatrix_row_const::operator[](int c) const
48 {
49 #ifdef MATRIX_BOUND_CHECK
50  if (_r<0 || _r>=_a.num_row() || c<0 || c>=_a.num_col())
51  HepGenMatrix::error("Range error in HepMatrix::operator[][]");
52 #endif
53  return *(_a.m.begin()+_r*_a.ncol+c);
54 }
55 
56 inline HepMatrix::HepMatrix_row::HepMatrix_row(HepMatrix&a,int r)
57 : _a(a) {
58  _r = r;
59 }
60 
61 inline HepMatrix::HepMatrix_row_const::HepMatrix_row_const
62 (const HepMatrix&a, int r)
63  : _a(a)
64 {
65  _r = r;
66 }
67 
68 // This function swaps two Matrices without doing a full copy.
69 inline void swap(HepMatrix &hm1,HepMatrix &hm2) {
70  HepGenMatrix::swap(hm1.m,hm2.m);
71 /*** commented
72  HepGenMatrix::swap(hm1.nrow,hm2.nrow);
73  HepGenMatrix::swap(hm1.ncol,hm2.ncol);
74  HepGenMatrix::swap(hm1.size_,hm2.size_);
75 */
76 }
77 
78  /*-ap inline */ HepMatrix HepMatrix::inverse(int &ierr) const
79 #ifdef HEP_GNU_OPTIMIZED_RETURN
80  return mTmp(*this);
81 {
82 #else
83 {
84  HepMatrix mTmp(*this);
85 #endif
86  mTmp.invert(ierr);
87  return mTmp;
88 }
89 
90 inline HepMatrix HepMatrix::inverse() const {
91  int ierr;
92  HepMatrix mt=inverse(ierr);
93  if (ierr) throw std::runtime_error("Error in HepMatrix inversion");
94  return mt;
95 }
96 
97 inline void HepMatrix::invert() {
98  int ierr;
99  invert(ierr);
100  if (ierr) throw std::runtime_error("Error in HepMatrix inversion");
101 }
102 
103 } // namespace CLHEP
104 
void swap(HepMatrix &hm1, HepMatrix &hm2)
Definition: Matrix.icc:69