]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multi_array/test/reshape.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 // reshape.cpp - testing reshaping functionality
17 #include <boost/multi_array.hpp>
19 #include <boost/core/lightweight_test.hpp>
21 #include <boost/array.hpp>
22 #include <boost/type.hpp>
28 typedef boost::multi_array
<int,ndims
> array
;
29 typedef boost::multi_array_ref
<int,ndims
> array_ref
;
30 typedef boost::const_multi_array_ref
<int,ndims
> const_array_ref
;
32 boost::array
<array::size_type
,ndims
> dims
= {{2,3,4}};
33 boost::array
<array::size_type
,ndims
> new_dims
= {{4,3,2}};
35 int data
[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
36 14,15,16,17,18,19,20,21,22,23};
37 const int data_size
=24;
42 A
.assign(data
,data
+data_size
);
44 array_ref
B(data
,dims
);
45 const_array_ref
C(data
,dims
);
52 for (array::index i
= 0; i
!= 4; ++i
)
53 for (array::index j
= 0; j
!= 3; ++j
)
54 for (array::index k
= 0; k
!= 2; ++k
) {
55 BOOST_TEST(A
[i
][j
][k
] == *ptr
);
56 BOOST_TEST(B
[i
][j
][k
] == *ptr
);
57 BOOST_TEST(C
[i
][j
][k
] == *ptr
++);
61 // Ensure that index bases are preserved over reshape
63 boost::array
<array::index
,ndims
> bases
= {{0, 1, -1}};
66 A
.assign(data
,data
+data_size
);
68 array_ref
B(data
,dims
);
69 const_array_ref
C(data
,dims
);
80 for (array::index i
= 0; i
!= 4; ++i
)
81 for (array::index j
= 1; j
!= 4; ++j
)
82 for (array::index k
= -1; k
!= 1; ++k
) {
83 BOOST_TEST(A
[i
][j
][k
] == *ptr
);
84 BOOST_TEST(B
[i
][j
][k
] == *ptr
);
85 BOOST_TEST(C
[i
][j
][k
] == *ptr
++);
89 return boost::report_errors();