CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
CLHEP::HepDiagMatrix Class Reference

#include <DiagMatrix.h>

+ Inheritance diagram for CLHEP::HepDiagMatrix:

Classes

class  HepDiagMatrix_row
 
class  HepDiagMatrix_row_const
 

Public Member Functions

 HepDiagMatrix ()
 
 HepDiagMatrix (int p)
 
 HepDiagMatrix (int p, int)
 
 HepDiagMatrix (int p, HepRandom &r)
 
 HepDiagMatrix (const HepDiagMatrix &hm1)
 
virtual ~HepDiagMatrix ()
 
int num_row () const
 
int num_col () const
 
doubleoperator() (int row, int col)
 
const doubleoperator() (int row, int col) const
 
doublefast (int row, int col)
 
const doublefast (int row, int col) const
 
void assign (const HepMatrix &hm2)
 
void assign (const HepSymMatrix &hm2)
 
void assign (const HepDiagMatrix &hm2)
 
HepDiagMatrixoperator*= (double t)
 
HepDiagMatrixoperator/= (double t)
 
HepDiagMatrixoperator+= (const HepDiagMatrix &hm2)
 
HepDiagMatrixoperator-= (const HepDiagMatrix &hm2)
 
HepDiagMatrixoperator= (const HepDiagMatrix &hm2)
 
HepDiagMatrix operator- () const
 
HepDiagMatrix T () const
 
HepDiagMatrix apply (double(*f)(double, int, int)) const
 
HepSymMatrix similarity (const HepMatrix &hm1) const
 
HepSymMatrix similarityT (const HepMatrix &hm1) const
 
double similarity (const HepVector &) const
 
HepDiagMatrix sub (int min_row, int max_row) const
 
HepDiagMatrix sub (int min_row, int max_row)
 
void sub (int row, const HepDiagMatrix &hm1)
 
HepDiagMatrix inverse (int &ierr) const
 
void invert (int &ierr)
 
void invert ()
 
HepDiagMatrix inverse () const
 
double determinant () const
 
double trace () const
 
HepDiagMatrix_row operator[] (int)
 
HepDiagMatrix_row_const operator[] (int) const
 
- Public Member Functions inherited from CLHEP::HepGenMatrix
virtual ~HepGenMatrix ()
 
virtual int num_row () const =0
 
virtual int num_col () const =0
 
virtual const doubleoperator() (int row, int col) const =0
 
virtual doubleoperator() (int row, int col)=0
 
virtual void invert (int &)=0
 
HepGenMatrix_row operator[] (int)
 
const HepGenMatrix_row_const operator[] (int) const
 
virtual bool operator== (const HepGenMatrix &) const
 

Protected Member Functions

int num_size () const
 
- Protected Member Functions inherited from CLHEP::HepGenMatrix
virtual int num_size () const =0
 
void delete_m (int size, double *)
 
doublenew_m (int size)
 

Friends

class HepDiagMatrix_row
 
class HepDiagMatrix_row_const
 
class HepMatrix
 
class HepSymMatrix
 
HepDiagMatrix operator* (const HepDiagMatrix &hm1, const HepDiagMatrix &hm2)
 
HepDiagMatrix operator+ (const HepDiagMatrix &hm1, const HepDiagMatrix &hm2)
 
HepDiagMatrix operator- (const HepDiagMatrix &hm1, const HepDiagMatrix &hm2)
 
HepMatrix operator* (const HepDiagMatrix &hm1, const HepMatrix &hm2)
 
HepMatrix operator* (const HepMatrix &hm1, const HepDiagMatrix &hm2)
 
HepVector operator* (const HepDiagMatrix &hm1, const HepVector &hm2)
 

Additional Inherited Members

- Public Types inherited from CLHEP::HepGenMatrix
enum  { size_max = 25 }
 
typedef std::vector< double, Alloc< double, 25 > >::iterator mIter
 
typedef std::vector< double, Alloc< double, 25 > >::const_iterator mcIter
 
- Static Public Member Functions inherited from CLHEP::HepGenMatrix
static void swap (int &, int &)
 
static void swap (std::vector< double, Alloc< double, 25 > > &, std::vector< double, Alloc< double, 25 > > &)
 
static void error (const char *s)
 

Detailed Description

Author

Definition at line 35 of file DiagMatrix.h.

Constructor & Destructor Documentation

◆ HepDiagMatrix() [1/5]

CLHEP::HepDiagMatrix::HepDiagMatrix ( )
inline

◆ HepDiagMatrix() [2/5]

CLHEP::HepDiagMatrix::HepDiagMatrix ( int  p)
explicit

Definition at line 67 of file DiagMatrix.cc.

68 : m(p), nrow(p)
69{
70}

◆ HepDiagMatrix() [3/5]

CLHEP::HepDiagMatrix::HepDiagMatrix ( int  p,
int  init 
)

Definition at line 72 of file DiagMatrix.cc.

73 : m(p), nrow(p)
74{
75 switch(init)
76 {
77 case 0:
78 m.assign(nrow,0);
79 break;
80
81 case 1:
82 {
83 HepMatrix::mIter a=m.begin();
84 HepMatrix::mIter b=m.begin() + p;
85 for( ; a<b; a++) *a = 1.0;
86 break;
87 }
88 default:
89 error("DiagMatrix: initialization must be either 0 or 1.");
90 }
91}
std::vector< double, Alloc< double, 25 > >::iterator mIter
Definition: GenMatrix.h:73
static void error(const char *s)
Definition: GenMatrix.cc:70
void init()
Definition: testRandom.cc:29

◆ HepDiagMatrix() [4/5]

CLHEP::HepDiagMatrix::HepDiagMatrix ( int  p,
HepRandom r 
)

Definition at line 93 of file DiagMatrix.cc.

94 : m(p), nrow(p)
95{
96 HepMatrix::mIter a = m.begin();
97 HepMatrix::mIter b = m.begin() + num_size();
98 for(;a<b;a++) *a = r();
99}
int num_size() const

◆ HepDiagMatrix() [5/5]

CLHEP::HepDiagMatrix::HepDiagMatrix ( const HepDiagMatrix hm1)

Definition at line 106 of file DiagMatrix.cc.

107 : HepGenMatrix(hm1), m(hm1.nrow), nrow(hm1.nrow)
108{
109 m = hm1.m;
110}

◆ ~HepDiagMatrix()

CLHEP::HepDiagMatrix::~HepDiagMatrix ( )
virtual

Definition at line 103 of file DiagMatrix.cc.

103 {
104}

Member Function Documentation

◆ apply()

HepDiagMatrix CLHEP::HepDiagMatrix::apply ( double(*)(double, int, int)  f) const

Definition at line 581 of file DiagMatrix.cc.

585{
586#else
587{
588 HepDiagMatrix mret(num_row());
589#endif
590 HepMatrix::mcIter a = m.begin();
591 HepMatrix::mIter b = mret.m.begin();
592 for(int ir=1;ir<=num_row();ir++) {
593 *(b++) = (*f)(*(a++), ir, ir);
594 }
595 return mret;
596}
std::vector< double, Alloc< double, 25 > >::const_iterator mcIter
Definition: GenMatrix.h:74
void f(void g())
Definition: excDblThrow.cc:38

Referenced by main().

◆ assign() [1/3]

void CLHEP::HepDiagMatrix::assign ( const HepDiagMatrix hm2)

◆ assign() [2/3]

void CLHEP::HepDiagMatrix::assign ( const HepMatrix hm2)

Definition at line 598 of file DiagMatrix.cc.

599{
600 if(hm1.num_row()!=nrow)
601 {
602 nrow = hm1.num_row();
603 m.resize(nrow);
604 }
605 HepMatrix::mcIter a = hm1.m.begin();
606 HepMatrix::mIter b = m.begin();
607 for(int r=1;r<=nrow;r++) {
608 *(b++) = *a;
609 if(r<nrow) a += (nrow+1);
610 }
611}

Referenced by main().

◆ assign() [3/3]

void CLHEP::HepDiagMatrix::assign ( const HepSymMatrix hm2)

Definition at line 613 of file DiagMatrix.cc.

614{
615 if(hm1.num_row()!=nrow)
616 {
617 nrow = hm1.num_row();
618 m.resize(nrow);
619 }
620 HepMatrix::mcIter a = hm1.m.begin();
621 HepMatrix::mIter b = m.begin();
622 for(int r=1;r<=nrow;r++) {
623 *(b++) = *a;
624 if(r<nrow) a += (r+1);
625 }
626}

◆ determinant()

double CLHEP::HepDiagMatrix::determinant ( ) const

Definition at line 711 of file DiagMatrix.cc.

711 {
712 double d = 1.0;
713 HepMatrix::mcIter end = m.begin() + nrow;
714 for (HepMatrix::mcIter p=m.begin(); p < end; p++)
715 d *= *p;
716 return d;
717}

◆ fast() [1/2]

double & CLHEP::HepDiagMatrix::fast ( int  row,
int  col 
)

Referenced by main().

◆ fast() [2/2]

const double & CLHEP::HepDiagMatrix::fast ( int  row,
int  col 
) const

◆ inverse() [1/2]

HepDiagMatrix CLHEP::HepDiagMatrix::inverse ( ) const
inline

◆ inverse() [2/2]

HepDiagMatrix CLHEP::HepDiagMatrix::inverse ( int &  ierr) const

◆ invert() [1/2]

void CLHEP::HepDiagMatrix::invert ( )
inline

◆ invert() [2/2]

void CLHEP::HepDiagMatrix::invert ( int &  ierr)
virtual

Implements CLHEP::HepGenMatrix.

Definition at line 695 of file DiagMatrix.cc.

695 {
696 int n = num_row();
697 ierr = 1;
698 HepMatrix::mIter hmm = m.begin();
699 int i;
700 for(i=0;i<n;i++) {
701 if(*(hmm++)==0) return;
702 }
703 ierr = 0;
704 hmm = m.begin();
705 for(i=0;i<n;i++) {
706 *hmm = 1.0 / *hmm;
707 hmm++;
708 }
709}

◆ num_col()

◆ num_row()

◆ num_size()

int CLHEP::HepDiagMatrix::num_size ( ) const
inlineprotectedvirtual

Implements CLHEP::HepGenMatrix.

Referenced by HepDiagMatrix().

◆ operator()() [1/2]

double & CLHEP::HepDiagMatrix::operator() ( int  row,
int  col 
)
virtual

Implements CLHEP::HepGenMatrix.

◆ operator()() [2/2]

const double & CLHEP::HepDiagMatrix::operator() ( int  row,
int  col 
) const
virtual

Implements CLHEP::HepGenMatrix.

◆ operator*=()

HepDiagMatrix & CLHEP::HepDiagMatrix::operator*= ( double  t)

Definition at line 521 of file DiagMatrix.cc.

522{
523 SIMPLE_UOP(*=)
524 return (*this);
525}
#define SIMPLE_UOP(OPER)
Definition: DiagMatrix.cc:26

◆ operator+=()

HepDiagMatrix & CLHEP::HepDiagMatrix::operator+= ( const HepDiagMatrix hm2)

Definition at line 476 of file DiagMatrix.cc.

477{
478 CHK_DIM_2(num_row(),hm2.num_row(),num_col(),hm2.num_col(),+=);
479 SIMPLE_BOP(+=)
480 return (*this);
481}
#define CHK_DIM_2(r1, r2, c1, c2, fun)
Definition: DiagMatrix.cc:44
#define SIMPLE_BOP(OPER)
Definition: DiagMatrix.cc:31

◆ operator-()

HepDiagMatrix CLHEP::HepDiagMatrix::operator- ( ) const

Definition at line 176 of file DiagMatrix.cc.

179{
180#else
181{
182 HepDiagMatrix hm2(nrow);
183#endif
184 HepMatrix::mcIter a=m.begin();
185 HepMatrix::mIter b=hm2.m.begin();
186 HepMatrix::mcIter e=m.begin()+num_size();
187 for(;a<e; a++, b++) (*b) = -(*a);
188 return hm2;
189}

◆ operator-=()

HepDiagMatrix & CLHEP::HepDiagMatrix::operator-= ( const HepDiagMatrix hm2)

Definition at line 508 of file DiagMatrix.cc.

509{
510 CHK_DIM_2(num_row(),hm2.num_row(),num_col(),hm2.num_col(),-=);
511 SIMPLE_BOP(-=)
512 return (*this);
513}

◆ operator/=()

HepDiagMatrix & CLHEP::HepDiagMatrix::operator/= ( double  t)

Definition at line 515 of file DiagMatrix.cc.

516{
517 SIMPLE_UOP(/=)
518 return (*this);
519}

◆ operator=()

HepDiagMatrix & CLHEP::HepDiagMatrix::operator= ( const HepDiagMatrix hm2)

Definition at line 547 of file DiagMatrix.cc.

548{
549 if(hm1.nrow != nrow)
550 {
551 nrow = hm1.nrow;
552 m.resize(nrow);
553 }
554 m=hm1.m;
555 return (*this);
556}

◆ operator[]() [1/2]

HepDiagMatrix_row CLHEP::HepDiagMatrix::operator[] ( int  )
inline

◆ operator[]() [2/2]

HepDiagMatrix_row_const CLHEP::HepDiagMatrix::operator[] ( int  ) const
inline

◆ similarity() [1/2]

HepSymMatrix CLHEP::HepDiagMatrix::similarity ( const HepMatrix hm1) const

Definition at line 628 of file DiagMatrix.cc.

631{
632#else
633{
634 HepSymMatrix mret(hm1.num_row());
635#endif
636 CHK_DIM_1(num_row(),hm1.num_col(),"similarity");
637// HepMatrix temp = hm1*(*this);
638// If hm1*(*this) has correct dimensions, then so will the hm1.T multiplication.
639// So there is no need to check dimensions again.
640 HepMatrix::mIter mrc = mret.m.begin();
641 for(int r=1;r<=mret.num_row();r++) {
642 HepMatrix::mcIter mrr = hm1.m.begin()+(r-1)*hm1.num_col();
643 HepMatrix::mcIter mc = hm1.m.begin();
644 for(int c=1;c<=r;c++) {
645 HepMatrix::mcIter mi = m.begin();
646 double tmp = 0;
647 HepMatrix::mcIter mr = mrr;
648 for(int i=0;i<hm1.num_col();i++)
649 tmp+=*(mr++) * *(mc++) * *(mi++);
650 *(mrc++) = tmp;
651 }
652 }
653 return mret;
654}
#define CHK_DIM_1(c1, r2, fun)
Definition: DiagMatrix.cc:49
friend class HepSymMatrix
Definition: DiagMatrix.h:173

Referenced by main(), and similarity().

◆ similarity() [2/2]

double CLHEP::HepDiagMatrix::similarity ( const HepVector hm1) const

Definition at line 656 of file DiagMatrix.cc.

657{
658 double mret;
659 CHK_DIM_1(num_row(),hm1.num_row(),similarity);
660 HepMatrix::mcIter mi = m.begin();
661 HepMatrix::mcIter mv = hm1.m.begin();
662 mret = *(mv)* *(mv)* *(mi++);
663 mv++;
664 for(int i=2;i<=hm1.num_row();i++) {
665 mret+=*(mv)* *(mv)* *(mi++);
666 mv++;
667 }
668 return mret;
669}
HepSymMatrix similarity(const HepMatrix &hm1) const
Definition: DiagMatrix.cc:628

◆ similarityT()

HepSymMatrix CLHEP::HepDiagMatrix::similarityT ( const HepMatrix hm1) const

Definition at line 671 of file DiagMatrix.cc.

674{
675#else
676{
677 HepSymMatrix mret(hm1.num_col());
678#endif
679 CHK_DIM_1(num_col(),hm1.num_row(),similarityT);
680// Matrix temp = (*this)*hm1;
681// If hm1*(*this) has correct dimensions, then so will the hm1.T multiplication.
682// So there is no need to check dimensions again.
683 for(int r=1;r<=mret.num_row();r++)
684 for(int c=1;c<=r;c++)
685 {
686 HepMatrix::mcIter mi = m.begin();
687 double tmp = hm1(1,r)*hm1(1,c)* *(mi++);
688 for(int i=2;i<=hm1.num_row();i++)
689 tmp+=hm1(i,r)*hm1(i,c)* *(mi++);
690 mret.fast(r,c) = tmp;
691 }
692 return mret;
693}
HepSymMatrix similarityT(const HepMatrix &hm1) const
Definition: DiagMatrix.cc:671

Referenced by main().

◆ sub() [1/3]

HepDiagMatrix CLHEP::HepDiagMatrix::sub ( int  min_row,
int  max_row 
)

Definition at line 135 of file DiagMatrix.cc.

136{
137 HepDiagMatrix mret(max_row-min_row+1);
138 if(max_row > num_row())
139 error("HepDiagMatrix::sub: Index out of range");
140 HepMatrix::mIter a = mret.m.begin();
141 HepMatrix::mIter b = m.begin() + min_row - 1;
142 HepMatrix::mIter e = mret.m.begin() + mret.num_row();
143 for(;a<e;) *(a++) = *(b++);
144 return mret;
145}

◆ sub() [2/3]

HepDiagMatrix CLHEP::HepDiagMatrix::sub ( int  min_row,
int  max_row 
) const

Definition at line 118 of file DiagMatrix.cc.

121{
122#else
123{
124 HepDiagMatrix mret(max_row-min_row+1);
125#endif
126 if(max_row > num_row())
127 error("HepDiagMatrix::sub: Index out of range");
128 HepMatrix::mIter a = mret.m.begin();
129 HepMatrix::mcIter b = m.begin() + min_row - 1;
130 HepMatrix::mIter e = mret.m.begin() + mret.num_row();
131 for(;a<e;) *(a++) = *(b++);
132 return mret;
133}

Referenced by diagmatrix_test(), and main().

◆ sub() [3/3]

void CLHEP::HepDiagMatrix::sub ( int  row,
const HepDiagMatrix hm1 
)

Definition at line 147 of file DiagMatrix.cc.

148{
149 if(row <1 || row+hm1.num_row()-1 > num_row() )
150 error("HepDiagMatrix::sub: Index out of range");
151 HepMatrix::mcIter a = hm1.m.begin();
152 HepMatrix::mIter b = m.begin() + row - 1;
153 HepMatrix::mcIter e = hm1.m.begin() + hm1.num_row();
154 for(;a<e;) *(b++) = *(a++);
155}

◆ T()

HepDiagMatrix CLHEP::HepDiagMatrix::T ( ) const

Referenced by main().

◆ trace()

double CLHEP::HepDiagMatrix::trace ( ) const

Definition at line 719 of file DiagMatrix.cc.

719 {
720 double d = 0.0;
721 HepMatrix::mcIter end = m.begin() + nrow;
722 for (HepMatrix::mcIter p=m.begin(); p < end; p++)
723 d += *p;
724 return d;
725}

Friends And Related Function Documentation

◆ HepDiagMatrix_row

friend class HepDiagMatrix_row
friend

Definition at line 170 of file DiagMatrix.h.

◆ HepDiagMatrix_row_const

friend class HepDiagMatrix_row_const
friend

Definition at line 171 of file DiagMatrix.h.

◆ HepMatrix

friend class HepMatrix
friend

Definition at line 172 of file DiagMatrix.h.

◆ HepSymMatrix

friend class HepSymMatrix
friend

Definition at line 173 of file DiagMatrix.h.

◆ operator* [1/4]

HepDiagMatrix operator* ( const HepDiagMatrix hm1,
const HepDiagMatrix hm2 
)
friend

Definition at line 413 of file DiagMatrix.cc.

416{
417#else
418{
419 HepDiagMatrix mret(hm1.num_row());
420#endif
421 CHK_DIM_1(hm1.num_col(),hm2.num_row(),*);
422 HepMatrix::mIter a = mret.m.begin();
423 HepMatrix::mcIter b = hm1.m.begin();
424 HepMatrix::mcIter c = hm2.m.begin();
425 HepMatrix::mIter e = mret.m.begin() + hm1.num_col();
426 for(;a<e;) *(a++) = *(b++) * (*(c++));
427 return mret;
428}

◆ operator* [2/4]

HepMatrix operator* ( const HepDiagMatrix hm1,
const HepMatrix hm2 
)
friend

Definition at line 392 of file DiagMatrix.cc.

395{
396#else
397{
398 HepMatrix mret(hm1.num_row(),hm2.num_col());
399#endif
400 CHK_DIM_1(hm1.num_col(),hm2.num_row(),*);
401 HepMatrix::mcIter mit1=hm2.m.begin();
402 HepMatrix::mIter mir=mret.m.begin();
403 HepMatrix::mcIter mrr = hm1.m.begin();
404 for(int irow=1;irow<=hm2.num_row();irow++) {
405 for(int icol=1;icol<=hm2.num_col();icol++) {
406 *(mir++) = *(mit1++) * (*mrr);
407 }
408 mrr++;
409 }
410 return mret;
411}
friend class HepMatrix
Definition: DiagMatrix.h:172

◆ operator* [3/4]

HepVector operator* ( const HepDiagMatrix hm1,
const HepVector hm2 
)
friend

Definition at line 430 of file DiagMatrix.cc.

433{
434#else
435{
436 HepVector mret(hm1.num_row());
437#endif
438 CHK_DIM_1(hm1.num_col(),hm2.num_row(),*);
439 HepGenMatrix::mIter mir=mret.m.begin();
440 HepGenMatrix::mcIter mi1 = hm1.m.begin(), mi2 = hm2.m.begin();
441 for(int icol=1;icol<=hm1.num_col();icol++) {
442 *(mir++) = *(mi1++) * *(mi2++);
443 }
444 return mret;
445}

◆ operator* [4/4]

HepMatrix operator* ( const HepMatrix hm1,
const HepDiagMatrix hm2 
)
friend

Definition at line 372 of file DiagMatrix.cc.

375{
376#else
377 {
378 HepMatrix mret(hm1.num_row(),hm2.num_col());
379#endif
380 CHK_DIM_1(hm1.num_col(),hm2.num_row(),*);
381 HepMatrix::mcIter mit1=hm1.m.begin();
382 HepMatrix::mIter mir=mret.m.begin();
383 for(int irow=1;irow<=hm1.num_row();irow++) {
384 HepMatrix::mcIter mcc = hm2.m.begin();
385 for(int icol=1;icol<=hm1.num_col();icol++) {
386 *(mir++) = *(mit1++) * (*(mcc++));
387 }
388 }
389 return mret;
390 }

◆ operator+

HepDiagMatrix operator+ ( const HepDiagMatrix hm1,
const HepDiagMatrix hm2 
)
friend

Definition at line 221 of file DiagMatrix.cc.

224{
225#else
226{
227 HepDiagMatrix mret(hm1.nrow);
228#endif
229 CHK_DIM_1(hm1.nrow,hm2.nrow,+);
230 SIMPLE_TOP(+)
231 return mret;
232}
#define SIMPLE_TOP(OPER)
Definition: DiagMatrix.cc:37

◆ operator-

HepDiagMatrix operator- ( const HepDiagMatrix hm1,
const HepDiagMatrix hm2 
)
friend

Definition at line 291 of file DiagMatrix.cc.

294{
295#else
296{
297 HepDiagMatrix mret(hm1.nrow);
298#endif
299 CHK_DIM_1(hm1.num_row(),hm2.num_row(),-);
300 SIMPLE_TOP(-)
301 return mret;
302}

The documentation for this class was generated from the following files: