Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
math/smatrix/doc/SVector.md
Go to the documentation of this file.
1 \page SVectorDoc SVector Class Properties
2 
3 The template ROOT::Math::SVector class has 2 template parameters which define, at compile time, its properties. These are:
4 
5 * type of the contained elements, for example _float_ or double.
6 * size of the vector.
7 
8 ### Creating a Vector
9 
10 The following constructors are available to create a vector:
11 
12 * Default constructor for a zero vector (all elements equal to zero)
13 * Constructor (and assignment) from a vector expression, like v = p*q + w. Due to the expression template technique, no temporary objects are created in this operation.
14 * Construct a vector passing directly the elements. This is possible only for vector up to size 10\.
15 * Constructor from an iterator copying the data refered by the iterator. It is possible to specify the _begin_ and _end_ of the iterator or the _begin_ and the size. Note that for the Vector the iterator is not generic and must be of type _T*,_ where T is the type of the contained elements.
16 
17 Here are some examples on how to create a vector. In the following we assume that we are using the namespace ROOT::Math.
18 
19 ~~~ {.cpp}
20 SVector>double,N> v; _// create a vector of size N, v[i]=0_
21 SVector>double,3> v(1,2,3); _// create a vector of size 3, v[0]=1,v[1]=2,v[2]=3_
22 double a[9] = {1,2,3,4,5,6,7,8,9}; _// input data_
23 SVector>double,9> v(a,9); _// create a vector using the a[] data_
24 ~~~
25 
26 
27 ### Accessing and Setting Methods
28 
29 The single vector elements can be set or retrieved using the _operator[i]_ , _operator(i)_ or the iterator interface. Notice that the index starts from zero and not from one as in FORTRAN. Also no check is performed on the passed index. Furthermore, all the matrix elements can be set also by using the ROOT::SVector::SetElements function passing a generic iterator. The elements can be accessed also by using the ROOT::Math::SVector::apply(i) function.
30 
31 ~~~ {.cpp}
32 v[0] = 1; _ // set the first element _
33 v(1) = 2; _ // set the second element _
34 *(v.**begin**()+3) = 3; _// set the third element_
35 _// set vector elements from a std::vector<double>::iterator</double>_
36 std::vector <double>w(3);
37 v.SetElements(w.begin(),w.end());
38 
39 double x = m(i); _// return the i-th element_
40 x = m.**apply**(i); _// return the i-th element_
41 x = *(m.**begin**()+i); _// return the i-th element
42 ~~~
43 
44 
45 In addition there are methods to place a sub-vector in a vector. If the size of the the sub-vector is larger than the vector size a static assert ( a compilation error) is produced.
46 
47 ~~~ {.cpp}
48 SVector>double,N> v;
49 SVector>double,M> w; _// M <= N otherwise a compilation error is obtained later _
50 _// place a vector of size M starting from element ioff, v[ioff + i] = w[i]_
51 v.**Place_at**(w,ioff);
52 _// return a sub-vector of size M starting from v[ioff]: w[i] = v[ioff + i]_
53 w = v.Sub < SVector>double,M> > (ioff);
54 ~~~
55 
56 
57 For additional Vector functionality see the \ref MatVecFunctions page
double T(double x)
Definition: ChebyshevPol.h:34
bool equal(double d1, double d2, double stol=10000)
#define N
TString as(SEXP s)
Definition: RExports.h:71
TArc * a
Definition: textangle.C:12
Double_t x[n]
Definition: legend1.C:17
void Class()
Definition: Class.C:29
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:146
void example()
Definition: example.C:26
SVector< double, 2 > v
Definition: Dict.h:5
TMarker * m
Definition: textangle.C:8
#define _(A, B)
Definition: cfortran.h:108
int type
Definition: TGX11.cxx:120
TCppObject_t Construct(TCppType_t type)
Definition: Cppyy.cxx:265
float * q
Definition: THbookFile.cxx:87
decltype(auto) constexpr apply(F &&f, Tuple &&t)
SVector: a generic fixed size Vector class.