sl@0
|
1 |
// Copyright 2002 The Trustees of Indiana University.
|
sl@0
|
2 |
|
sl@0
|
3 |
// Use, modification and distribution is subject to the Boost Software
|
sl@0
|
4 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
5 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
6 |
|
sl@0
|
7 |
// Boost.MultiArray Library
|
sl@0
|
8 |
// Authors: Ronald Garcia
|
sl@0
|
9 |
// Jeremy Siek
|
sl@0
|
10 |
// Andrew Lumsdaine
|
sl@0
|
11 |
// See http://www.boost.org/libs/multi_array for documentation.
|
sl@0
|
12 |
|
sl@0
|
13 |
//
|
sl@0
|
14 |
// reshape.cpp - testing reshaping functionality
|
sl@0
|
15 |
//
|
sl@0
|
16 |
/*
|
sl@0
|
17 |
* © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "boost/multi_array.hpp"
|
sl@0
|
21 |
|
sl@0
|
22 |
#include "boost/test/minimal.hpp"
|
sl@0
|
23 |
|
sl@0
|
24 |
#include "boost/array.hpp"
|
sl@0
|
25 |
#include "boost/type.hpp"
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifdef __SYMBIAN32__
|
sl@0
|
28 |
#include "std_log_result.h"
|
sl@0
|
29 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
sl@0
|
30 |
#endif
|
sl@0
|
31 |
int
|
sl@0
|
32 |
test_main(int,char*[])
|
sl@0
|
33 |
{
|
sl@0
|
34 |
const int ndims=3;
|
sl@0
|
35 |
typedef boost::multi_array<int,ndims> array;
|
sl@0
|
36 |
typedef boost::multi_array_ref<int,ndims> array_ref;
|
sl@0
|
37 |
typedef boost::const_multi_array_ref<int,ndims> const_array_ref;
|
sl@0
|
38 |
|
sl@0
|
39 |
boost::array<array::size_type,ndims> dims = {{2,3,4}};
|
sl@0
|
40 |
boost::array<array::size_type,ndims> new_dims = {{4,3,2}};
|
sl@0
|
41 |
|
sl@0
|
42 |
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
|
sl@0
|
43 |
14,15,16,17,18,19,20,21,22,23};
|
sl@0
|
44 |
const int data_size=24;
|
sl@0
|
45 |
|
sl@0
|
46 |
// Basic reshape test
|
sl@0
|
47 |
{
|
sl@0
|
48 |
array A(dims);
|
sl@0
|
49 |
A.assign(data,data+data_size);
|
sl@0
|
50 |
|
sl@0
|
51 |
array_ref B(data,dims);
|
sl@0
|
52 |
const_array_ref C(data,dims);
|
sl@0
|
53 |
|
sl@0
|
54 |
A.reshape(new_dims);
|
sl@0
|
55 |
B.reshape(new_dims);
|
sl@0
|
56 |
C.reshape(new_dims);
|
sl@0
|
57 |
|
sl@0
|
58 |
int* ptr = data;
|
sl@0
|
59 |
for (array::index i = 0; i != 4; ++i)
|
sl@0
|
60 |
for (array::index j = 0; j != 3; ++j)
|
sl@0
|
61 |
for (array::index k = 0; k != 2; ++k) {
|
sl@0
|
62 |
BOOST_CHECK(A[i][j][k] == *ptr);
|
sl@0
|
63 |
BOOST_CHECK(B[i][j][k] == *ptr);
|
sl@0
|
64 |
BOOST_CHECK(C[i][j][k] == *ptr++);
|
sl@0
|
65 |
}
|
sl@0
|
66 |
}
|
sl@0
|
67 |
|
sl@0
|
68 |
// Ensure that index bases are preserved over reshape
|
sl@0
|
69 |
{
|
sl@0
|
70 |
boost::array<array::index,ndims> bases = {{0, 1, -1}};
|
sl@0
|
71 |
|
sl@0
|
72 |
array A(dims);
|
sl@0
|
73 |
A.assign(data,data+data_size);
|
sl@0
|
74 |
|
sl@0
|
75 |
array_ref B(data,dims);
|
sl@0
|
76 |
const_array_ref C(data,dims);
|
sl@0
|
77 |
|
sl@0
|
78 |
A.reindex(bases);
|
sl@0
|
79 |
B.reindex(bases);
|
sl@0
|
80 |
C.reindex(bases);
|
sl@0
|
81 |
|
sl@0
|
82 |
A.reshape(new_dims);
|
sl@0
|
83 |
B.reshape(new_dims);
|
sl@0
|
84 |
C.reshape(new_dims);
|
sl@0
|
85 |
|
sl@0
|
86 |
int* ptr = data;
|
sl@0
|
87 |
for (array::index i = 0; i != 4; ++i)
|
sl@0
|
88 |
for (array::index j = 1; j != 4; ++j)
|
sl@0
|
89 |
for (array::index k = -1; k != 1; ++k) {
|
sl@0
|
90 |
BOOST_CHECK(A[i][j][k] == *ptr);
|
sl@0
|
91 |
BOOST_CHECK(B[i][j][k] == *ptr);
|
sl@0
|
92 |
BOOST_CHECK(C[i][j][k] == *ptr++);
|
sl@0
|
93 |
}
|
sl@0
|
94 |
}
|
sl@0
|
95 |
#ifdef __SYMBIAN32__
|
sl@0
|
96 |
if(boost::minimal_test::errors_counter() != 0)
|
sl@0
|
97 |
assert_failed = true;
|
sl@0
|
98 |
testResultXml("reshape");
|
sl@0
|
99 |
close_log_file();
|
sl@0
|
100 |
#endif
|
sl@0
|
101 |
|
sl@0
|
102 |
return boost::exit_success;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
|
sl@0
|
106 |
|
sl@0
|
107 |
|
sl@0
|
108 |
|
sl@0
|
109 |
|
sl@0
|
110 |
|