ROOTPWA
testArray.cc
Go to the documentation of this file.
1 //
2 // tests matrix implementation using vector of vector
3 // run using:
4 // g++ -Wall testArray.cxx -o testArray && ./testArray
5 //
6 
7 
8 #include <iostream>
9 #include <complex>
10 
11 #include "boost/multi_array.hpp"
12 
13 #include "arrayUtils.hpp"
14 #include "reportingUtils.hpp"
15 
16 
17 using namespace std;
18 using namespace boost;
19 using namespace rpwa;
20 
21 
22 int main(int argc, char** argv)
23 {
24  double a[2][3][4];
25  for (unsigned int i = 0; i < 2; ++i)
26  for (unsigned int j = 0; j < 3; ++j)
27  for (unsigned int k = 0; k < 4; ++k)
28  a[i][j][k] = i * 100 + j * 10 + k;
29 
30  if (0) {
31 
32  double*** x = 0;
33  const unsigned int dim[3] = {2, 3, 4};
34  allocate3DArray(x, dim);
35  for (unsigned int i = 0; i < 2; ++i)
36  for (unsigned int j = 0; j < 3; ++j)
37  for (unsigned int k = 0; k < 4; ++k)
38  x[i][j][k] = i * 100 + j * 10 + k;
39 
40  for (unsigned int i = 0; i < 2; ++i)
41  for (unsigned int j = 0; j < 3; ++j)
42  for (unsigned int k = 0; k < 4; ++k) {
43  if (a[i][j][k] != a[i][j][k])
44  cout << "ERROR!" << endl;
45  cout << "x[" << i << "][" << j << "][" << k << "] = " << x[i][j][k] << " vs. "
46  << "a[" << i << "][" << j << "][" << k << "] = " << a[i][j][k] << endl;
47  }
48 
49  delete3DArray(x, dim);
50 
51  }
52 
53 
54  if (0) {
55 
56  double* x = 0;
57  const unsigned int dim[3] = {2, 3, 4};
58  const unsigned int nmbDim = 3;
59  allocatePseudoNdimArray(x, dim, nmbDim);
60  for (unsigned int i = 0; i < 2; ++i)
61  for (unsigned int j = 0; j < 3; ++j)
62  for (unsigned int k = 0; k < 4; ++k) {
63  const unsigned int indices[3] = {i, j, k};
64  const unsigned int offset = indicesToOffset(indices, dim, nmbDim);
65  x[offset] = i * 100 + j * 10 + k;
66  }
67 
68  double* y = (double*)a;
69  for (unsigned int i = 0; i < 2; ++i)
70  for (unsigned int j = 0; j < 3; ++j)
71  for (unsigned int k = 0; k < 4; ++k) {
72  const unsigned int indices[3] = {i, j, k};
73  const unsigned int offset = indicesToOffset(indices, dim, nmbDim);
74  if (x[offset] != a[i][j][k])
75  cout << "ERROR!" << endl;
76  cout << "x[" << offset << "] = " << x[offset] << " vs. "
77  << "a[" << i << "][" << j << "][" << k << "] = " << a[i][j][k] << endl;
78  if (x[offset] != y[offset])
79  cout << "ERROR!" << endl;
80  cout << "x[" << offset << "] = " << x[offset] << " vs. "
81  << "y[" << offset << "] = " << y[offset] << endl;
82  unsigned int testIndices[3];
83  offsetToIndices(offset, dim, nmbDim, testIndices);
84  cout << " indices {";
85  for (unsigned int d = 0; d < nmbDim; ++d) {
86  if (testIndices[d] != indices[d])
87  cout << "ERROR! ";
88  cout << testIndices[d] << " ";
89  }
90  cout << "} vs. {" << i << " " << j << " " << k << "}" << endl;
91  }
92 
93  delete[] x;
94  }
95 
96  if (1) {
97 
98  const unsigned int dim[3] = {1000, 300, 400};
99  // double a[dim[0]][dim[1]][dim[2]];
100  double*** x = 0;
101  allocate3DArray(x, dim);
102  double* y = 0;
103  const unsigned int nmbDim = 3;
104  allocatePseudoNdimArray(y, dim, nmbDim);
105  multi_array<double, 3> z(extents[dim[0]][dim[1]][dim[2]]);
106 
107  for (unsigned int i = 0; i < dim[0]; ++i)
108  for (unsigned int j = 0; j < dim[1]; ++j)
109  for (unsigned int k = 0; k < dim[2]; ++k) {
110  const unsigned int indices[3] = {i, j, k};
111  const unsigned int offset = indicesToOffset(indices, dim, nmbDim);
112  // if (a[i][j][k] != 0)
113  // cout << "a ";
114  if (x[i][j][k] != 0)
115  cout << "x ";
116  if (y[offset] != 0)
117  cout << "y ";
118  if (z[i][j][k] != 0)
119  cout << "z ";
120  }
121  cout << endl;
122  }
123 
124  return 0;
125 }