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 
6 
7 #include <iostream>
8 
9 template<typename T, int N>
11 public:
12  typedef T Scalar;
13 
15 
17  RKSmallVector( const Scalar* d) {
18  for (int i=0; i<N; ++i) data_[i] = d[i];
19  }
20 
23  template <class Iter> RKSmallVector(Iter begin, Iter end) {
24  for (int i=0; i<N; i++) data_[i] = *begin++;
25  }
26 
27  int size() const {return N;}
28  int dim() const {return N;}
29 
31  const T& operator()(int i) const {return data_[i];}
32  T& operator()(int i) {return data_[i];}
33  const T& operator[](int i) const {return data_[i];}
34  T& operator[](int i) {return data_[i];}
35 
37 
38  template <class U>
40  for (int i=0; i<N; ++i) data_[i] += v[i];
41  return *this;
42  }
43 
44  template <class U>
46  for (int i=0; i<N; ++i) data_[i] -= v[i];
47  return *this;
48  }
49 
51  template <class U>
53  for (int i=0; i<N; ++i) data_[i] += t*v[i];
54  return *this;
55  }
56 
57 
61  for (int i=0; i<N; ++i) r[i] = -data_[i];
62  return r;
63  }
64 
67  for (int i=0; i<N; ++i) data_[i] *= t;
68  return *this;
69  }
72  for (int i=0; i<N; ++i) data_[i] /= t;
73  return *this;
74  }
75 
77  T dot( const RKSmallVector& v) const {
79  for (int i=0; i<N; ++i) r[i] = data_[i]*data_[i];
80  return r;
81  }
82 
83 private:
84 
85  Scalar data_[N];
86 
87 };
88 
90 template <class T, int N>
91 inline std::ostream & operator<<( std::ostream& s, const RKSmallVector<T,N>& v) {
92  s << std::endl;
93  for (int i=0; i<N; ++i) s << "v[" << i << "] = " << v[i] << std::endl;
94  return s;
95 }
96 
98 template <class T, class U, int N>
102  RT r;
103  for (int i=0; i<N; ++i) r[i] = a[i]+b[i];
104  return r;
105 }
106 template <class T, class U, int N>
110  RT r;
111  for (int i=0; i<N; ++i) r[i] = a[i]-b[i];
112  return r;
113 }
114 
118 template <class T, class Scal, int N>
119 inline RKSmallVector<T,N> operator*( const RKSmallVector<T,N>& v, const Scal& s) {
120  T t = static_cast<T>(s);
122  for (int i=0; i<N; ++i) r[i] = t*v[i];
123  return r;
124 }
125 template <class T, class Scal, int N>
126 inline RKSmallVector<T,N> operator*( const Scal& s, const RKSmallVector<T,N>& v) {
127  T t = static_cast<T>(s);
129  for (int i=0; i<N; ++i) r[i] = t*v[i];
130  return r;
131 }
132 
136 template <class T, class Scal, int N>
137 inline RKSmallVector<T,N> operator/( const RKSmallVector<T,N>& v, const Scal& s) {
138  T t = static_cast<T>(s);
140  for (int i=0; i<N; ++i) r[i] = v[i]/t;
141  return r;
142 }
143 
144 
145 #endif
Basic3DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
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:77
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
RKSmallVector(Iter begin, Iter end)
Definition: RKSmallVector.h:23
const T & operator()(int i) const
access to values
Definition: RKSmallVector.h:31
Basic3DVector & operator-=(const Basic3DVector< U > &p)
RKSmallVector(const Scalar *d)
Construct from array.
Definition: RKSmallVector.h:17
T & operator()(int i)
Definition: RKSmallVector.h:32
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
T & operator[](int i)
Definition: RKSmallVector.h:34
#define dso_internal
Definition: Visibility.h:13
int dim() const
Definition: RKSmallVector.h:28
#define end
Definition: vmac.h:38
RKSmallVector operator-() const
Unary minus, returns a vector with negated components.
Definition: RKSmallVector.h:59
const T & operator[](int i) const
Definition: RKSmallVector.h:33
int size() const
Definition: RKSmallVector.h:27
#define N
Definition: blowfish.cc:9
Basic3DVector & operator/=(T t)
Scaling by a scalar value (division)
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:52
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
long double T
mathSSE::Vec4< T > v
Basic3DVector & operator+=(const Basic3DVector< U > &p)