test_boost_multi_array.cxx
Go to the documentation of this file.
1 #include "WireCellUtil/Testing.h"
2 
3 #include <boost/multi_array.hpp>
4 
5 #include <iostream>
6 
7 using namespace std;
8 
9 int main()
10 {
11  typedef boost::multi_array<double, 2> array_type;
12  typedef array_type::index index;
13 
14  size_t l_size = 10;
15  size_t t_size = 3;
16  array_type ar(boost::extents[l_size][t_size]);
17  cerr << "Dimensions: " << ar.dimensionality << endl;
18  cerr << "Dimension 0 is size " << ar.shape()[0] << endl;
19  cerr << "Dimension 1 is size " << ar.shape()[1] << endl;
20 
21  Assert(l_size == ar.shape()[0]);
22  Assert(t_size == ar.shape()[1]);
23  for (size_t l_ind=0; l_ind < l_size; ++l_ind) {
24  for (size_t t_ind=0; t_ind < t_size; ++t_ind) {
25  ar[l_ind][t_ind] = l_ind*t_ind;
26  }
27  }
28  for (size_t t_ind=0; t_ind < t_size; ++t_ind) {
29  for (size_t l_ind=0; l_ind < l_size; ++l_ind) {
30  cerr << "\t[" << l_ind<< "][" << t_ind << "] = " << ar[l_ind][t_ind];
31  }
32  cerr << endl;
33  }
34 
35  array_type ar2(boost::extents[l_size][t_size]);
36  ar2 = ar;
37  Assert(l_size == ar2.shape()[0]);
38  Assert(t_size == ar2.shape()[1]);
39 
40  array_type ar3 = ar;
41  Assert(l_size == ar3.shape()[0]);
42  Assert(t_size == ar3.shape()[1]);
43 
44 
45  int nx=3, ny=4, nz=5;
46 
47  typedef boost::multi_array<double, 3> array_type3;
48 
49  array_type3 B(boost::extents[nx][ny][nz]);
50  typedef array_type3::index index3;
51  for (index3 i=0; i<nx; ++i) {
52  for (index3 j=0; j<ny; ++j) {
53  for (index3 k=0; k<nz; ++k) {
54  const double foo = i*j*k;
55 
56  B[i][j][k] = foo;
57  }
58  }
59  }
60 
61  return 0;
62 }
char foo(size_t ind)
STL namespace.
#define Assert
Definition: Testing.h:7
int main()
QTextStream & endl(QTextStream &s)