CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RKSmallVector.h
Go to the documentation of this file.
1 #ifndef RKSmallVector_H
2 #define RKSmallVector_H
3 
5 
6 #include <iostream>
7 
8 template<typename T, int N>
9 class RKSmallVector {
10 public:
11  typedef T Scalar;
12 
14 
16  RKSmallVector( const Scalar* d) {
17  for (int i=0; i<N; ++i) data_[i] = d[i];
18  }
19 
22  template <class Iter> RKSmallVector(Iter begin, Iter end) {
23  for (int i=0; i<N; i++) data_[i] = *begin++;
24  }
25 
26  int size() const {return N;}
27  int dim() const {return N;}
28 
30  const T& operator()(int i) const {return data_[i];}
31  T& operator()(int i) {return data_[i];}
32  const T& operator[](int i) const {return data_[i];}
33  T& operator[](int i) {return data_[i];}
34 
36 
37  template <class U>
39  for (int i=0; i<N; ++i) data_[i] += v[i];
40  return *this;
41  }
42 
43  template <class U>
45  for (int i=0; i<N; ++i) data_[i] -= v[i];
46  return *this;
47  }
48 
50  template <class U>
52  for (int i=0; i<N; ++i) data_[i] += t*v[i];
53  return *this;
54  }
55 
56 
60  for (int i=0; i<N; ++i) r[i] = -data_[i];
61  return r;
62  }
63 
65  RKSmallVector& operator*= ( const T& t) {
66  for (int i=0; i<N; ++i) data_[i] *= t;
67  return *this;
68  }
70  RKSmallVector& operator/= ( const T& t) {
71  for (int i=0; i<N; ++i) data_[i] /= t;
72  return *this;
73  }
74 
76  T dot( const RKSmallVector& v) const {
78  for (int i=0; i<N; ++i) r[i] = data_[i]*data_[i];
79  return r;
80  }
81 
82 private:
83 
85 
86 };
87 
89 template <class T, int N>
90 inline std::ostream & operator<<( std::ostream& s, const RKSmallVector<T,N>& v) {
91  s << std::endl;
92  for (int i=0; i<N; ++i) s << "v[" << i << "] = " << v[i] << std::endl;
93  return s;
94 }
95 
97 template <class T, class U, int N>
101  RT r;
102  for (int i=0; i<N; ++i) r[i] = a[i]+b[i];
103  return r;
104 }
105 template <class T, class U, int N>
109  RT r;
110  for (int i=0; i<N; ++i) r[i] = a[i]-b[i];
111  return r;
112 }
113 
117 template <class T, class Scal, int N>
118 inline RKSmallVector<T,N> operator*( const RKSmallVector<T,N>& v, const Scal& s) {
119  T t = static_cast<T>(s);
121  for (int i=0; i<N; ++i) r[i] = t*v[i];
122  return r;
123 }
124 template <class T, class Scal, int N>
125 inline RKSmallVector<T,N> operator*( const Scal& s, const RKSmallVector<T,N>& v) {
126  T t = static_cast<T>(s);
128  for (int i=0; i<N; ++i) r[i] = t*v[i];
129  return r;
130 }
131 
135 template <class T, class Scal, int N>
136 inline RKSmallVector<T,N> operator/( const RKSmallVector<T,N>& v, const Scal& s) {
137  T t = static_cast<T>(s);
139  for (int i=0; i<N; ++i) r[i] = v[i]/t;
140  return r;
141 }
142 
143 
144 #endif
int i
Definition: DBlmapReader.cc:9
T dot(const RKSmallVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
Definition: RKSmallVector.h:76
RKSmallVector & operator+=(const RKSmallVector< U, N > &v)
Operations with vector of same size.
Definition: RKSmallVector.h:38
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
RKSmallVector & operator*=(const T &t)
Scaling by a scalar value (multiplication)
Definition: RKSmallVector.h:65
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
RKSmallVector(Iter begin, Iter end)
Definition: RKSmallVector.h:22
const T & operator()(int i) const
access to values
Definition: RKSmallVector.h:30
RKSmallVector & operator/=(const T &t)
Scaling by a scalar value (division)
Definition: RKSmallVector.h:70
RKSmallVector(const Scalar *d)
Construct from array.
Definition: RKSmallVector.h:16
T & operator()(int i)
Definition: RKSmallVector.h:31
RKSmallVector & operator-=(const RKSmallVector< U, N > &v)
Definition: RKSmallVector.h:44
T & operator[](int i)
Definition: RKSmallVector.h:33
Basic2DVector< T > operator/(const Basic2DVector< T > &v, const Scalar &s)
int dim() const
Definition: RKSmallVector.h:27
#define end
Definition: vmac.h:38
RKSmallVector operator-() const
Unary minus, returns a vector with negated components.
Definition: RKSmallVector.h:58
const T & operator[](int i) const
Definition: RKSmallVector.h:32
int size() const
Definition: RKSmallVector.h:26
double b
Definition: hdecay.h:120
#define begin
Definition: vmac.h:31
double a
Definition: hdecay.h:121
RKSmallVector & increment(const RKSmallVector< U, N > &v, const T &t)
Increment by another vector multiplied by a scalar.
Definition: RKSmallVector.h:51
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
string s
Definition: asciidump.py:422
mathSSE::Vec4< T > v
Scalar data_[N]
Definition: RKSmallVector.h:84