• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2002 The Trustees of Indiana University.
2 
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 //  Boost.MultiArray Library
8 //  Authors: Ronald Garcia
9 //           Jeremy Siek
10 //           Andrew Lumsdaine
11 //  See http://www.boost.org/libs/multi_array for documentation.
12 
13 
14 
15 #include <boost/multi_array.hpp>
16 
17 #include <boost/core/lightweight_test.hpp>
18 
19 #include <algorithm>
20 #include <list>
21 
22 
23 int
main()24 main()
25 {
26   typedef boost::multi_array<double, 3> array;
27   typedef array::size_type size_type;
28   boost::array<size_type,3> sizes = { { 3, 3, 3 } };
29   const size_type num_elements = 27;
30 
31   // Copy Constructor
32   {
33     array A(sizes);
34     std::vector<double> vals(num_elements, 4.5);
35     A.assign(vals.begin(),vals.end());
36     array B(A);
37     BOOST_TEST(A == B);
38     BOOST_TEST(B == A);
39     BOOST_TEST(A[0] == B[0]);
40   }
41   // Assignment Operator
42   {
43     array A(sizes), B(sizes);
44     std::vector<double> vals(num_elements, 4.5);
45     A.assign(vals.begin(),vals.end());
46     B = A;
47     BOOST_TEST(A == B);
48     BOOST_TEST(B == A);
49     BOOST_TEST(B[0] == A[0]);
50 
51     typedef array::index_range range;
52     array::index_gen indices;
53     array::array_view<2>::type C = A[indices[2][range()][range()]];
54     array::array_view<2>::type D = B[indices[2][range()][range()]];
55     BOOST_TEST(C == D);
56   }
57   // Different Arrays
58   {
59     array A(sizes), B(sizes);
60     std::vector<double> valsA(num_elements, 4.5);
61     std::vector<double> valsB(num_elements, 2.5);
62     A.assign(valsA.begin(),valsA.end());
63     B.assign(valsB.begin(),valsB.end());
64 
65     BOOST_TEST(A != B);
66     BOOST_TEST(B != A);
67     BOOST_TEST(A[0] != B[0]);
68 
69     typedef array::index_range range;
70     array::index_gen indices;
71     array::array_view<2>::type C = A[indices[2][range()][range()]];
72     array::array_view<2>::type D = B[indices[2][range()][range()]];
73     BOOST_TEST(C != D);
74   }
75 
76   // Comparisons galore!
77   {
78     array A(sizes), B(sizes);
79 
80     double valsA[] = {
81         0, 0, 0,
82         0, 0, 0,
83         0, 0, 0,
84 
85         1, 1, 1,
86         1, 1, 1,
87         1, 1, 1,
88 
89         2, 2, 2,
90         2, 2, 2,
91         2, 2, 2
92     };
93 
94     double valsB[] = {
95         0, 0, 0,
96         0, 0, 0,
97         0, 0, 0,
98 
99         1, 1, 1,
100         1, 1, 1,
101         1, 1, 1,
102 
103         2, 2, 2,
104         2, 2, 2,
105         2, 2, 1
106     };
107 
108     A.assign(valsA,valsA+num_elements);
109     B.assign(valsB,valsB+num_elements);
110 
111     BOOST_TEST(B < A);
112     BOOST_TEST(A > B);
113 
114     BOOST_TEST(B <= A);
115     BOOST_TEST(A >= B);
116 
117     BOOST_TEST(B[0] == A[0]);
118     BOOST_TEST(B[2] < A[2]);
119 
120     array C = A;
121 
122     BOOST_TEST(C <= A);
123     BOOST_TEST(C >= A);
124 
125     BOOST_TEST(!(C < A));
126     BOOST_TEST(!(C > A));
127 
128     typedef array::index_range range;
129     array::index_gen indices;
130     array::array_view<2>::type D = A[indices[2][range()][range()]];
131     array::array_view<2>::type E = B[indices[2][range()][range()]];
132 
133     BOOST_TEST(E < D);
134     BOOST_TEST(E <= D);
135   }
136 
137 
138 
139   return boost::report_errors();
140 }
141 
142 
143