]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multi_array/test/storage_order.cpp
1 // Copyright 2002 The Trustees of Indiana University.
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)
7 // Boost.MultiArray Library
8 // Authors: Ronald Garcia
11 // See http://www.boost.org/libs/multi_array for documentation.
14 // storage_order.cpp - testing storage_order-isms.
17 #include <boost/multi_array.hpp>
19 #include <boost/core/lightweight_test.hpp>
21 #include <boost/array.hpp>
55 const int num_elements
= 24;
57 // fortran storage order
59 typedef boost::multi_array
<int,ndims
> array
;
61 array::extent_gen extents
;
62 array
A(extents
[2][3][4],boost::fortran_storage_order());
64 A
.assign(data_col
,data_col
+num_elements
);
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
++);
73 // Mimic fortran_storage_order using
74 // general_storage_order data placement
76 typedef boost::general_storage_order
<ndims
> storage
;
77 typedef boost::multi_array
<int,ndims
> array
;
79 array::size_type ordering
[] = {0,1,2};
80 bool ascending
[] = {true,true,true};
82 array::extent_gen extents
;
83 array
A(extents
[2][3][4], storage(ordering
,ascending
));
85 A
.assign(data_col
,data_col
+num_elements
);
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
++);
94 // general_storage_order with arbitrary storage order
96 typedef boost::general_storage_order
<ndims
> storage
;
97 typedef boost::multi_array
<int,ndims
> array
;
99 array::size_type ordering
[] = {2,0,1};
100 bool ascending
[] = {true,true,true};
102 array::extent_gen extents
;
103 array
A(extents
[2][3][4], storage(ordering
,ascending
));
116 A
.assign(data_arb
,data_arb
+num_elements
);
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
++);
126 // general_storage_order with descending dimensions.
129 typedef boost::general_storage_order
<ndims
> storage
;
130 typedef boost::multi_array
<int,ndims
> array
;
132 array::size_type ordering
[] = {2,0,1};
133 bool ascending
[] = {false,true,true};
135 array::extent_gen extents
;
136 array
A(extents
[2][3][4], storage(ordering
,ascending
));
149 A
.assign(data_arb
,data_arb
+num_elements
);
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
++);
158 return boost::report_errors();