ROOT  6.06/09
Reference Guide
matrix_util.h
Go to the documentation of this file.
1 #ifndef MATRIX_UTIL_H
2 #define MATRIX_UTIL_H
3 
4 // utility functions to fill with random data
5 
6 #ifndef USE_VC
7 
8 template<class V>
9 void fillRandomVec(TRandom & r, V & v, unsigned int len, unsigned int start = 0, double offset = 1) {
10  for(unsigned int i = start; i < len+start; ++i)
11  v[i] = r.Rndm() + offset;
12 }
13 
14 template<class M>
15 void fillRandomMat(TRandom & r, M & m, unsigned int first, unsigned int second, unsigned int start = 0, double offset = 1) {
16  for(unsigned int i = start; i < first+start; ++i)
17  for(unsigned int j = start; j < second+start; ++j)
18  m(i,j) = r.Rndm() + offset;
19 }
20 
21 template<class M>
22 void fillRandomSym(TRandom & r, M & m, unsigned int first, unsigned int start = 0, double offset = 1) {
23  for(unsigned int i = start; i < first+start; ++i) {
24  for(unsigned int j = i; j < first+start; ++j) {
25  if ( i != j ) {
26  m(i,j) = r.Rndm() + offset;
27  m(j,i) = m(i,j);
28  }
29  else // add extra offset to make no singular when inverting
30  m(i,i) = r.Rndm() + 3*offset;
31  }
32  }
33 }
34 
35 #else
36 
37 // case of Vc
38 template<class V>
39 void fillRandomVec(TRandom & r, V & v, unsigned int len, unsigned int start = 0, double offset = 1) {
40  for (int k = 0; k < Vc::double_v::Size; ++k) {
41  for(unsigned int i = start; i < len+start; ++i) {
42  typename V::value_type x = v[i];
43  x[k] = r.Rndm() + offset;
44  v[i] = x;
45  }
46  }
47 }
48 
49 template<class M>
50 void fillRandomMat(TRandom & r, M & m, unsigned int first, unsigned int second, unsigned int start = 0, double offset = 1) {
51  for (int k = 0; k < Vc::double_v::Size; ++k) {
52  for(unsigned int i = start; i < first+start; ++i) {
53  for(unsigned int j = start; j < second+start; ++j) {
54  typename M::value_type x = m(i,j);
55  x[k] = r.Rndm() + offset;
56  m(i,j) = x;
57  }
58  }
59  }
60 }
61 
62 template<class M>
63 void fillRandomSym(TRandom & r, M & m, unsigned int first, unsigned int start = 0, double offset = 1) {
64  for (int k = 0; k < Vc::double_v::Size; ++k) {
65  for(unsigned int i = start; i < first+start; ++i) {
66  for(unsigned int j = i; j < first+start; ++j) {
67  typename M::value_type x = m(i,j);
68  if ( i != j ) {
69  x[k] = r.Rndm() + offset;
70  m(i,j) = x;
71  m(j,i) = m(i,j);
72  }
73  else {// add extra offset to make no singular when inverting
74  x[k] = r.Rndm() + 3*offset;
75  m(i,i) = x;
76  }
77  }
78  }
79  }
80 }
81 #endif
82 
83 #endif
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
const char * Size
Definition: TXMLSetup.cxx:56
void fillRandomVec(TRandom &r, V &v, unsigned int len, unsigned int start=0, double offset=1)
Definition: matrix_util.h:7
void fillRandomSym(TRandom &r, M &m, unsigned int first, unsigned int start=0, double offset=1)
Definition: matrix_util.h:20
Double_t x[n]
Definition: legend1.C:17
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:29
TMarker * m
Definition: textangle.C:8
void fillRandomMat(TRandom &r, M &m, unsigned int first, unsigned int second, unsigned int start=0, double offset=1)
Definition: matrix_util.h:13