sl@0: // Copyright 2002 The Trustees of Indiana University. sl@0: sl@0: // Use, modification and distribution is subject to the Boost Software sl@0: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // Boost.MultiArray Library sl@0: // Authors: Ronald Garcia sl@0: // Jeremy Siek sl@0: // Andrew Lumsdaine sl@0: // See http://www.boost.org/libs/multi_array for documentation. sl@0: sl@0: // sl@0: // reshape.cpp - testing reshaping functionality sl@0: // sl@0: /* sl@0: * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. sl@0: */ sl@0: sl@0: #include "boost/multi_array.hpp" sl@0: sl@0: #include "boost/test/minimal.hpp" sl@0: sl@0: #include "boost/array.hpp" sl@0: #include "boost/type.hpp" sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include "std_log_result.h" sl@0: #define LOG_FILENAME_LINE __FILE__, __LINE__ sl@0: #endif sl@0: int sl@0: test_main(int,char*[]) sl@0: { sl@0: const int ndims=3; sl@0: typedef boost::multi_array array; sl@0: typedef boost::multi_array_ref array_ref; sl@0: typedef boost::const_multi_array_ref const_array_ref; sl@0: sl@0: boost::array dims = {{2,3,4}}; sl@0: boost::array new_dims = {{4,3,2}}; sl@0: sl@0: int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13, sl@0: 14,15,16,17,18,19,20,21,22,23}; sl@0: const int data_size=24; sl@0: sl@0: // Basic reshape test sl@0: { sl@0: array A(dims); sl@0: A.assign(data,data+data_size); sl@0: sl@0: array_ref B(data,dims); sl@0: const_array_ref C(data,dims); sl@0: sl@0: A.reshape(new_dims); sl@0: B.reshape(new_dims); sl@0: C.reshape(new_dims); sl@0: sl@0: int* ptr = data; sl@0: for (array::index i = 0; i != 4; ++i) sl@0: for (array::index j = 0; j != 3; ++j) sl@0: for (array::index k = 0; k != 2; ++k) { sl@0: BOOST_CHECK(A[i][j][k] == *ptr); sl@0: BOOST_CHECK(B[i][j][k] == *ptr); sl@0: BOOST_CHECK(C[i][j][k] == *ptr++); sl@0: } sl@0: } sl@0: sl@0: // Ensure that index bases are preserved over reshape sl@0: { sl@0: boost::array bases = {{0, 1, -1}}; sl@0: sl@0: array A(dims); sl@0: A.assign(data,data+data_size); sl@0: sl@0: array_ref B(data,dims); sl@0: const_array_ref C(data,dims); sl@0: sl@0: A.reindex(bases); sl@0: B.reindex(bases); sl@0: C.reindex(bases); sl@0: sl@0: A.reshape(new_dims); sl@0: B.reshape(new_dims); sl@0: C.reshape(new_dims); sl@0: sl@0: int* ptr = data; sl@0: for (array::index i = 0; i != 4; ++i) sl@0: for (array::index j = 1; j != 4; ++j) sl@0: for (array::index k = -1; k != 1; ++k) { sl@0: BOOST_CHECK(A[i][j][k] == *ptr); sl@0: BOOST_CHECK(B[i][j][k] == *ptr); sl@0: BOOST_CHECK(C[i][j][k] == *ptr++); sl@0: } sl@0: } sl@0: #ifdef __SYMBIAN32__ sl@0: if(boost::minimal_test::errors_counter() != 0) sl@0: assert_failed = true; sl@0: testResultXml("reshape"); sl@0: close_log_file(); sl@0: #endif sl@0: sl@0: return boost::exit_success; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: