CLHEP 2.4.7.1
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>
12namespace CLHEP {
13
15 : m(0), nrow(0), ncol(0), size_(0) {}
16
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
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
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
47inline 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
57: _a(a) {
58 _r = r;
59}
60
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.
69inline 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
91 int ierr;
92 HepMatrix mt=inverse(ierr);
93 if (ierr) throw std::runtime_error("Error in HepMatrix inversion");
94 return mt;
95}
96
97inline 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
static void error(const char *s)
static void swap(int &, int &)
Definition GenMatrix.icc:13
HepMatrix_row_const(const HepMatrix &, int)
Definition Matrix.icc:62
const double & operator[](int) const
Definition Matrix.icc:47
HepMatrix_row(HepMatrix &, int)
Definition Matrix.icc:56
HepMatrix_row operator[](int)
Definition Matrix.icc:17
virtual int num_col() const
friend void swap(HepMatrix &hm1, HepMatrix &hm2)
Definition Matrix.icc:69
virtual int num_row() const
HepMatrix inverse() const
Definition Matrix.icc:90