ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
scalaraccess.cpp
Go to the documentation of this file.
1 /* This file is part of the Vc library.
2 
3  Copyright (C) 2010-2012 Matthias Kretz <kretz@kde.org>
4 
5  Vc is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as
7  published by the Free Software Foundation, either version 3 of
8  the License, or (at your option) any later version.
9 
10  Vc is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with Vc. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #include "unittest.h"
21 
22 using namespace Vc;
23 
24 template<typename V> void reads()
25 {
26  typedef typename V::EntryType T;
27  typedef typename V::IndexType I;
28 
29  V a = V::Zero();
30  const T zero = 0;
31  for (int i = 0; i < V::Size; ++i) {
32  const T x = a[i];
33  COMPARE(x, zero);
34  }
35  a = static_cast<V>(I::IndexesFromZero());
36  for (int i = 0; i < V::Size; ++i) {
37  const T x = a[i];
38  const T y = i;
39  COMPARE(x, y);
40  }
41 }
42 
43 template<typename V, size_t Index>
45 {
46  typedef typename V::EntryType T;
47  {
48  const T x = a[Index];
49  const T zero = 0;
50  COMPARE(x, zero) << Index;
51  }{
52  const T x = b[Index];
53  const T y = Index;
54  COMPARE(x, y) << Index;
55  }
56 }
57 
58 template<typename V, size_t Index>
59 struct ReadsConstantIndex
60 {
61  ReadsConstantIndex(VC_ALIGNED_PARAMETER(V) a, VC_ALIGNED_PARAMETER(V) b)
62  {
63  readsConstantIndexTest<V, Index>(a, b);
64  ReadsConstantIndex<V, Index - 1>(a, b);
65  }
66 };
67 
68 
69 template<typename V>
70 struct ReadsConstantIndex<V, 0>
71 {
72  ReadsConstantIndex(VC_ALIGNED_PARAMETER(V) a, VC_ALIGNED_PARAMETER(V) b)
73  {
74  readsConstantIndexTest<V, 0>(a, b);
75  }
76 };
77 
78 template<typename V> void readsConstantIndex()
79 {
80  typedef typename V::IndexType I;
81 
82  V a = V::Zero();
83  V b = static_cast<V>(I::IndexesFromZero());
84  ReadsConstantIndex<V, V::Size - 1>(a, b);
85 }
86 
87 template<typename V> void writes()
88 {
89  typedef typename V::EntryType T;
90  typedef typename V::IndexType I;
91 
92  V a;
93  for (int i = 0; i < V::Size; ++i) {
94  a[i] = static_cast<T>(i);
95  }
96  V b = static_cast<V>(I::IndexesFromZero());
97  COMPARE(a, b);
98 
99  const T one = 1;
100  const T two = 2;
101 
102  if (V::Size == 1) {
103  a(a == 0) += one;
104  a[0] += one;
105  a(a == 0) += one;
106  COMPARE(a, V(2));
107  } else if (V::Size == 4) {
108  a(a == 1) += two;
109  a[2] += one;
110  a(a == 3) += one;
111  b(b == 1) += one;
112  b(b == 2) += one;
113  b(b == 3) += one;
114  COMPARE(a, b);
115  } else if (V::Size == 8 || V::Size == 16) {
116  a(a == 2) += two;
117  a[3] += one;
118  a(a == 4) += one;
119  b(b == 2) += one;
120  b(b == 3) += one;
121  b(b == 4) += one;
122  COMPARE(a, b);
123  } else if (V::Size == 2) { // a = [0, 1]; b = [0, 1]
124  a(a == 0) += two; // a = [2, 1]
125  a[1] += one; // a = [2, 2]
126  a(a == 2) += one; // a = [3, 3]
127  b(b == 0) += one; // b = [1, 1]
128  b(b == 1) += one; // b = [2, 2]
129  b(b == 2) += one; // b = [3, 3]
130  COMPARE(a, b);
131  } else {
132  FAIL() << "unsupported Vector::Size";
133  }
134 }
135 
136 int main(int argc, char **argv)
137 {
138  initTest(argc, argv);
139 
143  //testAllTypes(writesConstantIndex);
144 
145  return 0;
146 }
void initTest(int argc, char **argv)
Definition: unittest.h:169
const char * Size
Definition: TXMLSetup.cxx:56
TArc * a
Definition: textangle.C:12
void writes()
void readsConstantIndex()
TTree * T
Double_t x[n]
Definition: legend1.C:17
#define COMPARE(a, b)
Definition: unittest.h:509
void readsConstantIndexTest(VC_ALIGNED_PARAMETER(V) a, VC_ALIGNED_PARAMETER(V) b)
#define testAllTypes(name)
Definition: unittest.h:43
#define VC_ALIGNED_PARAMETER(_Type)
Definition: macros.h:368
RooCmdArg Index(RooCategory &icat)
#define FAIL()
Definition: unittest.h:518
Double_t y[n]
Definition: legend1.C:17
void reads()
#define I(x, y, z)
int main(int argc, char **argv)