Logo ROOT   6.18/05
Reference Guide
SVector.h
Go to the documentation of this file.
1// @(#)root/smatrix:$Id$
2// Author: T. Glebe, L. Moneta, J. Palacios 2005
3
4#ifndef ROOT_Math_SVector
5#define ROOT_Math_SVector
6/********************************************************************
7//
8// source:
9//
10// type: source code
11//
12// created: 16. Mar 2001
13//
14// author: Thorsten Glebe
15// HERA-B Collaboration
16// Max-Planck-Institut fuer Kernphysik
17// Saupfercheckweg 1
18// 69117 Heidelberg
19// Germany
20// E-mail: T.Glebe@mpi-hd.mpg.de
21//
22// Description: A fixed size Vector class
23//
24// changes:
25// 16 Mar 2001 (TG) creation
26// 21 Mar 2001 (TG) SVector::value_type added
27// 21 Mar 2001 (TG) added operators +=, -=, *=, /=
28// 26 Mar 2001 (TG) added place_at()
29// 03 Apr 2001 (TG) Array() added
30// 06 Apr 2001 (TG) CTORS added
31// 07 Apr 2001 (TG) CTORS added
32// 22 Aug 2001 (TG) CTOR(T*,len) added
33// 04 Sep 2001 (TG) moved inlined functions to .icc file
34// 14 Jan 2002 (TG) added operator==(), operator!=(), operator>(), operator<()
35//
36********************************************************************/
37
38#include "Math/MConfig.h"
39
40#include <iosfwd>
41
42// expression engine
43
44#include "Math/Expression.h"
45
46
47
48
49namespace ROOT {
50
51namespace Math {
52
53// template <class T, unsigned int D, unsigned int D2> class MatRepStd;
54
55// template <class A, class T, unsigned int D, unsigned int D2 = 1, class R = MatRepStd<T,D,D2> > class Expr;
56
57//____________________________________________________________________________________________________________
58/**
59 SVector: a generic fixed size Vector class.
60 The class is template on the scalar type and on the vector size D.
61 See \ref SVectorDoc
62
63 Original author is Thorsten Glebe
64 HERA-B Collaboration, MPI Heidelberg (Germany)
65
66 @ingroup SMatrixSVector
67
68 @authors T. Glebe, L. Moneta and J. Palacios
69
70*/
71//==============================================================================
72// SVector
73//==============================================================================
74template <class T, unsigned int D>
75class SVector {
76public:
77 /** @name --- Typedefs --- */
78 /// contained scalar type
79 typedef T value_type;
80
81 /** STL iterator interface. */
82 typedef T* iterator;
83
84 /** STL const_iterator interface. */
85 typedef const T* const_iterator;
86
87
88 /** @name --- Constructors --- */
89 /**
90 Default constructor: vector filled with zero values
91 */
92 SVector();
93 /// contruct from a vector expression
94 template <class A>
95 SVector(const VecExpr<A,T,D>& rhs);
96 /// copy contructor
97 SVector(const SVector<T,D>& rhs);
98
99 // new constructs using STL iterator interface
100 // skip - need to solve the ambiguities
101#ifdef LATER
102 /**
103 Constructor with STL iterator interface. The data will be copied into the vector
104 The iterator size must be equal to the vector size
105 */
106 template<class InputIterator>
107 explicit SVector(InputIterator begin, InputIterator end);
108
109 /**
110 Constructor with STL iterator interface. The data will be copied into the vector
111 The size must be <= vector size
112 */
113 template<class InputIterator>
114 explicit SVector(InputIterator begin, unsigned int size);
115
116#else
117 // if you use iterator this is not necessary
118
119 /// fill from array with len must be equal to D!
120 SVector( const T * a, unsigned int len);
121
122 /** fill from a SVector iterator of type T*
123 (for ambiguities iterator cannot be generic )
124 */
126
127#endif
128 /// construct a vector of size 1 from a single scalar value
129 explicit SVector(const T& a1);
130 /// construct a vector of size 2 from 2 scalar values
131 SVector(const T& a1, const T& a2);
132 /// construct a vector of size 3 from 3 scalar values
133 SVector(const T& a1, const T& a2, const T& a3);
134 /// construct a vector of size 4 from 4 scalar values
135 SVector(const T& a1, const T& a2, const T& a3, const T& a4);
136 /// construct a vector of size 5 from 5 scalar values
137 SVector(const T& a1, const T& a2, const T& a3, const T& a4,
138 const T& a5);
139 /// construct a vector of size 6 from 6 scalar values
140 SVector(const T& a1, const T& a2, const T& a3, const T& a4,
141 const T& a5, const T& a6);
142 /// construct a vector of size 7 from 7 scalar values
143 SVector(const T& a1, const T& a2, const T& a3, const T& a4,
144 const T& a5, const T& a6, const T& a7);
145 /// construct a vector of size 8 from 8 scalar values
146 SVector(const T& a1, const T& a2, const T& a3, const T& a4,
147 const T& a5, const T& a6, const T& a7, const T& a8);
148 /// construct a vector of size 9 from 9 scalar values
149 SVector(const T& a1, const T& a2, const T& a3, const T& a4,
150 const T& a5, const T& a6, const T& a7, const T& a8,
151 const T& a9);
152 /// construct a vector of size 10 from 10 scalar values
153 SVector(const T& a1, const T& a2, const T& a3, const T& a4,
154 const T& a5, const T& a6, const T& a7, const T& a8,
155 const T& a9, const T& a10);
156
157
158
159 /// assignment from a scalar (only for size 1 vector)
160 SVector<T,D>& operator=(const T& a1);
161 /// assignment from another vector
163 /// assignment from Vector Expression
164 template <class A>
166
167 /** @name --- Access functions --- */
168
169 /**
170 Enumeration defining the Vector size
171 */
172 enum {
173 /// return vector size
174 kSize = D
175 };
176
177
178 /// return dimension $D$
179 inline static unsigned int Dim() { return D; }
180 /// access the parse tree. Index starts from zero
181 T apply(unsigned int i) const;
182 /// return read-only pointer to internal array
183 const T* Array() const;
184 /// return non-const pointer to internal array
185 T* Array();
186
187 /** @name --- STL-like interface --- */
188
189
190 /** STL iterator interface. */
191 iterator begin();
192
193 /** STL iterator interface. */
194 iterator end();
195
196 /** STL const_iterator interface. */
197 const_iterator begin() const;
198
199 /** STL const_iterator interface. */
200 const_iterator end() const;
201
202 /// set vector elements copying the values
203 /// iterator size must match vector size
204 template<class InputIterator>
205 void SetElements(InputIterator begin, InputIterator end);
206
207 /// set vector elements copying the values
208 /// size must be <= vector size
209 template<class InputIterator>
210 void SetElements(InputIterator begin, unsigned int size);
211
212
213 /** @name --- Operators --- */
214
215 /// element wise comparison
216 bool operator==(const T& rhs) const;
217 /// element wise comparison
218 bool operator!=(const T& rhs) const;
219 /// element wise comparison
220 bool operator==(const SVector<T,D>& rhs) const;
221 /// element wise comparison
222 bool operator!=(const SVector<T,D>& rhs) const;
223 /// element wise comparison
224 template <class A>
225 bool operator==(const VecExpr<A,T,D>& rhs) const;
226 /// element wise comparison
227 template <class A>
228 bool operator!=(const VecExpr<A,T,D>& rhs) const;
229
230 /// element wise comparison
231 bool operator>(const T& rhs) const;
232 /// element wise comparison
233 bool operator<(const T& rhs) const;
234 /// element wise comparison
235 bool operator>(const SVector<T,D>& rhs) const;
236 /// element wise comparison
237 bool operator<(const SVector<T,D>& rhs) const;
238 /// element wise comparison
239 template <class A>
240 bool operator>(const VecExpr<A,T,D>& rhs) const;
241 /// element wise comparison
242 template <class A>
243 bool operator<(const VecExpr<A,T,D>& rhs) const;
244
245 /// read-only access of vector elements. Index starts from 0.
246 const T& operator[](unsigned int i) const;
247 /// read-only access of vector elements. Index starts from 0.
248 const T& operator()(unsigned int i) const;
249 /// read-only access of vector elements with check on index. Index starts from 0.
250 const T& At(unsigned int i) const;
251 /// read/write access of vector elements. Index starts from 0.
252 T& operator[](unsigned int i);
253 /// read/write access of vector elements. Index starts from 0.
254 T& operator()(unsigned int i);
255 /// read/write access of vector elements with check on index. Index starts from 0.
256 T& At(unsigned int i);
257
258 /// self addition with a scalar
259 SVector<T,D>& operator+=(const T& rhs);
260 /// self subtraction with a scalar
261 SVector<T,D>& operator-=(const T& rhs);
262 /// self multiplication with a scalar
263 SVector<T,D>& operator*=(const T& rhs);
264 /// self division with a scalar
265 SVector<T,D>& operator/=(const T& rhs);
266
267
268 /// self addition with another vector
270 /// self subtraction with another vector
272 /// self addition with a vector expression
273 template <class A>
275 /// self subtraction with a vector expression
276 template <class A>
278
279
280#ifdef OLD_IMPL
281#ifndef __CINT__
282 /// self element-wise multiplication with another vector
284 /// self element-wise division with another vector
286
287 /// self element-wise multiplication with a vector expression
288 template <class A>
290 /// self element-wise division with a vector expression
291 template <class A>
293
294#endif
295#endif
296
297 /** @name --- Expert functions --- */
298 /// transform vector into a vector of length 1
300 /// place a sub-vector starting from the given position
301 template <unsigned int D2>
302 SVector<T,D>& Place_at(const SVector<T,D2>& rhs, unsigned int row);
303 /// place a sub-vector expression starting from the given position
304 template <class A, unsigned int D2>
305 SVector<T,D>& Place_at(const VecExpr<A,T,D2>& rhs, unsigned int row);
306
307 /**
308 return a subvector of size N starting at the value row
309 where N is the size of the returned vector (SubVector::kSize)
310 Condition row+N <= D
311 */
312 template <class SubVector >
313 SubVector Sub(unsigned int row) const;
314
315
316 /**
317 Function to check if a vector is sharing same memory location of the passed pointer
318 This function is used by the expression templates to avoid the alias problem during
319 expression evaluation. When the vector is in use, for example in operations
320 like V = M * V, where M is a mtrix, a temporary object storing the intermediate result is automatically
321 created when evaluating the expression.
322
323 */
324 bool IsInUse(const T* p) const;
325
326
327 /// used by operator<<()
328 std::ostream& Print(std::ostream& os) const;
329
330private:
331
332 /** @name --- Data member --- */
333
334 /// SVector data
336}; // end of class SVector
337
338
339//==============================================================================
340// operator<<
341//==============================================================================
342template <class T, unsigned int D>
343std::ostream& operator<<(std::ostream& os, const ROOT::Math::SVector<T,D>& rhs);
344
345
346
347} // namespace Math
348
349} // namespace ROOT
350
351
352
353#ifndef __CINT__
354
355// include implementation file
356#include "Math/SVector.icc"
357
358// include operators and functions
359#include "Math/UnaryOperators.h"
360#include "Math/BinaryOperators.h"
361#include "Math/Functions.h"
362
363#endif // __CINT__
364
365
366#endif /* ROOT_Math_SVector */
SVector: a generic fixed size Vector class.
Definition: SVector.h:75
const T * const_iterator
STL const_iterator interface.
Definition: SVector.h:85
SVector< T, D > & operator=(const T &a1)
assignment from a scalar (only for size 1 vector)
Definition: SVector.icc:194
T * iterator
STL iterator interface.
Definition: SVector.h:82
bool operator>(const T &rhs) const
element wise comparison
Definition: SVector.icc:283
SVector< T, D > & Place_at(const SVector< T, D2 > &rhs, unsigned int row)
place a sub-vector starting from the given position
Definition: SVector.icc:493
iterator begin()
STL iterator interface.
Definition: SVector.icc:553
static unsigned int Dim()
return dimension $D$
Definition: SVector.h:179
SVector< T, D > & operator*=(const T &rhs)
self multiplication with a scalar
Definition: SVector.icc:431
SVector< T, D > & Unit()
transform vector into a vector of length 1
Definition: SVector.icc:480
SubVector Sub(unsigned int row) const
return a subvector of size N starting at the value row where N is the size of the returned vector (Su...
Definition: SVector.icc:615
const T * Array() const
return read-only pointer to internal array
Definition: SVector.icc:543
T apply(unsigned int i) const
access the parse tree. Index starts from zero
Definition: SVector.icc:540
@ kSize
return vector size
Definition: SVector.h:174
T value_type
contained scalar type
Definition: SVector.h:79
const T & At(unsigned int i) const
read-only access of vector elements with check on index. Index starts from 0.
Definition: SVector.icc:599
bool operator!=(const T &rhs) const
element wise comparison
Definition: SVector.icc:264
SVector()
Default constructor: vector filled with zero values.
Definition: SVector.icc:53
const T & operator()(unsigned int i) const
read-only access of vector elements. Index starts from 0.
Definition: SVector.icc:588
SVector< T, D > & operator-=(const T &rhs)
self subtraction with a scalar
Definition: SVector.icc:403
bool IsInUse(const T *p) const
Function to check if a vector is sharing same memory location of the passed pointer This function is ...
Definition: SVector.icc:631
bool operator<(const T &rhs) const
element wise comparison
Definition: SVector.icc:314
const T & operator[](unsigned int i) const
read-only access of vector elements. Index starts from 0.
Definition: SVector.icc:585
SVector< T, D > & operator+=(const T &rhs)
self addition with a scalar
Definition: SVector.icc:374
bool operator==(const T &rhs) const
element wise comparison
Definition: SVector.icc:233
SVector< T, D > & operator/=(const T &rhs)
self division with a scalar
Definition: SVector.icc:468
T fArray[D]
SVector data.
Definition: SVector.h:335
std::ostream & Print(std::ostream &os) const
used by operator<<()
Definition: SVector.icc:524
iterator end()
STL iterator interface.
Definition: SVector.icc:559
void SetElements(InputIterator begin, InputIterator end)
set vector elements copying the values iterator size must match vector size
Definition: SVector.icc:566
Expression wrapper class for Vector objects.
Definition: Expression.h:64
Namespace for new Math classes and functions.
double T(double x)
Definition: ChebyshevPol.h:34
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12