1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// Copyright 2002 The Trustees of Indiana University.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Boost.MultiArray Library
// Authors: Ronald Garcia
// Jeremy Siek
// Andrew Lumsdaine
// See http://www.boost.org/libs/multi_array for documentation.
//
// storage_order.cpp - testing storage_order-isms.
//
#include <boost/multi_array.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/array.hpp>
int
main()
{
const int ndims=3;
int data_row[] = {
0,1,2,3,
4,5,6,7,
8,9,10,11,
12,13,14,15,
16,17,18,19,
20,21,22,23
};
int data_col[] = {
0,12,
4,16,
8,20,
1,13,
5,17,
9,21,
2,14,
6,18,
10,22,
3,15,
7,19,
11,23
};
const int num_elements = 24;
// fortran storage order
{
typedef boost::multi_array<int,ndims> array;
array::extent_gen extents;
array A(extents[2][3][4],boost::fortran_storage_order());
A.assign(data_col,data_col+num_elements);
int* num = data_row;
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
}
// Mimic fortran_storage_order using
// general_storage_order data placement
{
typedef boost::general_storage_order<ndims> storage;
typedef boost::multi_array<int,ndims> array;
array::size_type ordering[] = {0,1,2};
bool ascending[] = {true,true,true};
array::extent_gen extents;
array A(extents[2][3][4], storage(ordering,ascending));
A.assign(data_col,data_col+num_elements);
int* num = data_row;
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
}
// general_storage_order with arbitrary storage order
{
typedef boost::general_storage_order<ndims> storage;
typedef boost::multi_array<int,ndims> array;
array::size_type ordering[] = {2,0,1};
bool ascending[] = {true,true,true};
array::extent_gen extents;
array A(extents[2][3][4], storage(ordering,ascending));
int data_arb[] = {
0,1,2,3,
12,13,14,15,
4,5,6,7,
16,17,18,19,
8,9,10,11,
20,21,22,23
};
A.assign(data_arb,data_arb+num_elements);
int* num = data_row;
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
}
// general_storage_order with descending dimensions.
{
const int ndims=3;
typedef boost::general_storage_order<ndims> storage;
typedef boost::multi_array<int,ndims> array;
array::size_type ordering[] = {2,0,1};
bool ascending[] = {false,true,true};
array::extent_gen extents;
array A(extents[2][3][4], storage(ordering,ascending));
int data_arb[] = {
12,13,14,15,
0,1,2,3,
16,17,18,19,
4,5,6,7,
20,21,22,23,
8,9,10,11
};
A.assign(data_arb,data_arb+num_elements);
int* num = data_row;
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
}
return boost::report_errors();
}
|