1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/multi_array/src/reshape.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,110 @@
1.4 +// Copyright 2002 The Trustees of Indiana University.
1.5 +
1.6 +// Use, modification and distribution is subject to the Boost Software
1.7 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.8 +// http://www.boost.org/LICENSE_1_0.txt)
1.9 +
1.10 +// Boost.MultiArray Library
1.11 +// Authors: Ronald Garcia
1.12 +// Jeremy Siek
1.13 +// Andrew Lumsdaine
1.14 +// See http://www.boost.org/libs/multi_array for documentation.
1.15 +
1.16 +//
1.17 +// reshape.cpp - testing reshaping functionality
1.18 +//
1.19 +/*
1.20 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.21 +*/
1.22 +
1.23 +#include "boost/multi_array.hpp"
1.24 +
1.25 +#include "boost/test/minimal.hpp"
1.26 +
1.27 +#include "boost/array.hpp"
1.28 +#include "boost/type.hpp"
1.29 +
1.30 +#ifdef __SYMBIAN32__
1.31 +#include "std_log_result.h"
1.32 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.33 +#endif
1.34 +int
1.35 +test_main(int,char*[])
1.36 +{
1.37 + const int ndims=3;
1.38 + typedef boost::multi_array<int,ndims> array;
1.39 + typedef boost::multi_array_ref<int,ndims> array_ref;
1.40 + typedef boost::const_multi_array_ref<int,ndims> const_array_ref;
1.41 +
1.42 + boost::array<array::size_type,ndims> dims = {{2,3,4}};
1.43 + boost::array<array::size_type,ndims> new_dims = {{4,3,2}};
1.44 +
1.45 + int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
1.46 + 14,15,16,17,18,19,20,21,22,23};
1.47 + const int data_size=24;
1.48 +
1.49 + // Basic reshape test
1.50 + {
1.51 + array A(dims);
1.52 + A.assign(data,data+data_size);
1.53 +
1.54 + array_ref B(data,dims);
1.55 + const_array_ref C(data,dims);
1.56 +
1.57 + A.reshape(new_dims);
1.58 + B.reshape(new_dims);
1.59 + C.reshape(new_dims);
1.60 +
1.61 + int* ptr = data;
1.62 + for (array::index i = 0; i != 4; ++i)
1.63 + for (array::index j = 0; j != 3; ++j)
1.64 + for (array::index k = 0; k != 2; ++k) {
1.65 + BOOST_CHECK(A[i][j][k] == *ptr);
1.66 + BOOST_CHECK(B[i][j][k] == *ptr);
1.67 + BOOST_CHECK(C[i][j][k] == *ptr++);
1.68 + }
1.69 + }
1.70 +
1.71 + // Ensure that index bases are preserved over reshape
1.72 + {
1.73 + boost::array<array::index,ndims> bases = {{0, 1, -1}};
1.74 +
1.75 + array A(dims);
1.76 + A.assign(data,data+data_size);
1.77 +
1.78 + array_ref B(data,dims);
1.79 + const_array_ref C(data,dims);
1.80 +
1.81 + A.reindex(bases);
1.82 + B.reindex(bases);
1.83 + C.reindex(bases);
1.84 +
1.85 + A.reshape(new_dims);
1.86 + B.reshape(new_dims);
1.87 + C.reshape(new_dims);
1.88 +
1.89 + int* ptr = data;
1.90 + for (array::index i = 0; i != 4; ++i)
1.91 + for (array::index j = 1; j != 4; ++j)
1.92 + for (array::index k = -1; k != 1; ++k) {
1.93 + BOOST_CHECK(A[i][j][k] == *ptr);
1.94 + BOOST_CHECK(B[i][j][k] == *ptr);
1.95 + BOOST_CHECK(C[i][j][k] == *ptr++);
1.96 + }
1.97 + }
1.98 +#ifdef __SYMBIAN32__
1.99 +if(boost::minimal_test::errors_counter() != 0)
1.100 + assert_failed = true;
1.101 + testResultXml("reshape");
1.102 + close_log_file();
1.103 +#endif
1.104 +
1.105 + return boost::exit_success;
1.106 +}
1.107 +
1.108 +
1.109 +
1.110 +
1.111 +
1.112 +
1.113 +