os/ossrv/stdcpp/tsrc/Boost_test/multi_array/src/reshape.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright 2002 The Trustees of Indiana University.
     2 
     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)
     6 
     7 //  Boost.MultiArray Library
     8 //  Authors: Ronald Garcia
     9 //           Jeremy Siek
    10 //           Andrew Lumsdaine
    11 //  See http://www.boost.org/libs/multi_array for documentation.
    12 
    13 // 
    14 // reshape.cpp - testing reshaping functionality
    15 //
    16 /*
    17  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    18 */
    19 
    20 #include "boost/multi_array.hpp"
    21 
    22 #include "boost/test/minimal.hpp"
    23 
    24 #include "boost/array.hpp"
    25 #include "boost/type.hpp"
    26 
    27 #ifdef __SYMBIAN32__
    28 #include "std_log_result.h"
    29 #define LOG_FILENAME_LINE __FILE__, __LINE__
    30 #endif
    31 int
    32 test_main(int,char*[])
    33 {
    34   const int ndims=3;
    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;
    38 
    39   boost::array<array::size_type,ndims> dims = {{2,3,4}};
    40   boost::array<array::size_type,ndims> new_dims = {{4,3,2}};
    41 
    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;
    45 
    46   // Basic reshape test
    47   {
    48     array A(dims);
    49     A.assign(data,data+data_size);
    50 
    51     array_ref B(data,dims);
    52     const_array_ref C(data,dims);
    53 
    54     A.reshape(new_dims);
    55     B.reshape(new_dims);
    56     C.reshape(new_dims);
    57 
    58     int* ptr = data;
    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++);
    65         }
    66   }
    67 
    68   // Ensure that index bases are preserved over reshape
    69   {
    70     boost::array<array::index,ndims> bases = {{0, 1, -1}};
    71 
    72     array A(dims);
    73     A.assign(data,data+data_size);
    74 
    75     array_ref B(data,dims);
    76     const_array_ref C(data,dims);
    77 
    78     A.reindex(bases);
    79     B.reindex(bases);
    80     C.reindex(bases);
    81 
    82     A.reshape(new_dims);
    83     B.reshape(new_dims);
    84     C.reshape(new_dims);
    85 
    86     int* ptr = data;
    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++);
    93         }
    94   }
    95 #ifdef __SYMBIAN32__
    96 if(boost::minimal_test::errors_counter() != 0)
    97    assert_failed = true;
    98    	testResultXml("reshape");
    99 	close_log_file();
   100 #endif
   101   
   102   return boost::exit_success;
   103 }
   104 
   105 
   106 
   107 
   108 
   109 
   110