CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1// -*- C++ -*-
2// CLASSDOC OFF
3// ---------------------------------------------------------------------------
4// CLASSDOC ON
5//
6// This file is a part of the CLHEP - a Class Library for High Energy Physics.
7//
8// Although Vector and Matrix class are very much related, I like the typing
9// information I get by making them different types. It is usually an error
10// to use a Matrix where a Vector is expected, except in the case that the
11// Matrix is a single column. But this case can be taken care of by using
12// constructors as conversions. For this same reason, I don't want to make
13// a Vector a derived class of Matrix.
14//
15
16#ifndef _Vector_H_
17#define _Vector_H_
18
19#include "CLHEP/Matrix/defs.h"
20#include "CLHEP/Matrix/GenMatrix.h"
21
22namespace CLHEP {
23
24class HepRandom;
25
26class HepMatrix;
27class HepSymMatrix;
28class HepDiagMatrix;
29class Hep3Vector;
30
31/**
32 * @author
33 * @ingroup matrix
34 */
35class HepVector : public HepGenMatrix {
36public:
37 inline HepVector();
38 // Default constructor. Gives vector of length 0.
39 // Another Vector can be assigned to it.
40
41 explicit HepVector(int p);
42 HepVector(int p, int);
43 // Constructor. Gives vector of length p.
44
45 HepVector(int p, HepRandom &r);
46
47 HepVector(const HepVector &v);
48 HepVector(const HepMatrix &m);
49 // Copy constructors.
50 // Note that there is an assignment operator for v = Hep3Vector.
51
52 virtual ~HepVector();
53 // Destructor.
54
55 inline const double & operator()(int row) const;
56 inline double & operator()(int row);
57 // Read or write a matrix element.
58 // ** Note that the indexing starts from (1). **
59
60 inline const double & operator[](int row) const;
61 inline double & operator[](int row);
62 // Read and write an element of a Vector.
63 // ** Note that the indexing starts from [0]. **
64
65 virtual const double & operator()(int row, int col) const;
66 virtual double & operator()(int row, int col);
67 // Read or write a matrix element.
68 // ** Note that the indexing starts from (1,1). **
69 // Allows accessing Vector using GenMatrix
70
71 HepVector & operator*=(double t);
72 // Multiply a Vector by a floating number.
73
74 HepVector & operator/=(double t);
75 // Divide a Vector by a floating number.
76
77 HepVector & operator+=( const HepMatrix &v2);
78 HepVector & operator+=( const HepVector &v2);
79 HepVector & operator-=( const HepMatrix &v2);
80 HepVector & operator-=( const HepVector &v2);
81 // Add or subtract a Vector.
82
83 HepVector & operator=( const HepVector &hm2);
84 // Assignment operators.
85
88 // assignment operators from other classes.
89
90 HepVector operator- () const;
91 // unary minus, ie. flip the sign of each element.
92
93 HepVector apply(double (*f)(double, int)) const;
94 // Apply a function to all elements.
95
96 HepVector sub(int min_row, int max_row) const;
97 // Returns a sub vector.
98 HepVector sub(int min_row, int max_row);
99 // SGI CC bug. I have to have both with/without const. I should not need
100 // one without const.
101
102 void sub(int row, const HepVector &v1);
103 // Replaces a sub vector of a Vector with v1.
104
105 inline double normsq() const;
106 // Returns norm squared.
107
108 inline double norm() const;
109 // Returns norm.
110
111 virtual int num_row() const;
112 // Returns number of rows.
113
114 virtual int num_col() const;
115 // Number of columns. Always returns 1. Provided for compatibility with
116 // GenMatrix.
117
118 HepMatrix T() const;
119 // Returns the transpose of a Vector. Note that the returning type is
120 // Matrix.
121
122 friend inline void swap(HepVector &v1, HepVector &v2);
123 // Swaps two vectors.
124
125protected:
126 virtual int num_size() const;
127
128private:
129 virtual void invert(int&);
130 // produces an error. Demanded by GenMatrix
131
132 friend class HepDiagMatrix;
133 friend class HepSymMatrix;
134 friend class HepMatrix;
135 // friend classes
136
137 friend double dot(const HepVector &v1, const HepVector &v2);
138 // f = v1 * v2;
139
140 friend HepVector operator+(const HepVector &v1, const HepVector &v2);
141 friend HepVector operator-(const HepVector &v1, const HepVector &v2);
142 friend HepVector operator*(const HepSymMatrix &hm1, const HepVector &hm2);
143 friend HepVector operator*(const HepDiagMatrix &hm1, const HepVector &hm2);
144 friend HepMatrix operator*(const HepVector &hm1, const HepMatrix &hm2);
145 friend HepVector operator*(const HepMatrix &hm1, const HepVector &hm2);
146
147 friend HepVector solve(const HepMatrix &a, const HepVector &v);
148 friend void tridiagonal(HepSymMatrix *a,HepMatrix *hsm);
149 friend void row_house(HepMatrix *,const HepMatrix &, double, int, int,
150 int, int);
151 friend void row_house(HepMatrix *,const HepVector &, double, int, int);
152 friend void back_solve(const HepMatrix &R, HepVector *b);
153 friend void col_house(HepMatrix *,const HepMatrix &,double, int, int,
154 int, int);
155 friend HepVector house(const HepSymMatrix &a,int row,int col);
156 friend HepVector house(const HepMatrix &a,int row,int col);
157 friend void house_with_update(HepMatrix *a,int row,int col);
158 friend HepSymMatrix vT_times_v(const HepVector &v);
159 friend HepVector qr_solve(HepMatrix *, const HepVector &);
160
161#ifdef DISABLE_ALLOC
162 std::vector<double > m;
163#else
164 std::vector<double,Alloc<double,25> > m;
165#endif
166 int nrow;
167};
168
169//
170// Operations other than member functions
171//
172
173std::ostream& operator<<(std::ostream &s, const HepVector &v);
174// Write out Matrix, SymMatrix, DiagMatrix and Vector into ostream.
175
176HepVector operator*(const HepMatrix &hm1, const HepVector &hm2);
177HepVector operator*(double t, const HepVector &v1);
178HepVector operator*(const HepVector &v1, double t);
179// Multiplication operators.
180// Note that m *= x is always faster than m = m * x.
181
182HepVector operator/(const HepVector &v1, double t);
183// Divide by a real number.
184
185HepVector operator+(const HepMatrix &hm1, const HepVector &v2);
186HepVector operator+(const HepVector &v1, const HepMatrix &hm2);
187HepVector operator+(const HepVector &v1, const HepVector &v2);
188// Addition operators
189
190HepVector operator-(const HepMatrix &hm1, const HepVector &v2);
191HepVector operator-(const HepVector &v1, const HepMatrix &hm2);
192HepVector operator-(const HepVector &v1, const HepVector &v2);
193// subtraction operators
194
195HepVector dsum(const HepVector &s1, const HepVector &s2);
196// Direct sum of two vectors;
197
198} // namespace CLHEP
199
200#ifdef ENABLE_BACKWARDS_COMPATIBILITY
201// backwards compatibility will be enabled ONLY in CLHEP 1.9
202using namespace CLHEP;
203#endif
204
205#include "CLHEP/Matrix/Vector.icc"
206
207#endif /*!_Vector_H*/
HepVector & operator/=(double t)
Definition: Vector.cc:443
friend void swap(HepVector &v1, HepVector &v2)
HepVector sub(int min_row, int max_row) const
Definition: Vector.cc:150
HepMatrix T() const
Definition: Vector.cc:530
double & operator[](int row)
HepVector & operator-=(const HepMatrix &v2)
Definition: Vector.cc:429
virtual ~HepVector()
Definition: Vector.cc:91
double & operator()(int row)
virtual int num_size() const
Definition: Vector.cc:117
virtual int num_col() const
Definition: Vector.cc:118
HepVector apply(double(*f)(double, int)) const
Definition: Vector.cc:555
HepVector operator-() const
Definition: Vector.cc:212
double norm() const
virtual int num_row() const
Definition: Vector.cc:116
friend double dot(const HepVector &v1, const HepVector &v2)
Definition: Vector.cc:542
friend void row_house(HepMatrix *, const HepMatrix &, double, int, int, int, int)
friend void tridiagonal(HepSymMatrix *a, HepMatrix *hsm)
friend HepVector solve(const HepMatrix &a, const HepVector &v)
Definition: Vector.cc:575
const double & operator[](int row) const
const double & operator()(int row) const
friend void house_with_update(HepMatrix *a, int row, int col)
friend void col_house(HepMatrix *, const HepMatrix &, double, int, int, int, int)
HepVector & operator=(const HepVector &hm2)
Definition: Vector.cc:468
friend HepVector operator*(const HepSymMatrix &hm1, const HepVector &hm2)
Definition: SymMatrix.cc:507
friend HepSymMatrix vT_times_v(const HepVector &v)
Definition: SymMatrix.cc:539
friend HepVector qr_solve(HepMatrix *, const HepVector &)
friend HepVector operator+(const HepVector &v1, const HepVector &v2)
Definition: Vector.cc:255
HepVector & operator*=(double t)
Definition: Vector.cc:449
friend HepVector house(const HepSymMatrix &a, int row, int col)
HepVector & operator+=(const HepMatrix &v2)
Definition: Vector.cc:408
double normsq() const
friend void back_solve(const HepMatrix &R, HepVector *b)
Definition: MatrixLinear.cc:63
void f(void g())
Definition: excDblThrow.cc:38
std::ostream & operator<<(std::ostream &s, const HepDiagMatrix &q)
Definition: DiagMatrix.cc:560
HepMatrix operator+(const HepMatrix &hm1, const HepDiagMatrix &d2)
Definition: DiagMatrix.cc:193
HepMatrix operator-(const HepMatrix &hm1, const HepDiagMatrix &d2)
Definition: DiagMatrix.cc:264
HepDiagMatrix operator/(const HepDiagMatrix &hm1, double t)
Definition: DiagMatrix.cc:335
HepMatrix operator*(const HepMatrix &hm1, const HepDiagMatrix &hm2)
Definition: DiagMatrix.cc:372
HepDiagMatrix dsum(const HepDiagMatrix &s1, const HepDiagMatrix &s2)
Definition: DiagMatrix.cc:161