]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multi_array/test/storage_order.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multi_array / test / storage_order.cpp
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 // storage_order.cpp - testing storage_order-isms.
15 //
16
17 #include <boost/multi_array.hpp>
18
19 #include <boost/core/lightweight_test.hpp>
20
21 #include <boost/array.hpp>
22
23 int
24 main()
25 {
26 const int ndims=3;
27
28 int data_row[] = {
29 0,1,2,3,
30 4,5,6,7,
31 8,9,10,11,
32
33 12,13,14,15,
34 16,17,18,19,
35 20,21,22,23
36 };
37
38 int data_col[] = {
39 0,12,
40 4,16,
41 8,20,
42
43 1,13,
44 5,17,
45 9,21,
46
47 2,14,
48 6,18,
49 10,22,
50
51 3,15,
52 7,19,
53 11,23
54 };
55 const int num_elements = 24;
56
57 // fortran storage order
58 {
59 typedef boost::multi_array<int,ndims> array;
60
61 array::extent_gen extents;
62 array A(extents[2][3][4],boost::fortran_storage_order());
63
64 A.assign(data_col,data_col+num_elements);
65
66 int* num = data_row;
67 for (array::index i = 0; i != 2; ++i)
68 for (array::index j = 0; j != 3; ++j)
69 for (array::index k = 0; k != 4; ++k)
70 BOOST_TEST(A[i][j][k] == *num++);
71 }
72
73 // Mimic fortran_storage_order using
74 // general_storage_order data placement
75 {
76 typedef boost::general_storage_order<ndims> storage;
77 typedef boost::multi_array<int,ndims> array;
78
79 array::size_type ordering[] = {0,1,2};
80 bool ascending[] = {true,true,true};
81
82 array::extent_gen extents;
83 array A(extents[2][3][4], storage(ordering,ascending));
84
85 A.assign(data_col,data_col+num_elements);
86
87 int* num = data_row;
88 for (array::index i = 0; i != 2; ++i)
89 for (array::index j = 0; j != 3; ++j)
90 for (array::index k = 0; k != 4; ++k)
91 BOOST_TEST(A[i][j][k] == *num++);
92 }
93
94 // general_storage_order with arbitrary storage order
95 {
96 typedef boost::general_storage_order<ndims> storage;
97 typedef boost::multi_array<int,ndims> array;
98
99 array::size_type ordering[] = {2,0,1};
100 bool ascending[] = {true,true,true};
101
102 array::extent_gen extents;
103 array A(extents[2][3][4], storage(ordering,ascending));
104
105 int data_arb[] = {
106 0,1,2,3,
107 12,13,14,15,
108
109 4,5,6,7,
110 16,17,18,19,
111
112 8,9,10,11,
113 20,21,22,23
114 };
115
116 A.assign(data_arb,data_arb+num_elements);
117
118 int* num = data_row;
119 for (array::index i = 0; i != 2; ++i)
120 for (array::index j = 0; j != 3; ++j)
121 for (array::index k = 0; k != 4; ++k)
122 BOOST_TEST(A[i][j][k] == *num++);
123 }
124
125
126 // general_storage_order with descending dimensions.
127 {
128 const int ndims=3;
129 typedef boost::general_storage_order<ndims> storage;
130 typedef boost::multi_array<int,ndims> array;
131
132 array::size_type ordering[] = {2,0,1};
133 bool ascending[] = {false,true,true};
134
135 array::extent_gen extents;
136 array A(extents[2][3][4], storage(ordering,ascending));
137
138 int data_arb[] = {
139 12,13,14,15,
140 0,1,2,3,
141
142 16,17,18,19,
143 4,5,6,7,
144
145 20,21,22,23,
146 8,9,10,11
147 };
148
149 A.assign(data_arb,data_arb+num_elements);
150
151 int* num = data_row;
152 for (array::index i = 0; i != 2; ++i)
153 for (array::index j = 0; j != 3; ++j)
154 for (array::index k = 0; k != 4; ++k)
155 BOOST_TEST(A[i][j][k] == *num++);
156 }
157
158 return boost::report_errors();
159 }