CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Matrix/CLHEP/Matrix/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#ifdef GNUPRAGMA
20#pragma interface
21#endif
22
23#include "CLHEP/Matrix/defs.h"
24#include "CLHEP/Matrix/GenMatrix.h"
25
26namespace CLHEP {
27
28class HepRandom;
29
30class HepMatrix;
31class HepSymMatrix;
32class HepDiagMatrix;
33class Hep3Vector;
34
39class HepVector : public HepGenMatrix {
40public:
41 inline HepVector();
42 // Default constructor. Gives vector of length 0.
43 // Another Vector can be assigned to it.
44
45 explicit HepVector(int p);
46 HepVector(int p, int);
47 // Constructor. Gives vector of length p.
48
49 HepVector(int p, HepRandom &r);
50
51 HepVector(const HepVector &v);
52 HepVector(const HepMatrix &m);
53 // Copy constructors.
54 // Note that there is an assignment operator for v = Hep3Vector.
55
56 virtual ~HepVector();
57 // Destructor.
58
59 inline const double & operator()(int row) const;
60 inline double & operator()(int row);
61 // Read or write a matrix element.
62 // ** Note that the indexing starts from (1). **
63
64 inline const double & operator[](int row) const;
65 inline double & operator[](int row);
66 // Read and write an element of a Vector.
67 // ** Note that the indexing starts from [0]. **
68
69 virtual const double & operator()(int row, int col) const;
70 virtual double & operator()(int row, int col);
71 // Read or write a matrix element.
72 // ** Note that the indexing starts from (1,1). **
73 // Allows accessing Vector using GenMatrix
74
75 HepVector & operator*=(double t);
76 // Multiply a Vector by a floating number.
77
78 HepVector & operator/=(double t);
79 // Divide a Vector by a floating number.
80
81 HepVector & operator+=( const HepMatrix &v2);
82 HepVector & operator+=( const HepVector &v2);
83 HepVector & operator-=( const HepMatrix &v2);
84 HepVector & operator-=( const HepVector &v2);
85 // Add or subtract a Vector.
86
87 HepVector & operator=( const HepVector &hm2);
88 // Assignment operators.
89
92 // assignment operators from other classes.
93
94 HepVector operator- () const;
95 // unary minus, ie. flip the sign of each element.
96
97 HepVector apply(double (*f)(double, int)) const;
98 // Apply a function to all elements.
99
100 HepVector sub(int min_row, int max_row) const;
101 // Returns a sub vector.
102 HepVector sub(int min_row, int max_row);
103 // SGI CC bug. I have to have both with/without const. I should not need
104 // one without const.
105
106 void sub(int row, const HepVector &v1);
107 // Replaces a sub vector of a Vector with v1.
108
109 inline double normsq() const;
110 // Returns norm squared.
111
112 inline double norm() const;
113 // Returns norm.
114
115 virtual int num_row() const;
116 // Returns number of rows.
117
118 virtual int num_col() const;
119 // Number of columns. Always returns 1. Provided for compatibility with
120 // GenMatrix.
121
122 HepMatrix T() const;
123 // Returns the transpose of a Vector. Note that the returning type is
124 // Matrix.
125
126 friend inline void swap(HepVector &v1, HepVector &v2);
127 // Swaps two vectors.
128
129protected:
130 virtual int num_size() const;
131
132private:
133 virtual void invert(int&);
134 // produces an error. Demanded by GenMatrix
135
136 friend class HepDiagMatrix;
137 friend class HepSymMatrix;
138 friend class HepMatrix;
139 // friend classes
140
141 friend double dot(const HepVector &v1, const HepVector &v2);
142 // f = v1 * v2;
143
144 friend HepVector operator+(const HepVector &v1, const HepVector &v2);
145 friend HepVector operator-(const HepVector &v1, const HepVector &v2);
146 friend HepVector operator*(const HepSymMatrix &hm1, const HepVector &hm2);
147 friend HepVector operator*(const HepDiagMatrix &hm1, const HepVector &hm2);
148 friend HepMatrix operator*(const HepVector &hm1, const HepMatrix &hm2);
149 friend HepVector operator*(const HepMatrix &hm1, const HepVector &hm2);
150
151 friend HepVector solve(const HepMatrix &a, const HepVector &v);
152 friend void tridiagonal(HepSymMatrix *a,HepMatrix *hsm);
153 friend void row_house(HepMatrix *,const HepMatrix &, double, int, int,
154 int, int);
155 friend void row_house(HepMatrix *,const HepVector &, double, int, int);
156 friend void back_solve(const HepMatrix &R, HepVector *b);
157 friend void col_house(HepMatrix *,const HepMatrix &,double, int, int,
158 int, int);
159 friend HepVector house(const HepSymMatrix &a,int row,int col);
160 friend HepVector house(const HepMatrix &a,int row,int col);
161 friend void house_with_update(HepMatrix *a,int row,int col);
162 friend HepSymMatrix vT_times_v(const HepVector &v);
163 friend HepVector qr_solve(HepMatrix *, const HepVector &);
164
165#ifdef DISABLE_ALLOC
166 std::vector<double > m;
167#else
168 std::vector<double,Alloc<double,25> > m;
169#endif
170 int nrow;
171};
172
173//
174// Operations other than member functions
175//
176
177std::ostream& operator<<(std::ostream &s, const HepVector &v);
178// Write out Matrix, SymMatrix, DiagMatrix and Vector into ostream.
179
180HepVector operator*(const HepMatrix &hm1, const HepVector &hm2);
181HepVector operator*(double t, const HepVector &v1);
182HepVector operator*(const HepVector &v1, double t);
183// Multiplication operators.
184// Note that m *= x is always faster than m = m * x.
185
186HepVector operator/(const HepVector &v1, double t);
187// Divide by a real number.
188
189HepVector operator+(const HepMatrix &hm1, const HepVector &v2);
190HepVector operator+(const HepVector &v1, const HepMatrix &hm2);
191HepVector operator+(const HepVector &v1, const HepVector &v2);
192// Addition operators
193
194HepVector operator-(const HepMatrix &hm1, const HepVector &v2);
195HepVector operator-(const HepVector &v1, const HepMatrix &hm2);
196HepVector operator-(const HepVector &v1, const HepVector &v2);
197// subtraction operators
198
199HepVector dsum(const HepVector &s1, const HepVector &s2);
200// Direct sum of two vectors;
201
202} // namespace CLHEP
203
204#ifdef ENABLE_BACKWARDS_COMPATIBILITY
205// backwards compatibility will be enabled ONLY in CLHEP 1.9
206using namespace CLHEP;
207#endif
208
209#include "CLHEP/Matrix/Vector.icc"
210
211#endif
HepVector & operator/=(double t)
Definition Vector.cc:444
friend void swap(HepVector &v1, HepVector &v2)
HepVector sub(int min_row, int max_row) const
Definition Vector.cc:151
HepMatrix T() const
Definition Vector.cc:531
double & operator[](int row)
HepVector & operator-=(const HepMatrix &v2)
Definition Vector.cc:430
virtual ~HepVector()
Definition Vector.cc:92
double & operator()(int row)
virtual int num_size() const
Definition Vector.cc:118
virtual int num_col() const
Definition Vector.cc:119
HepVector apply(double(*f)(double, int)) const
Definition Vector.cc:556
HepVector operator-() const
Definition Vector.cc:213
double norm() const
virtual int num_row() const
Definition Vector.cc:117
friend double dot(const HepVector &v1, const HepVector &v2)
Definition Vector.cc:543
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:576
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:469
friend HepVector operator*(const HepSymMatrix &hm1, const HepVector &hm2)
Definition SymMatrix.cc:510
friend HepSymMatrix vT_times_v(const HepVector &v)
Definition SymMatrix.cc:542
friend HepVector qr_solve(HepMatrix *, const HepVector &)
friend HepVector operator+(const HepVector &v1, const HepVector &v2)
Definition Vector.cc:256
HepVector & operator*=(double t)
Definition Vector.cc:450
friend HepVector house(const HepSymMatrix &a, int row, int col)
HepVector & operator+=(const HepMatrix &v2)
Definition Vector.cc:409
double normsq() const
friend void back_solve(const HepMatrix &R, HepVector *b)
void f(void g())
Hep3Vector operator-(const Hep3Vector &, const Hep3Vector &)
Hep3Vector operator+(const Hep3Vector &, const Hep3Vector &)
HepLorentzRotation operator*(const HepRotation &r, const HepLorentzRotation &lt)
std::ostream & operator<<(std::ostream &os, const HepAxisAngle &aa)
Definition AxisAngle.cc:86
HepDiagMatrix dsum(const HepDiagMatrix &s1, const HepDiagMatrix &s2)
HepLorentzVector operator/(const HepLorentzVector &, double a)