HepVector


Although HepVector and HepMatrix class are very much related, I like the typing information I get by making them different types. It is usually an error to use a HepMatrix where a HepVector is expected, except in the case that the HepMatrix is a single column. But this case can be taken care of by using constructors as conversions. For this same reason, I don't want to make a HepVector derived class of HepMatrix.

Authors

Nobu Katayama and Mike Smyth

See also

HepGenMatrix, HepMatrix, HepSymMatrix, HepDiagMatrix, HepPile,

Declaration

#include "CLHEP/Matrix/Vector.h"

class HepVector : public HepGenMatrix

Public Member Functions

Constructor
inline HepVector()
Default constructor. Gives vector of zero length. Another HepVector can be assigned to it.
Constructor
HepVector(int p)
Gives vector of length p.
Constructor
HepVector(int p, int)
Gives vector of length p.
Constructor
#ifdef HEP_USE_RANDOM
HepVector(int p, HepRandom &r)
#endif
Constructor with a HepRandom object.
Constructor
HepVector(const HepMatrix &m)
Constructor from HepMatrix.
Copy constructor
HepVector(const HepVector &v)
Copy constructor.
Note that there is an assignment operator for v = Hep3Vector.
Destructor
virtual ~HepVector()
=
HepVector & operator = (const HepVector &m2)
Assignment operator.

HepVector & operator = (const HepMatrix &)
HepVector & operator = (const Hep3Vector &)
Assignment operators from other classes.
+=
HepVector & operator += (const HepMatrix &v2)
HepVector & operator += (const HepVector &v2)
Add a HepVector.
-
HepVector operator - () const
Unary minus, i.e. flip the sign of each element.
-=
HepVector & operator -= (const HepMatrix &v2)
HepVector & operator -= (const HepVector &v2)
Subtract a HepVector.
*=
HepVector & operator *= (HepDouble t)
Multiply a HepVector by a floating number.
/=
HepVector & operator /= (HepDouble t)
Divide a HepVector by a floating number.
()
inline const HepDouble & operator()(int row) const
inline HepDouble & operator()(int row)
Read or write a matrix element.
** Note that the indexing starts from (1) **

inline virtual const HepDouble & operator()(int row, int col) const
inline virtual HepDouble & operator()(int row, int col)
Read or write a matrix element.
** Note that indexing starts from (1,1) **
Allows accessing HepVector using HepGenMatrix.
[]
inline const HepDouble & operator[](int row) const
inline HepDouble & operator[](int row)
Read and write an element of a HepVector.
** Note that the indexing starts from [0] **
apply
HepVector apply(HepDouble (*f)(HepDouble, int)) const
Apply a function to all elements the vector.
norm
inline HepDouble norm() const
Returns norm.
normsq
inline HepDouble normsq() const
Returns norm squared.
num_col
inline virtual int num_col() const
Number of columns. Always returns 1.
Provided for compatibility with HepGenMatrix
num_row
inline virtual int num_row() const
Returns number of rows.
sub
HepVector sub(int min_row, int max_row) const
Returns a sub vector.

#ifdef HEP_CC_NEED_SUB_WITHOUT_CONST
HepVector sub(int min_row, int max_row)
#endif
SGI CC bug. I have to have both with/without const. I should not need one without const.

void sub(int row, const HepVector &v1)
Replaces a sub vector of a HepVector with v1.
T
HepMatrix T() const
Returns the transpose of a HepVector.
Note that the returning type is HepMatrix.

Non-Member Functions

+
HepVector operator + (const HepMatrix &m1, const HepVector &v2)
HepVector operator + (const HepVector &v1, const HepMatrix &m2)
HepVector operator + (const HepVector &v1, const HepVector &v2)
Addition operators.
-
HepVector operator - (const HepMatrix &m1, const HepVector &v2)
HepVector operator - (const HepVector &v1, const HepMatrix &m2)
HepVector operator - (const HepVector &v1, const HepVector &v2)
Subtraction operators.
*
HepVector operator * (const HepSymMatrix &m1, const HepVector &m2)
HepVector operator * (const HepDiagMatrix &m1, const HepVector &m2)
HepMatrix operator * (const HepVector &m1, const HepMatrix &m2)
HepVector operator * (const HepMatrix &m1, const HepVector &m2)
Multiplication operators.
Note that m *= x is always faster than m = m * x.

HepVector operator * (HepDouble t, const HepVector &v1)
HepVector operator * (const HepVector &v1, HepDouble t)
Multiplication with a number.
/
HepVector operator / (const HepVector &v1, HepDouble t)
Divide by a real number.
<<
HepStd::ostream & operator << (HepStd::ostream &s, const HepVector &v)
Output to a stream.
dot
HepDouble dot(const HepVector &v1, const HepVector &v2)
Scalar product.
dsum
HepVector dsum(const HepVector &s1, const HepVector &s2)
Direct sum of two vectors.
swap
swap(HepVector &v1, HepVector &v2)
Swaps two vectors.
vT_times_v
HepSymMatrix vT_times_v(const HepVector &v)

Example

CLHEP/test/testMatrix.cc


19 June 2001
EVC