Update contrib.
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 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
20 #include "boost/multi_array.hpp"
22 #include "boost/test/minimal.hpp"
24 #include "boost/array.hpp"
25 #include "boost/type.hpp"
28 #include "std_log_result.h"
29 #define LOG_FILENAME_LINE __FILE__, __LINE__
32 test_main(int,char*[])
35 typedef boost::multi_array<int,ndims> array;
36 typedef boost::multi_array_ref<int,ndims> array_ref;
37 typedef boost::const_multi_array_ref<int,ndims> const_array_ref;
39 boost::array<array::size_type,ndims> dims = {{2,3,4}};
40 boost::array<array::size_type,ndims> new_dims = {{4,3,2}};
42 int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
43 14,15,16,17,18,19,20,21,22,23};
44 const int data_size=24;
49 A.assign(data,data+data_size);
51 array_ref B(data,dims);
52 const_array_ref C(data,dims);
59 for (array::index i = 0; i != 4; ++i)
60 for (array::index j = 0; j != 3; ++j)
61 for (array::index k = 0; k != 2; ++k) {
62 BOOST_CHECK(A[i][j][k] == *ptr);
63 BOOST_CHECK(B[i][j][k] == *ptr);
64 BOOST_CHECK(C[i][j][k] == *ptr++);
68 // Ensure that index bases are preserved over reshape
70 boost::array<array::index,ndims> bases = {{0, 1, -1}};
73 A.assign(data,data+data_size);
75 array_ref B(data,dims);
76 const_array_ref C(data,dims);
87 for (array::index i = 0; i != 4; ++i)
88 for (array::index j = 1; j != 4; ++j)
89 for (array::index k = -1; k != 1; ++k) {
90 BOOST_CHECK(A[i][j][k] == *ptr);
91 BOOST_CHECK(B[i][j][k] == *ptr);
92 BOOST_CHECK(C[i][j][k] == *ptr++);
96 if(boost::minimal_test::errors_counter() != 0)
98 testResultXml("reshape");
102 return boost::exit_success;