[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
# Copyright David Abrahams 2003. Permission to copy, use,
# modify, sell and distribute this software is granted provided this
# copyright notice appears in all copies. This software is provided
# "as is" without express or implied warranty, and with no claim as
# to its suitability for any purpose.
test-suite multi_array
:
[ compile-fail fail_cbracket.cpp ]
[ compile-fail fail_cdata.cpp ]
[ compile-fail fail_citerator.cpp ]
[ compile-fail fail_cparen.cpp ]
[ compile-fail fail_criterator.cpp ]
[ compile-fail fail_csubarray.cpp ]
[ compile-fail fail_csubarray2.cpp ]
[ compile-fail fail_csubarray3.cpp ]
[ compile-fail fail_cview.cpp ]
[ compile-fail fail_cview2.cpp ]
[ compile-fail fail_cview3.cpp ]
[ compile-fail fail_ref_cbracket.cpp ]
[ compile-fail fail_ref_cdata.cpp ]
[ compile-fail fail_ref_citerator.cpp ]
[ compile-fail fail_ref_cparen.cpp ]
[ compile-fail fail_ref_criterator.cpp ]
[ compile-fail fail_ref_csubarray.cpp ]
[ compile-fail fail_ref_csubarray2.cpp ]
[ compile-fail fail_ref_csubarray3.cpp ]
[ compile-fail fail_ref_cview.cpp ]
[ compile-fail fail_ref_cview2.cpp ]
[ compile-fail fail_ref_cview3.cpp ]
[ run constructors.cpp ../../test/build//boost_test_exec_monitor ]
[ run access.cpp ../../test/build//boost_test_exec_monitor ]
[ run compare.cpp ../../test/build//boost_test_exec_monitor ]
[ run iterators.cpp ../../test/build//boost_test_exec_monitor ]
[ run slice.cpp ../../test/build//boost_test_exec_monitor ]
[ run assign.cpp ../../test/build//boost_test_exec_monitor ]
[ run assign_to_array.cpp ../../test/build//boost_test_exec_monitor ]
[ run index_bases.cpp ../../test/build//boost_test_exec_monitor ]
[ run storage_order_convert.cpp ../../test/build//boost_test_exec_monitor ]
[ run storage_order.cpp ../../test/build//boost_test_exec_monitor ]
[ run reshape.cpp ../../test/build//boost_test_exec_monitor ]
[ run range1.cpp ../../test/build//boost_test_exec_monitor ]
[ run idxgen1.cpp ../../test/build//boost_test_exec_monitor ]
[ run stl_interaction.cpp ../../test/build//boost_test_exec_monitor ]
[ run resize.cpp ../../test/build//boost_test_exec_monitor ]
[ run assert.cpp ../../test/build//boost_test_exec_monitor ]
[ run reverse_view.cpp ../../test/build//boost_test_exec_monitor ]
[ compile concept_checks.cpp ]
;

View File

@@ -0,0 +1,63 @@
// 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.
//
// access.cpp - operator[] and operator() tests with various arrays
// The tests assume that they are working on an Array of shape 2x3x4
//
#include "generative_tests.hpp"
#include "boost/static_assert.hpp"
template <typename Array>
void access(Array& A, const mutable_array_tag&) {
assign(A);
access(A,const_array_tag());
const Array& CA = A;
access(CA,const_array_tag());
}
template <typename Array>
void access(Array& A, const const_array_tag&) {
const unsigned int ndims = 3;
BOOST_STATIC_ASSERT((Array::dimensionality == ndims));
typedef typename Array::index index;
const index idx0 = A.index_bases()[0];
const index idx1 = A.index_bases()[1];
const index idx2 = A.index_bases()[2];
// operator[]
int cnum = 0;
const Array& CA = A;
for (index i = idx0; i != idx0+2; ++i)
for (index j = idx1; j != idx1+3; ++j)
for (index k = idx2; k != idx2+4; ++k) {
BOOST_CHECK(A[i][j][k] == cnum++);
BOOST_CHECK(CA[i][j][k] == A[i][j][k]);
}
// operator()
for (index i2 = idx0; i2 != idx0+2; ++i2)
for (index j2 = idx1; j2 != idx1+3; ++j2)
for (index k2 = idx2; k2 != idx2+4; ++k2) {
boost::array<index,ndims> indices;
indices[0] = i2; indices[1] = j2; indices[2] = k2;
BOOST_CHECK(A(indices) == A[i2][j2][k2]);
BOOST_CHECK(CA(indices) == A(indices));
}
++tests_run;
}
int test_main(int,char*[]) {
return run_generative_tests();
}

View File

@@ -0,0 +1,59 @@
// Copyright 2007 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.
//
// Using the BOOST.ASSERT mechanism to replace library assertions
// with exceptions
//
#include "boost/test/minimal.hpp"
#define BOOST_ENABLE_ASSERT_HANDLER
#include "boost/multi_array.hpp" // includes assert.hpp
#include <stdexcept>
namespace boost {
void assertion_failed(char const* expr, char const* function,
char const* file, long line) {
throw std::runtime_error(expr);
}
void assertion_failed_msg(char const * expr, char const * msg,
char const * function,
char const * file, long line) {
throw std::runtime_error(msg);
}
} // namespace boost
using namespace boost;
int
test_main(int,char*[]) {
typedef multi_array<int,2> array_t;
array_t A(extents[2][2]);
array_t B(extents[3][3]);
try {
A = B;
BOOST_ERROR("did not throw an exception");
} catch (std::runtime_error&) {
//...all good
}
return boost::exit_success;
}

View File

@@ -0,0 +1,73 @@
// 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.
//
// assign.cpp - Test out operator=() on the different types
//
//
#include "generative_tests.hpp"
#include "boost/array.hpp"
#include "boost/multi_array.hpp"
#include "boost/cstdlib.hpp"
#include <algorithm>
#include <iostream>
bool equal(const int& a, const int& b)
{
return a == b;
}
template <typename ArrayA, typename ArrayB>
bool equal(const ArrayA& A, const ArrayB& B)
{
typename ArrayA::const_iterator ia;
typename ArrayB::const_iterator ib = B.begin();
for (ia = A.begin(); ia != A.end(); ++ia, ++ib)
if (!::equal(*ia, *ib))
return false;
return true;
}
template <typename Array>
void access(Array& A, const mutable_array_tag&) {
assign(A);
typedef boost::multi_array<int,3> array3;
int insert[] = {
99,98,97,96,
95,94,93,92,
91,90,89,88,
87,86,85,84,
83,82,81,80,
79,78,77,76
};
const int insert_size = 2*3*4;
array3 filler(boost::extents[2][3][4]);
filler.assign(insert,insert+insert_size);
A = filler;
BOOST_CHECK(::equal(A,filler));
++tests_run;
}
template <typename Array>
void access(Array&, const const_array_tag&) {
}
int test_main(int,char*[]) {
return run_generative_tests();
}

View File

@@ -0,0 +1,60 @@
// 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.
//
// assign_to_array.cpp - multi_array should be constructible from any other
// array type in the library.
//
//
#include "generative_tests.hpp"
#include "boost/array.hpp"
#include "boost/multi_array.hpp"
#include "boost/cstdlib.hpp"
#include <algorithm>
#include <iostream>
bool equal(const int& a, const int& b)
{
return a == b;
}
template <typename ArrayA, typename ArrayB>
bool equal(const ArrayA& A, const ArrayB& B)
{
typename ArrayA::const_iterator ia;
typename ArrayB::const_iterator ib = B.begin();
for (ia = A.begin(); ia != A.end(); ++ia, ++ib)
if (!::equal(*ia, *ib))
return false;
return true;
}
template <typename Array>
void access(Array& A, const mutable_array_tag&) {
assign(A);
access(A,const_array_tag());
}
template <typename Array>
void access(Array& A, const const_array_tag&) {
typedef boost::multi_array<int,3> array3;
array3 acopy(A);
BOOST_CHECK(::equal(acopy,A));
++tests_run;
}
int test_main(int,char*[]) {
return run_generative_tests();
}

View File

@@ -0,0 +1,142 @@
// 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.
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include <algorithm>
#include <list>
int
test_main(int, char*[])
{
typedef boost::multi_array<double, 3> array;
typedef array::size_type size_type;
boost::array<size_type,3> sizes = { { 3, 3, 3 } };
const size_type num_elements = 27;
// Copy Constructor
{
array A(sizes);
std::vector<double> vals(num_elements, 4.5);
A.assign(vals.begin(),vals.end());
array B(A);
BOOST_CHECK(A == B);
BOOST_CHECK(B == A);
BOOST_CHECK(A[0] == B[0]);
}
// Assignment Operator
{
array A(sizes), B(sizes);
std::vector<double> vals(num_elements, 4.5);
A.assign(vals.begin(),vals.end());
B = A;
BOOST_CHECK(A == B);
BOOST_CHECK(B == A);
BOOST_CHECK(B[0] == A[0]);
typedef array::index_range range;
array::index_gen indices;
array::array_view<2>::type C = A[indices[2][range()][range()]];
array::array_view<2>::type D = B[indices[2][range()][range()]];
BOOST_CHECK(C == D);
}
// Different Arrays
{
array A(sizes), B(sizes);
std::vector<double> valsA(num_elements, 4.5);
std::vector<double> valsB(num_elements, 2.5);
A.assign(valsA.begin(),valsA.end());
B.assign(valsB.begin(),valsB.end());
BOOST_CHECK(A != B);
BOOST_CHECK(B != A);
BOOST_CHECK(A[0] != B[0]);
typedef array::index_range range;
array::index_gen indices;
array::array_view<2>::type C = A[indices[2][range()][range()]];
array::array_view<2>::type D = B[indices[2][range()][range()]];
BOOST_CHECK(C != D);
}
// Comparisons galore!
{
array A(sizes), B(sizes);
double valsA[] = {
0, 0, 0,
0, 0, 0,
0, 0, 0,
1, 1, 1,
1, 1, 1,
1, 1, 1,
2, 2, 2,
2, 2, 2,
2, 2, 2
};
double valsB[] = {
0, 0, 0,
0, 0, 0,
0, 0, 0,
1, 1, 1,
1, 1, 1,
1, 1, 1,
2, 2, 2,
2, 2, 2,
2, 2, 1
};
A.assign(valsA,valsA+num_elements);
B.assign(valsB,valsB+num_elements);
BOOST_CHECK(B < A);
BOOST_CHECK(A > B);
BOOST_CHECK(B <= A);
BOOST_CHECK(A >= B);
BOOST_CHECK(B[0] == A[0]);
BOOST_CHECK(B[2] < A[2]);
array C = A;
BOOST_CHECK(C <= A);
BOOST_CHECK(C >= A);
BOOST_CHECK(!(C < A));
BOOST_CHECK(!(C > A));
typedef array::index_range range;
array::index_gen indices;
array::array_view<2>::type D = A[indices[2][range()][range()]];
array::array_view<2>::type E = B[indices[2][range()][range()]];
BOOST_CHECK(E < D);
BOOST_CHECK(E <= D);
}
return boost::exit_success;
}

View File

@@ -0,0 +1,65 @@
// 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.
//
// concept_checks.cpp -
// make sure the types meet concept requirements
//
#include "boost/concept_check.hpp"
#include "boost/multi_array/concept_checks.hpp"
#include "boost/multi_array.hpp"
#include "boost/cstdlib.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
typedef boost::multi_array_ref<int,ndims> array_ref;
typedef boost::const_multi_array_ref<int,ndims> const_array_ref;
typedef array::array_view<ndims>::type array_view;
typedef array::const_array_view<ndims>::type const_array_view;
typedef array::subarray<ndims>::type subarray;
typedef array::const_subarray<ndims>::type const_subarray;
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<array,ndims> >();
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<array_ref,ndims> >();
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<const_array_ref,ndims> >();
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<array_view,ndims> >();
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<const_array_view,ndims> >();
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<subarray,ndims> >();
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<const_subarray,ndims> >();
boost::function_requires<
boost::multi_array_concepts::MutableMultiArrayConcept<array,ndims> >();
boost::function_requires<
boost::multi_array_concepts::MutableMultiArrayConcept<array_ref,ndims> >();
boost::function_requires<
boost::multi_array_concepts::MutableMultiArrayConcept<array_view,ndims> >();
boost::function_requires<
boost::multi_array_concepts::MutableMultiArrayConcept<subarray,ndims> >();
return 0;
}

View File

@@ -0,0 +1,218 @@
// 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.
//
// constructors.cpp - Testing out the various constructor options
//
#include "boost/test/minimal.hpp"
#include "boost/multi_array.hpp"
#include <algorithm>
#include <list>
void check_shape(const double&, std::size_t*, int*, unsigned int)
{}
template <class Array>
void check_shape(const Array& A,
std::size_t* sizes,
int* strides,
unsigned int num_elements)
{
BOOST_CHECK(A.num_elements() == num_elements);
BOOST_CHECK(A.size() == *sizes);
BOOST_CHECK(std::equal(sizes, sizes + A.num_dimensions(), A.shape()));
BOOST_CHECK(std::equal(strides, strides + A.num_dimensions(), A.strides()));
check_shape(A[0], ++sizes, ++strides, num_elements / A.size());
}
bool equal(const double& a, const double& b)
{
return a == b;
}
template <typename ArrayA, typename ArrayB>
bool equal(const ArrayA& A, const ArrayB& B)
{
typename ArrayA::const_iterator ia;
typename ArrayB::const_iterator ib = B.begin();
for (ia = A.begin(); ia != A.end(); ++ia, ++ib)
if (!::equal(*ia, *ib))
return false;
return true;
}
int
test_main(int, char*[])
{
typedef boost::multi_array<double, 3>::size_type size_type;
boost::array<size_type,3> sizes = { { 3, 3, 3 } };
int strides[] = { 9, 3, 1 };
size_type num_elements = 27;
// Default multi_array constructor
{
boost::multi_array<double, 3> A;
}
// Constructor 1, default storage order and allocator
{
boost::multi_array<double, 3> A(sizes);
check_shape(A, &sizes[0], strides, num_elements);
double* ptr = 0;
boost::multi_array_ref<double,3> B(ptr,sizes);
check_shape(B, &sizes[0], strides, num_elements);
const double* cptr = ptr;
boost::const_multi_array_ref<double,3> C(cptr,sizes);
check_shape(C, &sizes[0], strides, num_elements);
}
// Constructor 1, fortran storage order and user-supplied allocator
{
typedef boost::multi_array<double, 3,
std::allocator<double> >::size_type size_type;
size_type num_elements = 27;
int col_strides[] = { 1, 3, 9 };
boost::multi_array<double, 3,
std::allocator<double> > A(sizes,boost::fortran_storage_order());
check_shape(A, &sizes[0], col_strides, num_elements);
double *ptr=0;
boost::multi_array_ref<double, 3>
B(ptr,sizes,boost::fortran_storage_order());
check_shape(B, &sizes[0], col_strides, num_elements);
const double *cptr=ptr;
boost::const_multi_array_ref<double, 3>
C(cptr,sizes,boost::fortran_storage_order());
check_shape(C, &sizes[0], col_strides, num_elements);
}
// Constructor 2, default storage order and allocator
{
typedef boost::multi_array<double, 3>::size_type size_type;
size_type num_elements = 27;
boost::multi_array<double, 3>::extent_gen extents;
boost::multi_array<double, 3> A(extents[3][3][3]);
check_shape(A, &sizes[0], strides, num_elements);
double *ptr=0;
boost::multi_array_ref<double, 3> B(ptr,extents[3][3][3]);
check_shape(B, &sizes[0], strides, num_elements);
const double *cptr=ptr;
boost::const_multi_array_ref<double, 3> C(cptr,extents[3][3][3]);
check_shape(C, &sizes[0], strides, num_elements);
}
// Copy Constructors
{
typedef boost::multi_array<double, 3>::size_type size_type;
size_type num_elements = 27;
std::vector<double> vals(27, 4.5);
boost::multi_array<double, 3> A(sizes);
A.assign(vals.begin(),vals.end());
boost::multi_array<double, 3> B(A);
check_shape(B, &sizes[0], strides, num_elements);
BOOST_CHECK(::equal(A, B));
double ptr[27];
boost::multi_array_ref<double, 3> C(ptr,sizes);
A.assign(vals.begin(),vals.end());
boost::multi_array_ref<double, 3> D(C);
check_shape(D, &sizes[0], strides, num_elements);
BOOST_CHECK(C.data() == D.data());
const double* cptr = ptr;
boost::const_multi_array_ref<double, 3> E(cptr,sizes);
boost::const_multi_array_ref<double, 3> F(E);
check_shape(F, &sizes[0], strides, num_elements);
BOOST_CHECK(E.data() == F.data());
}
// Conversion construction
{
typedef boost::multi_array<double, 3>::size_type size_type;
size_type num_elements = 27;
std::vector<double> vals(27, 4.5);
boost::multi_array<double, 3> A(sizes);
A.assign(vals.begin(),vals.end());
boost::multi_array_ref<double, 3> B(A);
boost::const_multi_array_ref<double, 3> C(A);
check_shape(B, &sizes[0], strides, num_elements);
check_shape(C, &sizes[0], strides, num_elements);
BOOST_CHECK(B.data() == A.data());
BOOST_CHECK(C.data() == A.data());
double ptr[27];
boost::multi_array_ref<double, 3> D(ptr,sizes);
D.assign(vals.begin(),vals.end());
boost::const_multi_array_ref<double, 3> E(D);
check_shape(E, &sizes[0], strides, num_elements);
BOOST_CHECK(E.data() == D.data());
}
// Assignment Operator
{
typedef boost::multi_array<double, 3>::size_type size_type;
size_type num_elements = 27;
std::vector<double> vals(27, 4.5);
boost::multi_array<double, 3> A(sizes), B(sizes);
A.assign(vals.begin(),vals.end());
B = A;
check_shape(B, &sizes[0], strides, num_elements);
BOOST_CHECK(::equal(A, B));
double ptr1[27];
double ptr2[27];
boost::multi_array_ref<double, 3> C(ptr1,sizes), D(ptr2,sizes);
C.assign(vals.begin(),vals.end());
D = C;
check_shape(D, &sizes[0], strides, num_elements);
BOOST_CHECK(::equal(C,D));
}
// subarray value_type is multi_array
{
typedef boost::multi_array<double,3> array;
typedef array::size_type size_type;
size_type num_elements = 27;
std::vector<double> vals(num_elements, 4.5);
boost::multi_array<double, 3> A(sizes);
A.assign(vals.begin(),vals.end());
typedef array::subarray<2>::type subarray;
subarray B = A[1];
subarray::value_type C = B[0];
// should comparisons between the types work?
BOOST_CHECK(::equal(A[1][0],C));
BOOST_CHECK(::equal(B[0],C));
}
return boost::exit_success;
}

View File

@@ -0,0 +1,312 @@
// 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.
//
// Trying to diagnose problems under visual
#include "boost/config.hpp"
#include "boost/array.hpp"
#include "boost/limits.hpp"
#include <algorithm>
#include <utility>
typedef int index;
typedef std::size_t size_type;
template <typename Index,typename SizeType>
class index_range {
public:
index_range()
{
start_ = from_start();
finish_ = to_end();
stride_ = 1;
degenerate_ = false;
}
explicit index_range(Index pos)
{
start_ = pos;
finish_ = pos;
stride_ = 1;
degenerate_ = true;
}
explicit index_range(Index start, Index finish, Index stride=1)
: start_(start), finish_(finish), stride_(stride),
degenerate_(start_ == finish_)
{ }
// These are for chaining assignments to an index_range
index_range& start(Index s) {
start_ = s;
degenerate_ = (start_ == finish_);
return *this;
}
index_range& finish(Index f) {
finish_ = f;
degenerate_ = (start_ == finish_);
return *this;
}
index_range& stride(Index s) { stride_ = s; return *this; }
Index start() const
{
return start_;
}
Index get_start(Index low_index_range = 0) const
{
if (start_ == from_start())
return low_index_range;
return start_;
}
Index finish() const
{
return finish_;
}
Index get_finish(Index high_index_range = 0) const
{
if (finish_ == to_end())
return high_index_range;
return finish_;
}
unsigned int size(Index recommended_length = 0) const
{
if ((start_ == from_start()) || (finish_ == to_end()))
return recommended_length;
else
return (finish_ - start_) / stride_;
}
Index stride() const { return stride_; }
bool is_ascending_contiguous() const
{
return (start_ < finish_) && is_unit_stride();
}
void set_index_range(Index start, Index finish, Index stride=1)
{
start_ = start;
finish_ = finish;
stride_ = stride;
}
static index_range all()
{ return index_range(from_start(), to_end(), 1); }
bool is_unit_stride() const
{ return stride_ == 1; }
bool is_degenerate() const { return degenerate_; }
index_range operator-(Index shift) const
{
return index_range(start_ - shift, finish_ - shift, stride_);
}
index_range operator+(Index shift) const
{
return index_range(start_ + shift, finish_ + shift, stride_);
}
Index operator[](unsigned i) const
{
return start_ + i * stride_;
}
Index operator()(unsigned i) const
{
return start_ + i * stride_;
}
// add conversion to std::slice?
private:
static Index from_start()
{ return (std::numeric_limits<Index>::min)(); }
static Index to_end()
{ return (std::numeric_limits<Index>::max)(); }
public:
Index start_, finish_, stride_;
bool degenerate_;
};
// Express open and closed interval end-points using the comparison
// operators.
// left closed
template <typename Index, typename SizeType>
inline index_range<Index,SizeType>
operator<=(Index s, const index_range<Index,SizeType>& r)
{
return index_range<Index,SizeType>(s, r.finish(), r.stride());
}
// left open
template <typename Index, typename SizeType>
inline index_range<Index,SizeType>
operator<(Index s, const index_range<Index,SizeType>& r)
{
return index_range<Index,SizeType>(s + 1, r.finish(), r.stride());
}
// right open
template <typename Index, typename SizeType>
inline index_range<Index,SizeType>
operator<(const index_range<Index,SizeType>& r, Index f)
{
return index_range<Index,SizeType>(r.start(), f, r.stride());
}
// right closed
template <typename Index, typename SizeType>
inline index_range<Index,SizeType>
operator<=(const index_range<Index,SizeType>& r, Index f)
{
return index_range<Index,SizeType>(r.start(), f + 1, r.stride());
}
//
// range_list.hpp - helper to build boost::arrays for *_set types
//
/////////////////////////////////////////////////////////////////////////
// choose range list begins
//
struct choose_range_list_n {
template <typename T, std::size_t NumRanges>
struct bind {
typedef boost::array<T,NumRanges> type;
};
};
struct choose_range_list_zero {
template <typename T, std::size_t NumRanges>
struct bind {
typedef boost::array<T,1> type;
};
};
template <std::size_t NumRanges>
struct range_list_gen_helper {
typedef choose_range_list_n choice;
};
template <>
struct range_list_gen_helper<0> {
typedef choose_range_list_zero choice;
};
template <typename T, std::size_t NumRanges>
struct range_list_generator {
private:
typedef typename range_list_gen_helper<NumRanges>::choice Choice;
public:
typedef typename Choice::template bind<T,NumRanges>::type type;
};
//
// choose range list ends
/////////////////////////////////////////////////////////////////////////
//
// Index_gen.hpp stuff
//
template <int NumRanges, int NumDims>
struct index_gen {
private:
typedef index Index;
typedef size_type SizeType;
typedef index_range<Index,SizeType> range;
public:
typedef typename range_list_generator<range,NumRanges>::type range_list;
range_list ranges_;
index_gen() { }
template <int ND>
explicit index_gen(const index_gen<NumRanges-1,ND>& rhs,
const index_range<Index,SizeType>& range)
{
std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin());
*ranges_.rbegin() = range;
}
index_gen<NumRanges+1,NumDims+1>
operator[](const index_range<Index,SizeType>& range) const
{
index_gen<NumRanges+1,NumDims+1> tmp;
std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin());
*tmp.ranges_.rbegin() = range;
return tmp;
}
index_gen<NumRanges+1,NumDims>
operator[](Index idx) const
{
index_gen<NumRanges+1,NumDims> tmp;
std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin());
*tmp.ranges_.rbegin() = index_range<Index,SizeType>(idx);
return tmp;
}
};
template <int NDims, int NRanges>
void accept_gen(index_gen<NRanges,NDims>& indices) {
// do nothing
}
template <typename X, typename Y, int A, int B>
class foo { };
class boo {
template <int NDims, int NRanges>
void operator[](index_gen<NRanges,NDims>& indices) {
}
};
template <typename X, typename Y, int A1, int A2>
void take_foo(foo<X,Y,A1,A2>& f) { }
int main() {
index_gen<0,0> indices;
typedef index_range<index,size_type> range;
take_foo(foo<int,std::size_t,1,2>());
indices[range()][range()][range()];
accept_gen(indices);
accept_gen(index_gen<0,0>());
accept_gen(indices[range()][range()][range()]);
boo b;
b[indices[range()][range()][range()]];
return 0;
}

View File

@@ -0,0 +1,40 @@
// 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.
//
// fail_cbracket.cpp -
// checking constness of const operator[].
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
array sma(sma_dims);
const array& csma = sma;
// FAIL! cannot assign to csma.
csma[0][0][0] = 5;
return boost::exit_success;
}

View File

@@ -0,0 +1,41 @@
// 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.
//
// fail_cdata.cpp
// Testing data() member function constness.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
const int data_size = 24;
array sma(sma_dims);
sma.assign(data,data+data_size);
const array& csma = sma;
// FAIL! data() returns a const int*
*csma.data() = 0;
return boost::exit_success;
}

View File

@@ -0,0 +1,33 @@
// 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.
//
// fail_citerator.cpp -
// const_iterator/iterator conversion test
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {
typedef boost::multi_array<int,3> array;
typedef array::iterator iterator1;
typedef array::const_iterator citerator1;
// ILLEGAL conversion from const_iterator to iterator
iterator1 in = citerator1();
return boost::exit_success;
}

View File

@@ -0,0 +1,44 @@
// 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.
//
// fail_cparen.cpp -
// Testing const operator() constness.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
const int data_size = 24;
array sma(sma_dims);
sma.assign(data,data+data_size);
const array& csma = sma;
boost::array<array::index,ndims> indices = {{0,0,0}};
// FAIL! Cannot assign to csma
csma(indices) = 5;
return boost::exit_success;
}

View File

@@ -0,0 +1,33 @@
// 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.
//
// fail_criterator.cpp
// const_reverse_iterator/reverse_iterator conversion test
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {
typedef boost::multi_array<int,3> array;
typedef array::reverse_iterator riterator1;
typedef array::const_reverse_iterator criterator1;
// ILLEGAL conversion from const_reverse_iterator to reverse_iterator
riterator1 in = criterator1();
return boost::exit_success;
}

View File

@@ -0,0 +1,46 @@
// 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.
//
// fail_csubarray.cpp -
// Testing subarray and const_subarray assignment
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
array sma(sma_dims);
int num = 0;
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
sma[i][j][k] = num++;
array::const_subarray<ndims-1>::type csba = sma[0];
// FAIL! Preserve constness (no const_subarray -> subarray conversion).
array::subarray<ndims-1>::type sba = csba;
return boost::exit_success;
}

View File

@@ -0,0 +1,45 @@
// 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.
//
// fail_csubarray2.cpp
// Testing constness of subarray operations.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
array sma(sma_dims);
int num = 0;
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
sma[i][j][k] = num++;
const array& sma_const = sma;
// FAIL! preserve constness.
array::subarray<ndims-1>::type sba = sma_const[0];
return boost::exit_success;
}

View File

@@ -0,0 +1,49 @@
// 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.
//
// fail_csubarray3.cpp
// Testing constness of subarray operations.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
array sma(sma_dims);
int num = 0;
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
sma[i][j][k] = num++;
const array& sma_const = sma;
array::const_subarray<ndims-1>::type sba = sma_const[0];
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
// FAIL! sba cannot be assigned to.
sba[j][k] = num++;
return boost::exit_success;
}

View File

@@ -0,0 +1,65 @@
// 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.
//
// fail_cview.cpp -
// ensure const_array_view doesn't allow element assignment.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
const int data_size = 24;
array sma(sma_dims);
sma.assign(data,data+data_size);
//
// subarray dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
const array& csma = sma;
typedef array::index_range range;
array::index_gen indices;
array::const_array_view<ndims>::type csma2 =
csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];
boost::array<array::index,3> elmt = {{0,0,0}};
// FAIL! const_array_view cannot be assigned to.
csma2(elmt) = 5;
return boost::exit_success;
}

View File

@@ -0,0 +1,63 @@
// 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.
//
// fail_cview2.cpp
// ensure const_array_view cannot be converted to array_view
//
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
#include "boost/cstdlib.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
const int data_size = 24;
array sma(sma_dims);
sma.assign(data,data+data_size);
//
// subarray dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
const array& csma = sma;
typedef array::index_range range;
array::index_gen indices;
// FAIL! preserve constness (no const_array_view -> array_view).
array::array_view<ndims>::type csma2 =
csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];
return boost::exit_success;
}

View File

@@ -0,0 +1,66 @@
// 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.
//
// fail_cview3.cpp
// ensure const_array_ref doesn't allow assignment.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
boost::array<array::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
const int data_size = 24;
array sma(sma_dims);
sma.assign(data,data+data_size);
//
// subarray dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
const array& csma = sma;
typedef array::index_range range;
array::index_gen indices;
array::const_array_view<ndims>::type csma2 =
csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 2; ++j)
for (array::index k = 0; k != 2; ++k)
// FAIL! csma2 cannot be assigned to.
csma2[i][j][k] = 0;
return boost::exit_success;
}

View File

@@ -0,0 +1,44 @@
// 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.
//
// fail_ref_cbracket.cpp
// checking constness of const operator[].
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {77,77,77,77,77,77,77,77,77,77,77,77,
77,77,77,77,77,77,77,77,77,77,77,77};
array_ref sma(data,sma_dims);
const array_ref& csma = sma;
// FAIL! can't assign to const multi_array_ref.
csma[0][0][0] = 5;
return boost::exit_success;
}

View File

@@ -0,0 +1,40 @@
// 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.
//
// fail_ref_cdata.cpp -
// Testing data() member function constness.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
array_ref sma(data,sma_dims);
const array_ref& csma = sma;
// FAIL! data() returns const int*.
*csma.data() = 0;
return boost::exit_success;
}

View File

@@ -0,0 +1,33 @@
// 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.
//
// fail_ref_citerator.cpp
// const_iterator/iterator conversion test
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {
typedef boost::multi_array_ref<int,3> array_ref;
typedef array_ref::iterator iterator1;
typedef array_ref::const_iterator citerator1;
// FAIL! ILLEGAL conversion from const_iterator to iterator
iterator1 in = citerator1();
return boost::exit_success;
}

View File

@@ -0,0 +1,44 @@
// 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.
//
// fail_ref_cparen.cpp
// Testing const operator() constness.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
array_ref sma(data,sma_dims);
const array_ref& csma = sma;
boost::array<array_ref::index,ndims> indices = {{0,0,0}};
// FAIL! cannot assign to a const multi_array_ref
csma(indices) = 5;
return boost::exit_success;
}

View File

@@ -0,0 +1,33 @@
// 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.
//
// fail_ref_criterator.cpp
// const_reverse_iterator/reverse_iterator conversion test
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {
typedef boost::multi_array_ref<int,3> array_ref;
typedef array_ref::reverse_iterator riterator1;
typedef array_ref::const_reverse_iterator criterator1;
// Fail! ILLEGAL conversion from const_reverse_iterator to reverse_iterator
riterator1 in = criterator1();
return boost::exit_success;
}

View File

@@ -0,0 +1,48 @@
// 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.
//
// fail_ref_csubarray.cpp -
// Testing subarray and const_subarray assignment
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {77,77,77,77,77,77,77,77,77,77,77,77,
77,77,77,77,77,77,77,77,77,77,77,77};
array_ref sma(data,sma_dims);
int num = 0;
for (array_ref::index i = 0; i != 2; ++i)
for (array_ref::index j = 0; j != 3; ++j)
for (array_ref::index k = 0; k != 4; ++k)
sma[i][j][k] = num++;
array_ref::const_subarray<ndims-1>::type csba = sma[0];
array_ref::subarray<ndims-1>::type sba = csba; // FAIL! preserve constness.
return boost::exit_success;
}

View File

@@ -0,0 +1,49 @@
// 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.
//
// fail_ref_csubarray2.cpp -
// Testing constness of subarray operations.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {77,77,77,77,77,77,77,77,77,77,77,77,
77,77,77,77,77,77,77,77,77,77,77,77};
array_ref sma(data,sma_dims);
int num = 0;
for (array_ref::index i = 0; i != 2; ++i)
for (array_ref::index j = 0; j != 3; ++j)
for (array_ref::index k = 0; k != 4; ++k)
sma[i][j][k] = num++;
const array_ref& sma_const = sma;
array_ref::subarray<ndims-1>::type sba = sma_const[0]; // FAIL!
// preserve constness
return boost::exit_success;
}

View File

@@ -0,0 +1,52 @@
// 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.
//
// fail_ref_csubarray3.cpp -
// Testing constness of subarray operations.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {77,77,77,77,77,77,77,77,77,77,77,77,
77,77,77,77,77,77,77,77,77,77,77,77};
array_ref sma(data,sma_dims);
int num = 0;
for (array_ref::index i = 0; i != 2; ++i)
for (array_ref::index j = 0; j != 3; ++j)
for (array_ref::index k = 0; k != 4; ++k)
sma[i][j][k] = num++;
const array_ref& sma_const = sma;
array_ref::const_subarray<ndims-1>::type sba = sma_const[0];
for (array_ref::index j = 0; j != 3; ++j)
for (array_ref::index k = 0; k != 4; ++k)
sba[j][k] = num++; // FAIL! can't assign to const_subarray.
return boost::exit_success;
}

View File

@@ -0,0 +1,62 @@
// 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.
//
// fail_ref_cview.cpp
// ensure const_array_view doesn't allow element assignment.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
array_ref sma(data,sma_dims);
//
// subarray dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
const array_ref& csma = sma;
typedef array_ref::index_range range;
array_ref::index_gen indices;
array_ref::const_array_view<ndims>::type csma2 =
csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];
boost::array<array_ref::index,3> elmt = {{0,0,0}};
csma2(elmt) = 5; // FAIL! csma is read only
return boost::exit_success;
}

View File

@@ -0,0 +1,63 @@
// 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.
//
// fail_ref_cview2.cpp
// ensure const_array_view cannot be converted to array_view
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
array_ref sma(data,sma_dims);
//
// subarray dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
const array_ref& csma = sma;
typedef array_ref::index_range range;
array_ref::index_gen indices;
array_ref::array_view<ndims>::type csma2 =
csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];
for (array_ref::index i = 0; i != 2; ++i)
for (array_ref::index j = 0; j != 2; ++j)
for (array_ref::index k = 0; k != 2; ++k)
csma2[i][j][k] = 0; // FAIL! csma2 is read only
return boost::exit_success;
}

View File

@@ -0,0 +1,64 @@
// 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.
//
// fail_ref_cview3.cpp -
// ensure const_array_view doesn't allow assignment.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array_ref<int,ndims> array_ref;
boost::array<array_ref::size_type,ndims> sma_dims = {{2,3,4}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
array_ref sma(data,sma_dims);
//
// subarray dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
const array_ref& csma = sma;
typedef array_ref::index_range range;
array_ref::index_gen indices;
array_ref::const_array_view<ndims>::type csma2 =
csma[indices[range(0,2)][range(1,3)][range(0,4,2)]];
for (array_ref::index i = 0; i != 2; ++i)
for (array_ref::index j = 0; j != 2; ++j)
for (array_ref::index k = 0; k != 2; ++k)
csma2[i][j][k] = 0; // FAIL! csma2 is read only.
return boost::exit_success;
}

View File

@@ -0,0 +1,285 @@
#ifndef GENERATIVE_TESTS_RG072001_HPP
#define GENERATIVE_TESTS_RG072001_HPP
// 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.
//
// generative-tests.hpp - Framework for running tests on all the types
// of multi_array
//
// In order to create a set of tests, you must define the following two
// function signatures:
// template <typename Array>
// void access(Array& A, const mutable_array_tag&);
//
// template <typename Array>
// void access(Array& A, const const_array_tag&);
//
// The framework will always pass 2x3x4 arrays into these functions.
// The const_array_tag version of access must NOT attempt to modify
// the array. Assume that the passed array has constness in this case.
//
// The mutable_array_tag version of access should pass the array to the
// assign() function in order to set its values before running tests.
//
// If you wish to write your own code to assign data to the array
// (ie. test the iterators by assigning data with them), you must
// #define MULTIARRAY_TEST_ASSIGN before including this file.
// assign() will call this function.
//
// If you wish to know how many tests were run, you must increment
// the global variable 'tests_run' somewhere in your test code.
//
// Since generative-tests uses the Boost.Test framework, you must
// define at least the following:
//
// int test_main(int,char*[]) { return run_generative_tests(); }
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include <boost/config.hpp> /* BOOST_NO_SFINAE */
#include <algorithm>
#include <iostream>
#include <vector>
namespace {
unsigned int tests_run = 0;
} // empty namespace
struct mutable_array_tag { };
struct const_array_tag { };
template <typename Array>
void assign_if_not_const(Array&, const const_array_tag&) {
// do nothing
}
template <typename Array>
void assign_if_not_const(Array& A, const mutable_array_tag&);
#ifndef MULTIARRAY_TEST_ASSIGN
template <typename Array>
void assign_if_not_const(Array& A, const mutable_array_tag&) {
typedef typename Array::index index;
const index idx0 = A.index_bases()[0];
const index idx1 = A.index_bases()[1];
const index idx2 = A.index_bases()[2];
int num = 0;
for (index i = idx0; i != idx0 + 2; ++i)
for (index j = idx1; j != idx1 + 3; ++j)
for (index k = idx2; k != idx2 + 4; ++k)
A[i][j][k] = num++;
}
#endif // MULTIARRAY_TEST_ASSIGN
template <typename Array>
void assign(Array& A) {
assign_if_not_const(A,mutable_array_tag());
}
template <typename Array>
void access(Array& A, const mutable_array_tag&);
template <typename Array>
void access(Array& A, const const_array_tag&);
template <typename StorageOrder3,typename StorageOrder4,typename Modifier>
int run_configuration(const StorageOrder3& so3,
const StorageOrder4& so4,
const Modifier& modifier) {
// multi_array
{
typedef boost::multi_array<int,3> array;
typename array::extent_gen extents;
{
array A(extents[2][3][4],so3);
modifier.modify(A);
access(A,mutable_array_tag());
}
}
// multi_array_ref
{
typedef boost::multi_array_ref<int,3> array_ref;
typename array_ref::extent_gen extents;
{
int local[24];
array_ref A(local,extents[2][3][4],so3);
modifier.modify(A);
access(A,mutable_array_tag());
}
}
// const_multi_array_ref
{
typedef boost::multi_array_ref<int,3> array_ref;
typedef boost::const_multi_array_ref<int,3> const_array_ref;
typename array_ref::extent_gen extents;
{
int local[24];
array_ref A(local,extents[2][3][4],so3);
modifier.modify(A);
assign(A);
const_array_ref B = A;
access(B,const_array_tag());
}
}
// sub_array
{
typedef boost::multi_array<int,4> array;
typename array::extent_gen extents;
{
array A(extents[2][2][3][4],so4);
modifier.modify(A);
typename array::template subarray<3>::type B = A[1];
access(B,mutable_array_tag());
}
}
// const_sub_array
{
typedef boost::multi_array<int,4> array;
typename array::extent_gen extents;
{
array A(extents[2][2][3][4],so4);
modifier.modify(A);
typename array::template subarray<3>::type B = A[1];
assign(B);
typename array::template const_subarray<3>::type C = B;
access(C,const_array_tag());
}
}
// array_view
{
typedef boost::multi_array<int,3> array;
typedef typename array::index_range range;
typename array::index_gen indices;
typename array::extent_gen extents;
{
typedef typename array::index index;
array A(extents[4][5][6],so3);
modifier.modify(A);
const index idx0 = A.index_bases()[0];
const index idx1 = A.index_bases()[1];
const index idx2 = A.index_bases()[2];
typename array::template array_view<3>::type B =A[
indices[range(idx0+1,idx0+3)]
[range(idx1+1,idx1+4)]
[range(idx2+1,idx2+5)]
];
access(B,mutable_array_tag());
}
}
// const_array_view
{
typedef boost::multi_array<int,3> array;
typedef typename array::index_range range;
typename array::index_gen indices;
typename array::extent_gen extents;
{
typedef typename array::index index;
array A(extents[4][5][6],so3);
modifier.modify(A);
const index idx0 = A.index_bases()[0];
const index idx1 = A.index_bases()[1];
const index idx2 = A.index_bases()[2];
typename array::template array_view<3>::type B =A[
indices[range(idx0+1,idx0+3)]
[range(idx1+1,idx1+4)]
[range(idx2+1,idx2+5)]
];
assign(B);
typename array::template const_array_view<3>::type C = B;
access(C,const_array_tag());
}
}
return boost::exit_success;
}
template <typename ArrayModifier>
int run_storage_tests(const ArrayModifier& modifier) {
run_configuration(boost::c_storage_order(),
boost::c_storage_order(),modifier);
run_configuration(boost::fortran_storage_order(),
boost::fortran_storage_order(),modifier);
std::size_t ordering[] = {2,0,1,3};
bool ascending[] = {false,true,true,true};
run_configuration(boost::general_storage_order<3>(ordering,ascending),
boost::general_storage_order<4>(ordering,ascending),
modifier);
return boost::exit_success;
}
struct null_modifier {
template <typename Array>
void modify(Array&) const { }
};
struct set_index_base_modifier {
template <typename Array>
void modify(Array& A) const {
#ifdef BOOST_NO_SFINAE
typedef boost::multi_array_types::index index;
A.reindex(index(1));
#else
A.reindex(1);
#endif
}
};
struct reindex_modifier {
template <typename Array>
void modify(Array& A) const {
boost::array<int,4> bases = {{1,2,3,4}};
A.reindex(bases);
}
};
struct reshape_modifier {
template <typename Array>
void modify(Array& A) const {
typedef typename Array::size_type size_type;
std::vector<size_type> old_shape(A.num_dimensions());
std::vector<size_type> new_shape(A.num_dimensions());
std::copy(A.shape(),A.shape()+A.num_dimensions(),old_shape.begin());
std::copy(old_shape.rbegin(),old_shape.rend(),new_shape.begin());
A.reshape(new_shape);
A.reshape(old_shape);
}
};
int run_generative_tests() {
run_storage_tests(null_modifier());
run_storage_tests(set_index_base_modifier());
run_storage_tests(reindex_modifier());
run_storage_tests(reshape_modifier());
std::cout << "Total Tests Run: " << tests_run << '\n';
return boost::exit_success;
}
#endif // GENERATIVE_TESTS_RG072001_HPP

View File

@@ -0,0 +1,81 @@
// 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.
//
// idxset1.cpp - testing the code for index_gen
//
#include "boost/multi_array/index_gen.hpp"
#include "boost/multi_array/index_range.hpp"
#include "boost/multi_array/types.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
typedef boost::detail::multi_array::index index_type;
typedef boost::detail::multi_array::size_type size_type;
typedef boost::detail::multi_array::index_range<index_type,size_type> range;
template <int NumRanges, int NumDims>
void check(const boost::detail::multi_array::
index_gen<NumRanges,NumDims>&) { }
bool operator==(const range& lhs,const range& rhs) {
return lhs.start_ == rhs.start_ &&
lhs.finish_ == rhs.finish_ &&
lhs.stride_ == rhs.stride_ &&
lhs.degenerate_ == rhs.degenerate_;
}
int
test_main(int,char*[])
{
boost::detail::multi_array::index_gen<0,0> indices;
check<1,1>(indices[range()]);
check<2,2>(indices[range()][range()]);
check<3,3>(indices[range()][range()][range()]);
check<1,0>(indices[0]);
check<2,0>(indices[0][0]);
check<2,1>(indices[range()][0]);
check<2,1>(indices[0][range()]);
check<3,0>(indices[0][0][0]);
check<3,1>(indices[range()][0][0]);
check<3,1>(indices[0][range()][0]);
check<3,1>(indices[0][0][range()]);
check<3,2>(indices[range()][range()][0]);
check<3,2>(indices[range()][0][range()]);
check<3,2>(indices[0][range()][range()]);
{
boost::detail::multi_array::index_gen<3,3> is1 =
indices[range(0,1,2)][range(1,2,3)][range(2,3,4)];
BOOST_CHECK(is1.ranges_[0] == range(0,1,2));
BOOST_CHECK(is1.ranges_[1] == range(1,2,3));
BOOST_CHECK(is1.ranges_[2] == range(2,3,4));
}
{
boost::detail::multi_array::index_gen<3,2> is2 =
indices[range(0,1,2)][2][range(2,3,4)];
BOOST_CHECK(is2.ranges_[0] == range(0,1,2));
BOOST_CHECK(is2.ranges_[1] == range(2));
BOOST_CHECK(is2.ranges_[1].is_degenerate());
BOOST_CHECK(is2.ranges_[2] == range(2,3,4));
}
return boost::exit_success;
}

View File

@@ -0,0 +1,153 @@
// 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.
//
// index_bases - test of the index_base modifying facilities.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include <vector>
#include <iostream>
int
test_main(int,char*[])
{
typedef boost::multi_array<double, 3> array;
typedef boost::multi_array_ref<double, 3> array_ref;
typedef boost::const_multi_array_ref<double, 3> const_array_ref;
typedef array::array_view<3>::type array_view;
typedef array::size_type size_type;
typedef array::extent_range range;
typedef array::index_range irange;
array::extent_gen extents;
array::index_gen indices;
// Construct with nonzero bases
{
array A(extents[range(1,4)][range(2,5)][range(3,6)]);
array B(extents[3][3][3]);
double ptr[27];
array_ref
C(ptr,extents[range(1,4)][range(2,5)][range(3,6)]);
const_array_ref
D(ptr,extents[range(1,4)][range(2,5)][range(3,6)]);
array_view E = A[indices[irange()][irange()][irange()]];
std::vector<double> vals;
for (int i = 0; i < 27; ++i)
vals.push_back(i);
A.assign(vals.begin(),vals.end());
B.assign(vals.begin(),vals.end());
C.assign(vals.begin(),vals.end());
boost::array<int,3> bases = { { 1, 2, 3 } };
for (size_type a = 0; a < A.shape()[0]; ++a)
for (size_type b = 0; b < A.shape()[1]; ++b)
for (size_type c = 0; c < A.shape()[2]; ++c) {
BOOST_CHECK(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
// Test that E does not inherit A's index_base
BOOST_CHECK(E[a][b][c] == B[a][b][c]);
}
}
// Reindex
{
typedef array::size_type size_type;
array A(extents[3][3][3]), B(extents[3][3][3]);
double ptr[27];
array_ref C(ptr,extents[3][3][3]);
const_array_ref D(ptr,extents[3][3][3]);
array_view E = B[indices[irange()][irange()][irange()]];
std::vector<double> vals;
for (int i = 0; i < 27; ++i)
vals.push_back(i);
A.assign(vals.begin(),vals.end());
B.assign(vals.begin(),vals.end());
C.assign(vals.begin(),vals.end());
boost::array<int,3> bases = { { 1, 2, 3 } };
A.reindex(bases);
C.reindex(bases);
D.reindex(bases);
E.reindex(bases);
for (size_type a = 0; a < A.shape()[0]; ++a)
for (size_type b = 0; b < A.shape()[1]; ++b)
for (size_type c = 0; c < A.shape()[2]; ++c) {
BOOST_CHECK(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(E[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
}
}
// Set Index Base
{
typedef array::size_type size_type;
array A(extents[3][3][3]), B(extents[3][3][3]);
double ptr[27];
array_ref C(ptr,extents[3][3][3]);
const_array_ref D(ptr,extents[3][3][3]);
array_view E = B[indices[irange()][irange()][irange()]];
std::vector<double> vals;
for (int i = 0; i < 27; ++i)
vals.push_back(i);
A.assign(vals.begin(),vals.end());
B.assign(vals.begin(),vals.end());
C.assign(vals.begin(),vals.end());
#ifdef BOOST_NO_SFINAE
typedef boost::multi_array_types::index index;
A.reindex(index(1));
C.reindex(index(1));
D.reindex(index(1));
E.reindex(index(1));
#else
A.reindex(1);
C.reindex(1);
D.reindex(1);
E.reindex(1);
#endif
for (size_type a = 0; a < A.shape()[0]; ++a)
for (size_type b = 0; b < A.shape()[1]; ++b)
for (size_type c = 0; c < A.shape()[2]; ++c) {
BOOST_CHECK(A[a+1][b+1][c+1] == B[a][b][c]);
BOOST_CHECK(C[a+1][b+1][c+1] == B[a][b][c]);
BOOST_CHECK(D[a+1][b+1][c+1] == B[a][b][c]);
BOOST_CHECK(E[a+1][b+1][c+1] == B[a][b][c]);
}
}
return boost::exit_success;
}

View File

@@ -0,0 +1,188 @@
// 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.
//
// iterators.cpp - checking out iterator stuffs.
// The tests assume that the array has shape 2x3x4
//
#define MULTIARRAY_TEST_ASSIGN
#include "generative_tests.hpp"
#include "boost/concept_check.hpp" // for ignore_unused_variable_warning
#include "boost/mpl/if.hpp"
#include "boost/type_traits/is_same.hpp"
// iterator-test-specific code
template <typename Array>
void assign_if_not_const(Array& A, const mutable_array_tag&) {
typedef typename Array::iterator iterator3;
typedef typename Array::template subarray<2>::type::iterator iterator2;
typedef typename Array::template subarray<1>::type::iterator iterator1;
int num = 0;
for (iterator3 i = A.begin(); i != A.end(); ++i)
for(iterator2 ii = (*i).begin(); ii != (*i).end(); ++ii)
for(iterator1 iii = (*ii).begin(); iii != (*ii).end(); ++iii)
*iii = num++;
}
template <typename Array>
struct ittraits_const {
typedef typename Array::const_iterator iterator3;
typedef typename boost::subarray_gen<Array,2>::type::const_iterator
iterator2;
typedef typename boost::subarray_gen<Array,1>::type::const_iterator
iterator1;
typedef typename Array::const_reverse_iterator riterator3;
typedef typename boost::subarray_gen<Array,2>::type::const_reverse_iterator
riterator2;
typedef typename boost::subarray_gen<Array,1>::type::const_reverse_iterator
riterator1;
};
template <typename Array>
struct ittraits_mutable {
typedef typename Array::iterator iterator3;
typedef typename boost::subarray_gen<Array,2>::type::iterator iterator2;
typedef typename boost::subarray_gen<Array,1>::type::iterator iterator1;
typedef typename Array::reverse_iterator riterator3;
typedef typename boost::subarray_gen<Array,2>::type::reverse_iterator
riterator2;
typedef typename boost::subarray_gen<Array,1>::type::reverse_iterator
riterator1;
};
// Meta-program chooses ittraits implementation.
template <typename Array, typename ConstTag>
struct ittraits_generator :
boost::mpl::if_< boost::is_same<ConstTag,const_array_tag>,
ittraits_const<Array>,
ittraits_mutable<Array> >
{};
template <typename Array>
void construct_iterators(Array&) {
// Default constructed iterators and
// const iterators constructed from iterators.
{
typename Array::iterator i1;
typename Array::const_iterator ci1;
typename Array::reverse_iterator r1;
typename Array::const_reverse_iterator cr1;
#if 0 // RG - MSVC fails to compile these
typename Array::const_iterator ci2 =
typename Array::iterator();
typename Array::const_reverse_iterator cr2 =
typename Array::reverse_iterator();
#endif
typename Array::const_iterator ci2 = i1;
typename Array::const_reverse_iterator cr2 = cr1;
boost::ignore_unused_variable_warning(cr2);
}
}
template <typename Array, typename IterTraits>
void test_iterators(Array& A, const IterTraits&) {
// Iterator comparison and arithmetic
{
typedef typename IterTraits::iterator3 iterator;
iterator i1 = A.begin();
iterator i2 = A.end();
BOOST_CHECK(i1 < i2);
BOOST_CHECK((i2 - i1) == typename iterator::difference_type(2));
}
// Standard Array Iteration
{
typedef typename IterTraits::iterator3 iterator3;
typedef typename IterTraits::iterator2 iterator2;
typedef typename IterTraits::iterator1 iterator1;
int vals = 0;
for (iterator3 i = A.begin(); i != A.end(); ++i)
for(iterator2 ii = (*i).begin(); ii != (*i).end(); ++ii)
for(iterator1 iii = (*ii).begin(); iii != (*ii).end(); ++iii)
BOOST_CHECK(*iii == vals++);
}
// Using operator->() on iterators
{
typedef typename IterTraits::iterator3 iterator3;
typedef typename IterTraits::iterator2 iterator2;
typedef typename IterTraits::iterator1 iterator1;
int vals = 0;
for (iterator3 i = A.begin(); i != A.end(); ++i)
for(iterator2 ii = i->begin(); ii != i->end(); ++ii)
for(iterator1 iii = ii->begin(); iii != ii->end(); ++iii)
BOOST_CHECK(*iii == vals++);
}
// Reverse Iterator Hierarchy Test
{
typedef typename IterTraits::riterator3 riterator3;
typedef typename IterTraits::riterator2 riterator2;
typedef typename IterTraits::riterator1 riterator1;
int check_iter_val = A.num_elements()-1;
for (riterator3 i = A.rbegin(); i != (riterator3)A.rend(); ++i)
for(riterator2 ii = (*i).rbegin(); ii != (riterator2)(*i).rend(); ++ii)
for(riterator1 iii = (*ii).rbegin(); iii != (riterator1)(*ii).rend();
++iii)
BOOST_CHECK(*iii == check_iter_val--);
}
++tests_run;
}
template <typename Array>
void access(Array& A, const mutable_array_tag&) {
assign(A);
construct_iterators(A);
typedef typename ittraits_generator<Array,mutable_array_tag>::type
m_iter_traits;
typedef typename ittraits_generator<Array,const_array_tag>::type
c_iter_traits;
test_iterators(A,m_iter_traits());
test_iterators(A,c_iter_traits());
const Array& CA = A;
test_iterators(CA,c_iter_traits());
}
template <typename Array>
void access(Array& A, const const_array_tag&) {
construct_iterators(A);
typedef typename ittraits_generator<Array,const_array_tag>::type
c_iter_traits;
test_iterators(A,c_iter_traits());
}
int
test_main(int, char*[])
{
return run_generative_tests();
}

View File

@@ -0,0 +1,105 @@
// 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.
//
// range1.cpp - test of index_range
//
#include "boost/multi_array/index_range.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include <cstddef>
int
test_main(int,char*[])
{
typedef boost::detail::multi_array::index_range<int,std::size_t> range;
{
// typical range creation and extraction
range r1(-3,5);
BOOST_CHECK(r1.start() == -3);
BOOST_CHECK(r1.finish() == 5);
BOOST_CHECK(r1.stride() == 1);
BOOST_CHECK(!r1.is_degenerate());
BOOST_CHECK(r1.get_start(0) == -3);
BOOST_CHECK(r1.get_finish(100) == 5);
}
{
range r2(-3,5,2);
BOOST_CHECK(r2.start() == -3);
BOOST_CHECK(r2.finish() == 5);
BOOST_CHECK(r2.stride() == 2);
BOOST_CHECK(!r2.is_degenerate());
}
{
// degenerate creation
range r3(5);
BOOST_CHECK(r3.start() == 5);
BOOST_CHECK(r3.finish() == 6);
BOOST_CHECK(r3.stride() == 1);
BOOST_CHECK(r3.is_degenerate());
}
{
// default range creation
range r4;
BOOST_CHECK(r4.get_start(0) == 0);
BOOST_CHECK(r4.get_finish(100) == 100);
BOOST_CHECK(r4.stride() == 1);
}
{
// create a range using the setter methods
range r5 = range().stride(2).start(-3).finish(7);
BOOST_CHECK(r5.start() == -3);
BOOST_CHECK(r5.stride() == 2);
BOOST_CHECK(r5.finish() == 7);
}
// try out all the comparison operators
{
range r6 = -3 <= range().stride(2) < 7;
BOOST_CHECK(r6.start() == -3);
BOOST_CHECK(r6.stride() == 2);
BOOST_CHECK(r6.finish() == 7);
}
{
range r7 = -3 < range() <= 7;
BOOST_CHECK(r7.start() == -2);
BOOST_CHECK(r7.stride() == 1);
BOOST_CHECK(r7.finish() == 8);
}
// arithmetic operators
{
range r8 = range(0,5) + 2;
BOOST_CHECK(r8.start() == 2);
BOOST_CHECK(r8.stride() == 1);
BOOST_CHECK(r8.finish() == 7);
}
{
range r9 = range(0,5) - 2;
BOOST_CHECK(r9.start() == -2);
BOOST_CHECK(r9.stride() == 1);
BOOST_CHECK(r9.finish() == 3);
}
return boost::exit_success;
}

View File

@@ -0,0 +1,38 @@
// Regression suite file for boost::multi_array
run libs/multi_array/test/constructors.cpp
run libs/multi_array/test/access.cpp
run libs/multi_array/test/compare.cpp
run libs/multi_array/test/iterators.cpp
run libs/multi_array/test/slice.cpp
run libs/multi_array/test/assign.cpp
run libs/multi_array/test/index_bases.cpp
run libs/multi_array/test/storage_order.cpp
run libs/multi_array/test/reshape.cpp
run libs/multi_array/test/range1.cpp
run libs/multi_array/test/idxgen1.cpp
run libs/multi_array/test/stl_interaction.cpp
compile libs/multi_array/test/concept_checks.cpp
compile-fail libs/multi_array/test/fail_cbracket.cpp
compile-fail libs/multi_array/test/fail_cdata.cpp
compile-fail libs/multi_array/test/fail_citerator.cpp
compile-fail libs/multi_array/test/fail_cparen.cpp
compile-fail libs/multi_array/test/fail_criterator.cpp
compile-fail libs/multi_array/test/fail_csubarray.cpp
compile-fail libs/multi_array/test/fail_csubarray2.cpp
compile-fail libs/multi_array/test/fail_csubarray3.cpp
compile-fail libs/multi_array/test/fail_cview.cpp
compile-fail libs/multi_array/test/fail_cview2.cpp
compile-fail libs/multi_array/test/fail_cview3.cpp
compile-fail libs/multi_array/test/fail_ref_cbracket.cpp
compile-fail libs/multi_array/test/fail_ref_cdata.cpp
compile-fail libs/multi_array/test/fail_ref_citerator.cpp
compile-fail libs/multi_array/test/fail_ref_cparen.cpp
compile-fail libs/multi_array/test/fail_ref_criterator.cpp
compile-fail libs/multi_array/test/fail_ref_csubarray.cpp
compile-fail libs/multi_array/test/fail_ref_csubarray2.cpp
compile-fail libs/multi_array/test/fail_ref_csubarray3.cpp
compile-fail libs/multi_array/test/fail_ref_cview.cpp
compile-fail libs/multi_array/test/fail_ref_cview2.cpp
compile-fail libs/multi_array/test/fail_ref_cview3.cpp

View File

@@ -0,0 +1,97 @@
// 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.
//
// reshape.cpp - testing reshaping functionality
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
int
test_main(int,char*[])
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
typedef boost::multi_array_ref<int,ndims> array_ref;
typedef boost::const_multi_array_ref<int,ndims> const_array_ref;
boost::array<array::size_type,ndims> dims = {{2,3,4}};
boost::array<array::size_type,ndims> new_dims = {{4,3,2}};
int data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,
14,15,16,17,18,19,20,21,22,23};
const int data_size=24;
// Basic reshape test
{
array A(dims);
A.assign(data,data+data_size);
array_ref B(data,dims);
const_array_ref C(data,dims);
A.reshape(new_dims);
B.reshape(new_dims);
C.reshape(new_dims);
int* ptr = data;
for (array::index i = 0; i != 4; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 2; ++k) {
BOOST_CHECK(A[i][j][k] == *ptr);
BOOST_CHECK(B[i][j][k] == *ptr);
BOOST_CHECK(C[i][j][k] == *ptr++);
}
}
// Ensure that index bases are preserved over reshape
{
boost::array<array::index,ndims> bases = {{0, 1, -1}};
array A(dims);
A.assign(data,data+data_size);
array_ref B(data,dims);
const_array_ref C(data,dims);
A.reindex(bases);
B.reindex(bases);
C.reindex(bases);
A.reshape(new_dims);
B.reshape(new_dims);
C.reshape(new_dims);
int* ptr = data;
for (array::index i = 0; i != 4; ++i)
for (array::index j = 1; j != 4; ++j)
for (array::index k = -1; k != 1; ++k) {
BOOST_CHECK(A[i][j][k] == *ptr);
BOOST_CHECK(B[i][j][k] == *ptr);
BOOST_CHECK(C[i][j][k] == *ptr++);
}
}
return boost::exit_success;
}

View File

@@ -0,0 +1,127 @@
// 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.
//
// resize.cpp - Test of resizing multi_arrays
//
#include "boost/test/minimal.hpp"
#include "boost/multi_array.hpp"
#include <iostream>
using namespace std;
int test_main(int,char*[]) {
typedef boost::multi_array<int,3> marray;
int A_data[] = {
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 A_resize[] = {
0,1,
4,5,
8,9,
12,13,
16,17,
20,21,
0,0,
0,0,
0,0,
0,0,
0,0,
0,0
};
// resize through the extent_gen interface
{
marray A(boost::extents[2][3][4]);
A.assign(A_data,A_data+(2*3*4));
A.resize(boost::extents[4][3][2]);
BOOST_CHECK(std::equal(A_resize,A_resize+(4*3*2),A.data()));
}
// resize through the Collection
{
marray A(boost::extents[2][3][4]);
A.assign(A_data,A_data+(2*3*4));
boost::array<int,3> new_extents = {{4,3,2}};
A.resize(new_extents);
BOOST_CHECK(std::equal(A_resize,A_resize+(4*3*2),A.data()));
}
// default construct all the new elements (in this case, all elements)
{
marray defaultA;
defaultA.resize(boost::extents[2][3][4]);
BOOST_CHECK(std::accumulate(defaultA.data(),
defaultA.data()+(2*3*4),0) == 0);
}
// verify the preservation of storage order
{
int tiling_graph_storage_order[] = {2, 0, 1};
bool tiling_graph_index_order[] = {true, true, true};
marray A(boost::extents[3][4][2],
boost::general_storage_order<3>(tiling_graph_storage_order,
tiling_graph_index_order));
int value = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 2; k++) {
*(A.data() + value) = value;
++value;
}
}
}
// "Resize" to the same size
A.resize(boost::extents[3][4][2]);
int check = 0;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 4; y++) {
for (int z = 0; z < 2; z++) {
BOOST_CHECK(*(A.data() + check) == check);
++check;
}
}
}
}
// Resizing that changes index bases too (impl bug caused an assert)
{
typedef boost::multi_array<int, 1> ar_t;
typedef ar_t::extent_range range;
ar_t ar;
ar.resize(boost::extents[range(-3, 3)]);
}
return boost::exit_success;
}

View File

@@ -0,0 +1,43 @@
// 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.
//
// reverse_view.cpp - a small test of creating a view with negative strides
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
using namespace boost;
// One-dimensional array with views
double data[] = { 1, 2, 3, 4 };
double rdata[] = { 4, 3, 2, 1 };
typedef multi_array< double, 1 > array;
array A(extents[4]);
A.assign(data,data+4);
typedef array::index_range range;
array::array_view<1>::type B = A[indices[range(3, -1, -1)]];
for(multi_array_types::size_type i = 0; i != B.size(); ++i) {
BOOST_CHECK(B[i] == rdata[i]);
}
return boost::exit_success;
}

View File

@@ -0,0 +1,146 @@
// 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.
//
// slice.cpp - testing out slicing on a matrices
//
#include "generative_tests.hpp"
#include "boost/array.hpp"
#include "boost/mpl/if.hpp"
#include "boost/type_traits/is_same.hpp"
template <typename Array>
struct view_traits_mutable {
public:
#if 0 // RG - MSVC can't handle templates nested in templates. Use traits
typedef typename Array::template array_view<3>::type array_view3;
typedef typename Array::template array_view<2>::type array_view2;
#endif
typedef typename boost::array_view_gen<Array,3>::type array_view3;
typedef typename boost::array_view_gen<Array,2>::type array_view2;
};
template <typename Array>
struct view_traits_const {
#if 0 // RG - MSVC can't handle templates nested in templates. Use traits
typedef typename Array::template const_array_view<3>::type array_view3;
typedef typename Array::template const_array_view<2>::type array_view2;
#endif
typedef typename boost::const_array_view_gen<Array,3>::type array_view3;
typedef typename boost::const_array_view_gen<Array,2>::type array_view2;
};
// Meta-program selects the proper view_traits implementation.
template <typename Array, typename ConstTag>
struct view_traits_generator :
boost::mpl::if_< boost::is_same<ConstTag,const_array_tag>,
view_traits_const<Array>,
view_traits_mutable<Array> >
{};
template <typename Array, typename ViewTraits>
void test_views(Array& A, const ViewTraits&) {
typedef typename Array::index index;
typedef typename Array::index_range range;
typename Array::index_gen indices;
const index idx0 = A.index_bases()[0];
const index idx1 = A.index_bases()[1];
const index idx2 = A.index_bases()[2];
// Standard View
{
typename ViewTraits::array_view3 B = A[
indices[range(idx0+0,idx0+2)]
[range(idx1+1,idx1+3)]
[range(idx2+0,idx2+4,2)]
];
for (index i = 0; i != 2; ++i)
for (index j = 0; j != 2; ++j)
for (index k = 0; k != 2; ++k) {
BOOST_CHECK(B[i][j][k] == A[idx0+i][idx1+j+1][idx2+k*2]);
boost::array<index,3> elmts;
elmts[0]=i; elmts[1]=j; elmts[2]=k;
BOOST_CHECK(B(elmts) == A[idx0+i][idx1+j+1][idx2+k*2]);
}
}
// Degenerate dimensions
{
typename ViewTraits::array_view2 B =
A[indices[range(idx0+0,idx0+2)][idx1+1][range(idx2+0,idx2+4,2)]];
for (index i = 0; i != 2; ++i)
for (index j = 0; j != 2; ++j) {
BOOST_CHECK(B[i][j] == A[idx0+i][idx1+1][idx2+j*2]);
boost::array<index,2> elmts;
elmts[0]=i; elmts[1]=j;
BOOST_CHECK(B(elmts) == A[idx0+i][idx1+1][idx2+j*2]);
}
}
// Flip the third dimension
{
typename ViewTraits::array_view3 B = A[
indices[range(idx0+0,idx0+2)]
[range(idx1+0,idx1+2)]
[range(idx2+2,idx2+0,-1)]
];
// typename ViewTraits::array_view3 B =
// A[indices[range(idx0+0,idx0+2)][idx1+1][range(idx2+0,idx2+4,2)]];
for (index i = 0; i != 2; ++i)
for (index j = 0; j != 2; ++j)
for (index k = 0; k != 2; ++k) {
BOOST_CHECK(B[i][j][k] == A[idx0+i][idx1+j][idx2+2-k]);
boost::array<index,3> elmts;
elmts[0]=i; elmts[1]=j; elmts[2]=k;
BOOST_CHECK(B(elmts) == A[idx0+i][idx1+j][idx2+2-k]);
}
}
++tests_run;
}
template <typename Array>
void access(Array& A, const mutable_array_tag&) {
assign(A);
typedef typename view_traits_generator<Array,mutable_array_tag>::type
m_view_traits;
typedef typename view_traits_generator<Array,const_array_tag>::type
c_view_traits;
test_views(A,m_view_traits());
test_views(A,c_view_traits());
const Array& CA = A;
test_views(CA,c_view_traits());
}
template <typename Array>
void access(Array& A, const const_array_tag&) {
typedef typename view_traits_generator<Array,const_array_tag>::type
c_view_traits;
test_views(A,c_view_traits());
}
int test_main(int,char*[]) {
return run_generative_tests();
}

View File

@@ -0,0 +1,72 @@
// 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.
//
// stl_interaction.cpp - Make sure multi_arrays work with STL containers.
//
#include "boost/test/minimal.hpp"
#include "boost/multi_array.hpp"
#include <algorithm>
#include <vector>
int
test_main(int, char*[])
{
using boost::extents;
using boost::indices;
typedef boost::multi_array_types::index_range range;
typedef boost::multi_array<int,3> array3;
typedef boost::multi_array<int,2> array2;
typedef std::vector<array3> array3vec;
int data[] = {
0,1,2,3,
4,5,6,7,
8,9,10,11,
12,13,14,15,
16,17,18,19,
20,21,22,23
};
const int data_size = 24;
int insert[] = {
99,98,
97,96,
};
const int insert_size = 4;
array3 myarray(extents[2][3][4]);
myarray.assign(data,data+data_size);
array3vec myvec(5,myarray);
BOOST_CHECK(myarray == myvec[1]);
array3::array_view<2>::type myview =
myarray[indices[1][range(0,2)][range(1,3)]];
array2 filler(extents[2][2]);
filler.assign(insert,insert+insert_size);
// Modify a portion of myarray through a view (myview)
myview = filler;
myvec.push_back(myarray);
BOOST_CHECK(myarray != myvec[1]);
BOOST_CHECK(myarray == myvec[5]);
return boost::exit_success;
}

View File

@@ -0,0 +1,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/test/minimal.hpp"
#include "boost/array.hpp"
int
test_main(int,char*[])
{
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_CHECK(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_CHECK(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_CHECK(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_CHECK(A[i][j][k] == *num++);
}
return boost::exit_success;
}

View File

@@ -0,0 +1,39 @@
// 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.
//
// test out my new storage_order stuff
//
#include "boost/test/minimal.hpp"
#include "boost/multi_array/storage_order.hpp"
int
test_main(int,char*[]) {
using namespace boost;
array<std::size_t,5> c_ordering = {{4,3,2,1,0}};;
array<std::size_t,5> fortran_ordering = {{0,1,2,3,4}};
array<bool,5> ascending = {{true,true,true,true,true}};
general_storage_order<5> c_storage(c_ordering.begin(),
ascending.begin());
general_storage_order<5> fortran_storage(fortran_ordering.begin(),
ascending.begin());
BOOST_CHECK(c_storage == (general_storage_order<5>) c_storage_order());
BOOST_CHECK(fortran_storage ==
(general_storage_order<5>) fortran_storage_order());
return boost::exit_success;
}

View File

@@ -0,0 +1,44 @@
// 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.
//
// index_bases - test of the index_base modifying facilities.
//
#include "boost/multi_array.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include <vector>
#include <iostream>
int
test_main(int,char*[])
{
typedef boost::multi_array<double, 3> array;
typedef array::array_view<3>::type array_view;
typedef array::extent_range erange;
typedef array::index_range irange;
array::extent_gen extents;
array::index_gen indices;
// Construct with nonzero bases
{
array A(extents[erange(1,4)][erange(2,5)][erange(3,6)]);
array_view E = A[indices[irange(1,2)][irange(1,2)][irange(1,2)]];
}
return boost::exit_success;
}