[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,15 @@
# Copyright (c) 2016 Rene Rivera
#
# Distributed under 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)
###############################################################################
alias boostdoc
: xml/bbref.xml
:
:
: ;
explicit boostdoc ;
alias boostrelease ;
explicit boostrelease ;

View File

@@ -0,0 +1,58 @@
<html>
<!--
== 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.
-->
<head>
<title>MultiDimensional Array Libary</title></head>
<body bgcolor="#ffffff" text="#000000">
<table border="1" bgcolor="#007f7f" cellpadding="2">
<tbody><tr>
<td bgcolor="#ffffff">
<img src="../../../boost.png" alt="boost logo"
width="277" align="middle" height="86"></td>
<td><a href="../../../index.htm"><font face="Arial" color="#ffffff"><big>Home</big></font></a></td>
<td><a href="../../../libs/libraries.htm"><font face="Arial" color="#ffffff"><big>Libraries</big></font></a></td>
<td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color="#ffffff"><big>People</big></font></a></td>
<td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color="#ffffff"><big>FAQ</big></font></a></td>
<td><a href="../../../more/index.htm"><font face="Arial" color="#ffffff"><big>More</big></font></a></td>
</tr>
</tbody></table>
<h1>Boost.MultiArray</h1>
<p>Boost.MultiArray provides a generic N-dimensional array concept
definition and common implementations of that interface.
</p>
<ul>
<li><a href="./user.html">User Documentation and Tutorial</a> </li>
<li><a href="./reference.html">Reference Documentation</a> </li>
<li><a href="./test_cases.html">Test Cases and their Descriptions</a> </li>
<li><a href="./notes.html">Miscellaneous Notes</a> </li>
</ul>
<br>
<hr>
<table>
<tr valign=top>
<td nowrap>Copyright &copy 2000-2001</td><td>
<a href="http://www.osl.iu.edu/~garcia">Ronald Garcia</a>,
Indiana University (<a
HREF="mailto:garcia@osl.iu.edu">garcia@osl.iu.edu</a>)<br>
<a href="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
Indiana University (<a
HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</a>)<br>
<a href="http://www.osl.iu.edu/~lums">Andrew Lumsdaine</a>,
Indiana University (<a
HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</a>)
</td></tr></table>
</body></html>

View File

@@ -0,0 +1,797 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><!-- saved from url=(0022)http://internet.e-mail --><title>Improved Iterator Categories and Requirements</title>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
<meta content="Microsoft FrontPage 5.0" name="GENERATOR"></head>
<body bgcolor="#ffffff">
<p align="right">
<table border="0">
<tbody>
<tr>
<td width="125">
<p align="right">Document number: </p></td>
<td width="190">
<p>J16/01-0011 = WG21 N1297 </p></td></tr>
<tr>
<td width="125">
<p align="right">Date: </p></td>
<td width="190">
<p>March 21, 2001 </p></td></tr>
<tr>
<td width="125">
<p align="right">Author: </p></td>
<td width="190">
<p>Jeremy Siek, <br>University of Notre Dame </p></td></tr>
<tr>
<td width="125">
<p></p></td>
<td width="190">
<p><a href="mailto:jsiek@lsc.nd.edu">jsiek@lsc.nd.edu</a>
</p></td></tr></tbody></table></p>
<h1>
<center>Improved Iterator Categories and Requirements</center></h1>
<h2>Introduction</h2>The standard iterator categories and requirements are
flawed because they use a single hierarchy of requirements to address two
orthogonal issues: <b><i>iterator traversal</i></b> and <b><i>dereference return
type</i></b>. The current iterator requirement hierarchy is mainly geared
towards iterator traversal (hence the category names), while requirements that
address dereference return type sneak in at various places. The following table
gives a summary of the current dereference return type requirements in the
iterator categories.
<p>
</p><center>
<a name="table:1">
<b>Table 1.</b> Summary of current dereference return type
requirements.</a><table border="1">
<tbody>
<tr>
<td>Output Iterator</td>
<td><tt>*i = a</tt> </td></tr>
<tr>
<td>Input Iterator</td>
<td><tt>*i</tt> is convertible to <tt>T</tt></td></tr>
<tr>
<td>Forward Iterator</td>
<td><tt>*i</tt> is <tt>T&amp;</tt> (or <tt>const T&amp;</tt> once <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#200">issue
200</a> is resolved)</td></tr>
<tr>
<td>Random Access Iterator</td>
<td><tt>i[n]</tt> is convertible to <tt>T</tt> (which is odd because the
operational semantics say <tt>i[n]</tt> is equivalent to <tt>*(i + n)</tt>
which would have a return type of <tt>T&amp;</tt>) </td></tr></tbody></table></center>
<h2>Examples of useful iterators that do not ``fit''</h2>
<p>Because of the mixing of iterator traversal and dereference return type, many
useful iterators can not be appropriately categorized. For example,
<tt>vector&lt;bool&gt;::iterator</tt> is almost a random access iterator, but
the return type is not <tt>bool&amp;</tt> (see <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#96">issue
96</a> and Herb Sutter's paper J16/99-0008 = WG21 N1185). Therefore, the
iterators only meet the requirements of input iterator and output iterator. This
is so nonintuitive that at least one implementation erroneously assigns
<tt>random_access_iterator_tag</tt> as its <tt>iterator_category</tt>. Also,
<tt>vector&lt;bool&gt;</tt> is not the only example of useful iterators that do
not return true references: there is the often cited example of disk-based
collections.
</p><p>Another example is a counting iterator, an iterator the returns a sequence of
integers when incremented and dereferenced (see <a href="http://www.boost.org/libs/iterator/doc/counting_iterator.html"><tt>boost::counting_iterator</tt></a>).
There are two ways to implement this iterator, 1) make the <tt>reference</tt>
type be a true reference (a reference to an integer data member of the counting
iterator) or 2) make the <tt>reference</tt> type be the same as the
<tt>value_type</tt>. Option 1) runs into the problems discussed in <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#198">Issue
198</a>, the reference will not be valid after the iterator is destroyed. Option
2) is therefore a better choice, but then we have a counting iterator that
cannot be a random access iterator.
</p><p>Yet another example is a transform iterator, an iterator adaptor that applies
a unary function object to the dereference value of the wrapped iterator (see <a href="http://www.boost.org/libs/iterator/doc/transform_iterator.html"><tt>boost::transform_iterator</tt></a>).
For unary functions such as <tt>std::times</tt> the return type of
<tt>operator*</tt> clearly needs to be the <tt>result_type</tt> of the function
object, which is typically not a reference. However, with the current iterator
requirements, if you wrap <tt>int*</tt> with a transform iterator, you do not
get a random access iterator as expected, but an input iterator.
</p><p>A fourth example is found in the vertex and edge iterators of the <a href="http://www.boost.org/libs/graph/doc/table_of_contents.html">Boost Graph
Library</a>. These iterators return vertex and edge descriptors, which are
lightweight handles created on-the-fly. They must be returned by-value. As a
result, their current standard iterator category is
<tt>std::input_iterator_tag</tt>, which means that, strictly speaking, you could
not use these iterators with algorithms like <tt>std::min_element()</tt>. As a
temporary solution, we introduced the concept <a href="http://www.boost.org/libs/utility/MultiPassInputIterator.html">Multi-Pass
Input Iterator</a> to describe the vertex and edge descriptors, but as the
design notes for concept suggest, a better solution is needed.
</p><p>In short, there are many useful iterators that do not fit into the current
standard iterator categories. As a result, the following bad things happen:
</p><ul>
<li>Iterators are often miss-categorized.
</li><li>Algorithm requirements are more strict than necessary, because they can
not separate out the need for random-access from the need for a true reference
return type. </li></ul>
<h2>Proposal for new iterator categories and requirements</h2>The iterator
requirements should be separated into two hierarchies. One set of concepts
handles the return type semantics:
<ul>
<li><a href="#concept_ReadableIterator">Readable
Iterator</a>
</li><li><a href="#concept_WritableIterator">Writable
Iterator</a>
</li><li><a href="#concept_SwappableIterator">Swappable
Iterator</a>
</li><li><a href="#concept_ConstantLvalueIterator">Constant
Lvalue Iterator</a>
</li><li><a href="#concept_MutableLvalueIterator">Mutable
Lvalue Iterator</a> </li></ul>The other set of concepts handles iterator
traversal:
<ul>
<li><a href="#concept_ForwardTraversalIterator">Forward
Traversal Iterator</a>
</li><li><a href="#concept_BidirectionalTraversalIterator">Bidirectional
Traversal Iterator</a>
</li><li><a href="#concept_RandomAccessTraversalIterator">Random
Access Traversal Iterator</a> </li></ul>The current Input Iterator and Output
Iterator requirements will continue to be used as is. Note that Input Iterator
implies Readable Iterator and Output Iterator implies Writable Iterator.
<p>Note: we considered defining a Single-Pass Iterator, which could be combined
with Readable or Writable Iterator to replace the Input and Output Iterator
requirements. We rejected this idea because there are several differences
between Input and Output Iterators that make it hard to merge them: Input
Iterator requires Equality Comparable while Output Iterator does not and Input
Iterator requires Assignable while Output Iterator does not.
</p><h3>New categories and traits classes</h3>Each of the new iterator requirements
will need a category tag. <pre>namespace std {
// Return Type Categories
struct readable_iterator_tag { };
struct writable_iterator_tag { };
struct swappable_iterator_tag { };
struct mutable_lvalue_iterator_tag : virtual public writable_iterator_tag,
virtual public readable_iterator_tag { };
struct constant_lvalue_iterator_tag : public readable_iterator_tag { };
// Traversal Categories
struct forward_traversal_tag { };
struct bidirectional_traversal_tag : public forward_traversal_tag { };
struct random_access_traversal_tag : public bidirectional_traversal_tag { };
}
</pre>And there will need to be a way to access these category tags using a
traits mechanism. Adding new typedefs to <tt>std::iterator_traits</tt> is not an
acceptable solution because that would break every existing iterator. Instead,
we propose two new traits classes. It is important that these traits classes are
<b>backward compatible</b>, that is, they should work with any iterator for
which there is a valid definition of <tt>std::iterator_traits</tt>. This can be
accomplished by making the default behavior of the traits classes map the
<tt>iterator_category</tt> of the iterator to the appropriate return or
traversal category. For new iterators, either specializations of these traits
classes can be defined, or the iterator can provide nested typedefs, and inherit
from <tt>new_iterator_base</tt> (which is just a signal to the traits class that
it is a new iterator). As with <tt>std::iterator_traits</tt>, specializations
for <tt>T*</tt> are provided. <pre>namespace std {
struct new_iterator_base { };
template &lt;typename Iterator&gt;
struct return_category
{
<b><i>// Pseudo-code</i></b>
if (Iterator inherits from new_iterator_base) {
typedef typename Iterator::return_category type;
} else {
typedef std::iterator_traits&lt;Iterator&gt; OldTraits;
typedef typename OldTraits::iterator_category Cat;
if (Cat inherits from std::forward_iterator_tag)
if (is-const(T))
typedef boost::constant_lvalue_iterator_tag type;
else
typedef boost::mutable_lvalue_iterator_tag type;
else if (Cat inherits from std::input_iterator_tag)
typedef boost::readable_iterator_tag type;
else if (Cat inherits from std::output_iterator_tag)
typedef boost::writable_iterator_tag type;
}
};
template &lt;typename T&gt;
struct return_category&lt;T*&gt;
{
<b><i>// Pseudo-code</i></b>
if (is-const(T))
typedef boost::constant_lvalue_iterator_tag type;
else
typedef boost::mutable_lvalue_iterator_tag type;
};
template &lt;typename Iterator&gt;
struct traversal_category
{
<b><i>// Pseudo-code</i></b>
if (Iterator inherits from new_iterator_base) {
typedef typename Iterator::traversal_category type;
} else {
typedef std::iterator_traits&lt;Iterator&gt; OldTraits;
typedef typename OldTraits::iterator_category Cat;
if (Cat inherits from std::random_access_iterator_tag)
typedef boost::random_access_traversal_tag type;
else if (Cat inherits from std::bidirectional_iterator_tag)
typedef boost::bidirectional_traversal_tag type;
else if (Cat inherits from std::forward_iterator_tag)
typedef boost::forward_traversal_tag type;
}
};
template &lt;typename T&gt;
struct traversal_category&lt;T*&gt;
{
typedef boost::random_access_traversal_tag type;
};
}
</pre>
<h2>Impact on the Standard Algorithms</h2>Many of the standard algorithms place
more requirements than necessary on their iterator parameters due to the
coarseness of the current iterator categories. By using the new iterator
categories a better fit can be achieved, thereby increasing the reusability of
the algorithms. These changes will not affect user-code, though they will
require changes by standard implementers: dispatching should be based on the new
categories, and in places return values may need to be handled more carefully.
In particular, uses of <tt>std::swap()</tt> will need to be replaced with
<tt>std::iter_swap()</tt>, and <tt>std::iter_swap()</tt> will need to call
<tt>std::swap()</tt>.
<p>
</p><center>
<a name="table:2">
<b>Table 2.</b> Requirement changes for standard
algorithms.</a><table border="1">
<tbody>
<tr>
<th>Algorithm</th>
<th>Requirement Change</th></tr>
<tr>
<td>find_end</td>
<td rowspan="12">Forward Iterator<br>-&gt; Forward Traversal Iterator and
Readable Iterator </td></tr>
<tr>
<td>find_first_of</td></tr>
<tr>
<td>adjacent_find</td></tr>
<tr>
<td>search</td></tr>
<tr>
<td>search_n</td></tr>
<tr>
<td>rotate_copy</td></tr>
<tr>
<td>lower_bound</td></tr>
<tr>
<td>upper_bound</td></tr>
<tr>
<td>equal_range</td></tr>
<tr>
<td>binary_search</td></tr>
<tr>
<td>min_element</td></tr>
<tr>
<td>max_element</td></tr>
<tr>
<td>iter_swap</td>
<td>Forward Iterator<br>-&gt; Swappable Iterator </td></tr>
<tr>
<td>fill</td>
<td rowspan="2">Forward Iterator<br>-&gt; Forward Traversal Iterator and
Writable Iterator </td></tr>
<tr>
<td>generate</td></tr>
<tr>
<td>swap_ranges</td>
<td rowspan="2">Forward Iterator<br>-&gt; Forward Traversal Iterator and
Swappable Iterator </td></tr>
<tr>
<td>rotate</td></tr>
<tr>
<td>replace</td>
<td rowspan="5">Forward Iterator<br>-&gt; Forward Traversal Iterator
and<br>Readable Iterator and Writable Iterator </td>
</tr><tr>
<td>replace_if</td></tr>
<tr>
<td>remove</td></tr>
<tr>
<td>remove_if</td></tr>
<tr>
<td>unique</td></tr>
<tr>
<td>reverse</td>
<td rowspan="2">Bidirectional Iterator<br>-&gt; Bidirectional Traversal
Iterator and Swappable Iterator </td></tr>
<tr>
<td>partition</td></tr>
<tr>
<td>copy_backwards</td>
<td>Bidirectional Iterator<br>-&gt; Bidirectional Traversal Iterator and
Readable Iterator<br>Bidirectional Iterator<br>-&gt; Bidirectional
Traversal Iterator and Writable Iterator </td></tr>
<tr>
<td>next_permutation</td>
<td rowspan="2">Bidirectional Iterator<br>-&gt; Bidirectional Traversal
Iterator and <br>Swappable Iterator and Readable Iterator </td>
</tr><tr>
<td>prev_permutation</td></tr>
<tr>
<td>stable_partition</td>
<td rowspan="2">Bidirectional Iterator<br>-&gt; Bidirectional Traversal
Iterator and <br>Readable Iterator and Writable Iterator </td>
</tr><tr>
<td>inplace_merge</td></tr>
<tr>
<td>reverse_copy</td>
<td>Bidirectional Iterator<br>-&gt; Bidirectional Traversal Iterator and
Readable Iterator </td></tr>
<tr>
<td>random_shuffle</td>
<td rowspan="9">Random Access Iterator<br>-&gt; Random Access Traversal
Iterator and Swappable Iterator </td></tr>
<tr>
<td>sort</td></tr>
<tr>
<td>stable_sort</td></tr>
<tr>
<td>partial_sort</td></tr>
<tr>
<td>nth_element</td></tr>
<tr>
<td>push_heap</td></tr>
<tr>
<td>pop_heap</td></tr>
<tr>
<td>make_heap</td></tr>
<tr>
<td>sort_heap</td></tr></tbody></table></center>
<h2>The New Iterator Requirements</h2>
<h3>Notation</h3>
<table>
<tbody>
<tr>
<td><tt>X</tt></td>
<td>The iterator type.</td></tr>
<tr>
<td><tt>T</tt></td>
<td>The value type of <tt>X</tt>, i.e.,
<tt>std::iterator_traits&lt;X&gt;::value_type</tt>.</td></tr>
<tr>
<td><tt>x</tt>, <tt>y</tt></td>
<td>An object of type <tt>X</tt>.</td></tr>
<tr>
<td><tt>t</tt></td>
<td>An object of type <tt>T</tt>.</td></tr></tbody></table>
<p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_ReadableIterator"></a>Readable Iterator </h3>A Readable
Iterator is an iterator that dereferences to produce an rvalue that is
convertible to the <tt>value_type</tt> of the iterator.
<h3>Associated Types</h3>
<table border="1">
<tbody>
<tr>
<td>Value type</td>
<td><tt>std::iterator_traits&lt;X&gt;::value_type</tt></td>
<td>The type of the objects pointed to by the iterator.</td></tr>
<tr>
<td>Reference type</td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td>
<td>The return type of dereferencing the iterator. This type must be
convertible to <tt>T</tt>. </td></tr>
<tr>
<td>Return Category</td>
<td><tt>std::return_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::readable_iterator_tag</tt>
</td></tr></tbody></table>
<h3>Refinement of</h3><a href="http://www.boost.org/libs/utility/CopyConstructible.html">Copy
Constructible</a>
<h3>Valid expressions</h3>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Expression</th>
<th>Type requirements</th>
<th>Return type</th></tr>
<tr>
<td>Dereference</td>
<td><tt>*x</tt></td>
<td><EFBFBD></td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td></tr>
<tr>
<td>Member access</td>
<td><tt>x-&gt;m</tt></td>
<td><tt>T</tt> is a type with a member named <tt>m</tt>.</td>
<td>If <tt>m</tt> is a data member, the type of <tt>m</tt>. If <tt>m</tt>
is a member function, the return type of <tt>m</tt>. </td></tr></tbody></table>
<p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_WritableIterator"></a>Writable Iterator </h3>A Writable
Iterator is an iterator that can be used to store a value using the
dereference-assignment expression.
<h3>Definitions</h3>If <tt>x</tt> is an Writable Iterator of type <tt>X</tt>,
then the expression <tt>*x = a;</tt> stores the value <tt>a</tt> into
<tt>x</tt>. Note that <tt>operator=</tt>, like other C++ functions, may be
overloaded; it may, in fact, even be a template function. In general, then,
<tt>a</tt> may be any of several different types. A type <tt>A</tt> belongs to
the <i>set of value types</i> of <tt>X</tt> if, for an object <tt>a</tt> of type
<tt>A</tt>, <tt>*x = a;</tt> is well-defined and does not require performing any
non-trivial conversions on <tt>a</tt>.
<h3>Associated Types</h3>
<table border="1">
<tbody>
<tr>
<td>Return Category</td>
<td><tt>std::return_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::writable_iterator_tag</tt>
</td></tr></tbody></table>
<h3>Refinement of</h3><a href="http://www.boost.org/libs/utility/CopyConstructible.html">Copy
Constructible</a>
<h3>Valid expressions</h3>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Expression</th>
<th>Return type</th></tr>
<tr>
<td>Dereference assignment</td>
<td><tt>*x = a</tt></td>
<td>unspecified</td></tr></tbody></table>
<p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_SwappableIterator"></a>Swappable Iterator </h3>A Swappable
Iterator is an iterator whose dereferenced values can be swapped.
<p>Note: the requirements for Swappable Iterator are dependent on the issues
surrounding <tt>std::swap()</tt> being resolved. Here we assume that the issue
will be resolved by allowing the overload of <tt>std::swap()</tt> for
user-defined types.
</p><p>Note: Readable Iterator and Writable Iterator combined implies Swappable
Iterator because of the fully templated <tt>std::swap()</tt>. However, Swappable
Iterator does not imply Readable Iterator nor Writable Iterator.
</p><h3>Associated Types</h3>
<table border="1">
<tbody>
<tr>
<td>Return Category</td>
<td><tt>std::return_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::swappable_iterator_tag</tt>
</td></tr></tbody></table>
<h3>Valid expressions</h3>Of the two valid expressions listed below, only one
<b>OR</b> the other is required. If <tt>std::iter_swap()</tt> is overloaded for
<tt>X</tt> then <tt>std::swap()</tt> is not required. If
<tt>std::iter_swap()</tt> is not overloaded for <tt>X</tt> then the default
(fully templated) version is used, which will call <tt>std::swap()</tt> (this
means changing the current requirements for <tt>std::iter_swap()</tt>).
<p>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Expression</th>
<th>Return type</th></tr>
<tr>
<td>Iterator Swap</td>
<td><tt>std::iter_swap(x, y)</tt></td>
<td>void</td></tr>
<tr>
<td>Dereference and Swap</td>
<td><tt>std::swap(*x, *y)</tt></td>
<td>void</td></tr></tbody></table>
</p><p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_ConstantLvalueIterator"></a>Constant Lvalue Iterator </h3>A
Constant Lvalue Iterator is an iterator that dereferences to produce a const
reference to the pointed-to object, i.e., the associated <tt>reference</tt> type
is <tt>const T&amp;</tt>. Changing the value of or destroying an iterator that
models Constant Lvalue Iterator does not invalidate pointers and references
previously obtained from that iterator.
<h3>Refinement of</h3><a href="#concept_ReadableIterator">Readable
Iterator</a>
<h3>Associated Types</h3>
<table border="1">
<tbody>
<tr>
<td>Reference type</td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td>
<td>The return type of dereferencing the iterator, which must be <tt>const
T&amp;</tt>. </td></tr><!-- I don't think this is needed
<tr>
<td>Pointer type</td>
<td><tt>std::iterator_traits&lt;X&gt;::pointer</tt></td>
<td>
The pointer to the value type, which must be <tt>const T*</tt>.
</td>
</tr>
-->
<tr>
<td>Return Category</td>
<td><tt>std::return_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::constant_lvalue_iterator_tag</tt>
</td></tr></tbody></table><!-- these are not necessary now that we use reference as operator* return type
<h3>Valid expressions</h3>
<Table border>
<tr><TH>Name</TH><TH>Expression</TH><TH>Type requirements</TH><TH>Return type</TH></tr>
<tr>
<td>Dereference</td>
<td><tt>*x</tt></td>
<td>&nbsp;</td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td>
</tr>
<tr>
<td>Member access</td>
<td><tt>x-&gt;m</tt></td>
<td><tt>T</tt> is a type with a member named <tt>m</tt>.</td>
<td>
&nbsp;
</td>
</tr>
</table>
-->
<p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_MutableLvalueIterator"></a>Mutable Lvalue Iterator </h3>A
Mutable Lvalue Iterator is an iterator that dereferences to produce a reference
to the pointed-to object. The associated <tt>reference</tt> type is
<tt>T&amp;</tt>. Changing the value of or destroying an iterator that models
Mutable Lvalue Iterator does not invalidate pointers and references previously
obtained from that iterator.
<h3>Refinement of</h3><a href="#concept_ReadableIterator">Readable
Iterator</a>, <a href="#concept_WritableIterator">Writable
Iterator</a>, and <a href="#concept_SwappableIterator">Swappable
Iterator</a>.
<h3>Associated Types</h3>
<table border="1">
<tbody>
<tr>
<td>Reference type</td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td>
<td>The return type of dereferencing the iterator, which must be
<tt>T&amp;</tt>.</td></tr><!-- I don't think this is necessary
<tr>
<td>Pointer type</td>
<td><tt>std::iterator_traits&lt;X&gt;::pointer</tt></td>
<td>
The pointer to the value type, which is <tt>T*</tt>.
</td>
</tr>
-->
<tr>
<td>Return Category</td>
<td><tt>std::return_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::mutable_lvalue_iterator_tag</tt>
</td></tr></tbody></table><!-- no longer needed since the return type is specified as reference in the readable iterator
<h3>Valid expressions</h3>
<Table border>
<tr><TH>Name</TH><TH>Expression</TH><TH>Type requirements</TH><TH>Return type</TH></tr>
<tr>
<td>Dereference</td>
<td><tt>*x</tt></td>
<td>&nbsp;</td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td>
</tr>
<tr>
<td>Member access</td>
<td><tt>x-&gt;m</tt></td>
<td><tt>T</tt> is a type with a member named <tt>m</tt>.</td>
<td>
&nbsp;
</td>
</tr>
</table>
-->
<p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_ForwardTraversalIterator"></a>Forward Traversal Iterator
</h3>The Forward Iterator is an iterator that can be incremented. Also, it is
permissible to make multiple passes through the iterator's range.
<h3>Refinement of</h3><a href="http://www.boost.org/libs/utility/CopyConstructible.html">Copy
Constructible</a>, <a href="http://www.boost.org/libs/utility/Assignable.html">Assignable</a>, <a href="http://www.sgi.com/tech/stl/DefaultConstructible.html">Default
Constructible</a>, and <a href="http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
Comparable</a>
<h3>Associated types</h3>
<table border="1">
<tbody>
<tr>
<td>Difference Type</td>
<td><tt>std::iterator_traits&lt;X&gt;::difference_type</tt></td>
<td>A signed integral type used for representing distances between
iterators that point into the same range. </td></tr>
<tr>
<td>Traversal Category</td>
<td><tt>std::traversal_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::forward_traversal_tag</tt>
</td></tr></tbody></table>
<h3>Valid expressions</h3>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Expression</th>
<th>Type requirements</th>
<th>Return type</th></tr>
<tr>
<td>Preincrement</td>
<td><tt>++i</tt></td>
<td><EFBFBD></td>
<td><tt>X&amp;</tt></td></tr>
<tr>
<td>Postincrement</td>
<td><tt>i++</tt></td>
<td><EFBFBD></td>
<td>convertible to <tt>const X&amp;</tt></td></tr></tbody></table>
<p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_BidirectionalTraversalIterator"></a>Bidirectional Traversal
Iterator </h3>An iterator that can be incremented and decremented.
<h3>Refinement of</h3><a href="#concept_ForwardTraversalIterator">Forward
Traversal Iterator</a>
<h3>Associated types</h3>
<table border="1">
<tbody>
<tr>
<td>Traversal Category</td>
<td><tt>std::traversal_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::bidirectional_traversal_tag</tt>
</td></tr></tbody></table>
<h3>Valid expressions</h3>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Expression</th>
<th>Type requirements</th>
<th>Return type</th></tr>
<tr>
<td>Predecrement</td>
<td><tt>--i</tt></td>
<td><EFBFBD></td>
<td><tt>X&amp;</tt></td></tr>
<tr>
<td>Postdecrement</td>
<td><tt>i--</tt></td>
<td><EFBFBD></td>
<td>convertible to <tt>const X&amp;</tt></td></tr></tbody></table>
<p>
</p><hr>
<!--------------------------------------------------------------------------->
<h3><a name="concept_RandomAccessTraversalIterator"></a>Random Access Traversal
Iterator </h3>An iterator that provides constant-time methods for moving forward
and backward in arbitrary-sized steps.
<h3>Refinement of</h3><a href="#concept_BidirectionalTraversalIterator">Bidirectional
Traversal Iterator</a> and <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
Comparable</a> where <tt>&lt;</tt> is a total ordering
<h3>Associated types</h3>
<table border="1">
<tbody>
<tr>
<td>Traversal Category</td>
<td><tt>std::traversal_category&lt;X&gt;::type</tt></td>
<td>A type convertible to <tt>std::random_access_traversal_tag</tt>
</td></tr></tbody></table>
<h3>Valid expressions</h3>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Expression</th>
<th>Type requirements</th>
<th>Return type</th></tr>
<tr>
<td>Iterator addition</td>
<td><tt>i += n</tt></td>
<td><EFBFBD></td>
<td><tt>X&amp;</tt></td></tr>
<tr>
<td>Iterator addition</td>
<td><tt>i + n</tt> or <tt>n + i</tt></td>
<td><EFBFBD></td>
<td><tt>X</tt></td></tr>
<tr>
<td>Iterator subtraction</td>
<td><tt>i -= n</tt></td>
<td><EFBFBD></td>
<td><tt>X&amp;</tt></td></tr>
<tr>
<td>Iterator subtraction</td>
<td><tt>i - n</tt></td>
<td><EFBFBD></td>
<td><tt>X</tt></td></tr>
<tr>
<td>Difference</td>
<td><tt>i - j</tt></td>
<td><EFBFBD></td>
<td><tt>std::iterator_traits&lt;X&gt;::difference_type</tt></td></tr>
<tr>
<td>Element operator</td>
<td><tt>i[n]</tt></td>
<td><tt>X</tt> must also be a model of <a href="#concept_ReadableIterator">Readable
Iterator</a>. </td>
<td><tt>std::iterator_traits&lt;X&gt;::reference</tt></td></tr>
<tr>
<td>Element assignment</td>
<td><tt>i[n] = t</tt></td>
<td><tt>X</tt> must also be a model of <a href="#concept_WritableIterator">Writable
Iterator</a>.</td>
<td>unspecified</td></tr></tbody></table>
<p>
</p><hr>
<!-- LocalWords: HTML BGCOLOR FFFFFF TR TD Siek HREF mailto jsiek
--><!-- LocalWords: lsc edu tt const href http anubis dkuug dk JTC SC WG docs lt
--><!-- LocalWords: lwg html bool gt Sutter's htm Lvalue namespace std struct
--><!-- LocalWords: lvalue typename OldTraits reusability min iter prev inplace
--><!-- LocalWords: rvalue templated Preincrement Postincrement Predecrement
--><!-- LocalWords: Postdecrement
--></body></html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,76 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
== 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.
-->
<head>
<title>Boost.MultiArray: Extra Notes</title>
</head>
<body>
<h1>
<img src="../../../boost.png" alt="boost logo"
width="277" align="middle" height="86">
<br>Boost.MultiArray: Extra Notes
<br>
</h1>
<a name="sec_compilers"></a>
<h2>Compiler Support</h2>
Boost.MultiArray was designed with compiler support in mind.
Interface compromises were kept to a minimum, but efforts were
made to account for C++ Standard compliance issues in compilers
that were popular at the time the library was written. That said,
Boost.MultiArray has been tested with the following compilers:
<ol>
<li> Gnu C++ Compiler v2.95.2 (compile with <tt>-ftemplate-depth-50</tt>)
<li> Gnu C++ Compiler v3.0.2
<li> Kuck and Associates C++ Compiler v4.0f
<li> Microsoft Visual C++ v6.0 sp5
<li> Comeau C++ Compiler v4.2.45 beta 2 (libcomo beta 14)
<li> Intel C++ Compiler v5.0 (with MS lib v6.0 sp5)
<li> Metrowerks CodeWarrior C++ Compiler v7.1
</ol>
Boost.MultiArray is known to NOT work with Borland C++ v5.5.1.
Support for this compiler is forthcoming.
<h2>Future Work</h2>
The following is a list of work that is intended for the near future
-- following the initial addition of the library to the Boost
distribution:
<ol>
<li> Pursue and document performance issues related to compilers and
implementation.
<li> More comprehensive examples of using the library components.
<li> Extensive rewrite of the user documentation to make it more accessible.
</ol>
<hr>
<address>
<a href="mailto:garcia@.cs.indiana.edu">Ronald Garcia</a>
</address>
<!-- Created: Fri Jun 29 10:53:07 EST 2001 -->
<!-- hhmts start -->
Last modified: Wed Jan 8 18:09:46 EST 2003
<!-- hhmts end -->
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,326 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
== 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.
-->
<head>
<title>
Boost.MultiArray: Test Descriptions
</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<IMG SRC="../../../boost.png"
ALT="C++ Boost" width="277" height="86">
<h1>Boost.MultiArray: Test Descriptions</h1>
The following is a description of the test cases that are included with
Boost.Multi_Array (B.M).
<h2>Terminology</h2>
The following list is to clarify the use of terms in the following
descriptions:
<ul>
<li> <b>B.M</b> - abbreviation for Boost.MultiArray.
<li><b>primary components</b> - refers to <tt>boost::multi_array</tt>,
<tt>boost::const_multi_array_ref</tt>, and
<tt>boost::multi_array_ref</tt>.
<li><b>array types</b> - refers to all the primary components, plus for each
primary component "array", the types <tt>array::const_subarray</tt>,
<tt>array::subarray</tt>, <tt>array::const_array_view</tt>, and
<tt>array::array_view </tt>
</ul>
<h2>Acceptance Tests</h2>
The following tests exercise various features of Boost.Multi_Array to
ensure proper operation at run time.
<table border="1" cellspacing="0" cellpadding="5"
summary="This table describes the test cases in the multi-array test
suite that should compile and run.">
<tr>
<td>Program</td>
<td>Description</td>
</tr>
<tr>
<td><a href="../test/constructors.cpp">libs/multi_array/test/constructors.cpp</a></td>
<td>
Exercises all of the constructors for B.M primary components.
</td>
</tr>
<tr>
<td><a href="../test/access.cpp">libs/multi_array/test/access.cpp</a></td>
<td>
Tests <tt>operator[]</tt> and <tt>operator()</tt> on all B.M array types.
</td>
</tr>
<tr>
<td><a href="../test/compare.cpp">libs/multi_array/test/compare.cpp</a></td>
<td>
Tests all comparison operators for the B.M primary components.
</td>
</tr>
<tr>
<td><a href="../test/iterators.cpp">libs/multi_array/test/iterators.cpp</a></td>
<td>
Test all iterator traversal and access functionality for all B.M array types.
</td>
</tr>
<tr>
<td><a href="../test/slice.cpp">libs/multi_array/test/slice.cpp</a></td>
<td>
Test all variations of subview generation for all B.M array types.
</td>
</tr>
<tr>
<td><a href="../test/assign.cpp">libs/multi_array/test/assign.cpp</a></td>
<td>
Tests out <tt>operator=()</tt> on the various B.M array types.
</td>
</tr>
<tr>
<td><a href="../test/assign_to_array.cpp">libs/multi_array/test/assign_to_array.cpp</a></td>
<td>
Ensure that a <tt>multi_array</tt> can be constructed from any other
array type.
</td>
</tr>
<tr>
<td><a href="../test/index_bases.cpp">libs/multi_array/test/index_bases.cpp</a></td>
<td>
Test re-indexing functionality for the B.M primary components.
</td>
</tr>
<tr>
<td><a href="../test/storage_order_convert.cpp">libs/multi_array/test/storage_order_convert.cpp</a></td>
<td>
Test out conversions among the storage orders data types.
</td>
</tr>
<tr>
<td><a href="../test/storage_order.cpp">libs/multi_array/test/storage_order.cpp</a></td>
<td>
Test variations on storage_order for the B.M primary components.
</td>
</tr>
<tr>
<td><a href="../test/reshape.cpp">libs/multi_array/test/reshape.cpp</a></td>
<td>
Test re-shaping functionality for the B.M primary components.
</td>
</tr>
<tr>
<td><a href="../test/range1.cpp">libs/multi_array/test/range1.cpp</a></td>
<td>
Test the various syntaxes for specifying index ranges using
<tt>array::index_range</tt>.
</td>
</tr>
<tr>
<td><a href="../test/idxgen1.cpp">libs/multi_array/test/idxgen1.cpp</a></td>
<td>
Test the <tt>array::index_gen</tt> objects.
</td>
</tr>
<tr>
<td><a href="../test/stl_interaction.cpp">libs/multi_array/test/stl_interaction.cpp</a></td>
<td>
Test interaction between array types and STL containers.
</td>
</tr>
<tr>
<td><a href="../test/resize.cpp">libs/multi_array/test/resize.cpp</a></td>
<td>
Test the <tt>multi_array</tt> class' resizing functionality.
</td>
</tr>
<tr>
<td><a href="../test/concept_checks.cpp">libs/multi_array/test/concept_checks.cpp</a></td>
<td>
Ensure that all the array types meet the defined Concepts.
</td>
</tr>
<tr>
<td><a href="../test/assert.cpp">libs/multi_array/test/assert.cpp</a></td>
<td>
Ensure that uses of BOOST_ASSERT within the library can be customized
by library users.
</td>
</tr>
<tr>
<td><a href="../test/generative_tests.hpp">libs/multi_array/test/generative_tests.hpp</a></td>
<td>
A test harness used to simplify testing operations upon all array
types. Used by slice.cpp, iterators.cpp, and access.cpp.
</td>
</tr>
</table>
<h2>Compile-Fail Tests</h2>
The following tests check to make sure that various constructs not
accepted by the library fail to compile. Each test checks only
one fault in order to more easily ensure the cause of the
compilation failure.
<p>
<table border="1" cellspacing="0" cellpadding="5"
summary="This table describes the tests in the multi array test suite
that should fail to compile">
<tr>
<td>Program</td>
<td>Description</td>
</tr>
<tr>
<td><a href="../test/fail_cbracket.cpp">libs/multi_array/test/fail_cbracket.cpp</a>
<br><a href="../test/fail_ref_cbracket.cpp">libs/multi_array/test/fail_ref_cbracket.cpp</a></td>
<td>
<tt>operator[]</tt> on a const array must not modify elements.
</td>
</tr>
<tr>
<td><a href="../test/fail_cdata.cpp">libs/multi_array/test/fail_cdata.cpp</a>
<br><a href="../test/fail_ref_cdata.cpp">libs/multi_array/test/fail_ref_cdata.cpp</a></td>
<td>
<tt>array::data() const</tt> must return a pointer to const data.
</td>
</tr>
<tr>
<td><a href="../test/fail_citerator.cpp">libs/multi_array/test/fail_citerator.cpp</a>
<br><a href="../test/fail_ref_citerator.cpp">libs/multi_array/test/fail_ref_citerator.cpp</a></td>
<td>
<tt>const_iterator</tt> must not be convertible to <tt>iterator</tt>.
</td>
</tr>
<tr>
<td><a href="../test/fail_cparen.cpp">libs/multi_array/test/fail_cparen.cpp</a>
<br><a href="../test/fail_ref_cparen.cpp">libs/multi_array/test/fail_ref_cparen.cpp</a></td>
<td>
<tt>operator()</tt> on a const array must not modify elements.
</td>
</tr>
<tr>
<td><a href="../test/fail_criterator.cpp">libs/multi_array/test/fail_criterator.cpp</a>
<br><a href="../test/fail_ref_criterator.cpp">libs/multi_array/test/fail_ref_criterator.cpp</a></td>
<td>
<tt>const_reverse_iterator</tt> must not be convertible to
<tt>reverse_iterator</tt>.
</td>
</tr>
<tr>
<td><a href="../test/fail_csubarray.cpp">libs/multi_array/test/fail_csubarray.cpp</a>
<br><a href="../test/fail_ref_csubarray.cpp">libs/multi_array/test/fail_ref_csubarray.cpp</a></td>
<td>
<tt>const_subarray</tt> must not be convertible to <tt>subarray</tt>.
</td>
</tr>
<tr>
<td><a href="../test/fail_csubarray2.cpp">libs/multi_array/test/fail_csubarray2.cpp</a>
<br><a href="../test/fail_ref_csubarray2.cpp">libs/multi_array/test/fail_ref_csubarray2.cpp</a></td>
<td>
<tt>array::operator[] const</tt> must not be convertible to <tt>subarray</tt>.
</td>
</tr>
<tr>
<td><a href="../test/fail_csubarray3.cpp">libs/multi_array/test/fail_csubarray3.cpp</a>
<br><a href="../test/fail_ref_csubarray3.cpp">libs/multi_array/test/fail_ref_csubarray3.cpp</a></td>
<td>
<tt>const_subarray</tt> into an array must not modify elements.
</td>
</tr>
<tr>
<td><a href="../test/fail_cview.cpp">libs/multi_array/test/fail_cview.cpp</a>
<br><a href="../test/fail_ref_cview.cpp">libs/multi_array/test/fail_ref_cview.cpp</a></td>
<td>
<tt>const_array_view</tt> of an array must not modify elements.
</td>
</tr>
<tr>
<td><a href="../test/fail_cview2.cpp">libs/multi_array/test/fail_cview2.cpp</a>
<br><a href="../test/fail_ref_cview2.cpp">libs/multi_array/test/fail_ref_cview2.cpp</a></td>
<td>
<tt>array::operator[] const</tt> must not be convertible to
<tt>array_view</tt>.
</td>
</tr>
<tr>
<td><a href="../test/fail_cview3.cpp">libs/multi_array/test/fail_cview3.cpp</a>
<br><a href="../test/fail_ref_cview3.cpp">libs/multi_array/test/fail_ref_cview3.cpp</a></td>
<td>
<tt>const_array_view</tt> of an array must not modify elements.
</td>
</tr>
</table>
<br>
<table summary="Copyright information">
<tr valign="top">
<td nowrap>Copyright &copy; 2001</td>
<td><a href="http://www.boost.org/people/ronald_garcia.htm">Ronald Garcia</a>,
Indiana University (<a href=
"mailto:garcia@cs.indiana.edu">garcia@cs.indiana.edu</a>)<br>
<a href="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>, Indiana
University (<a href=
"mailto:jsiek@cs.indiana.edu">jsiek@cs.indiana.edu</a>)<br>
<a href="http://www.lsc.nd.edu/~lums">Andrew Lumsdaine</a>, Indiana
University (<a href=
"mailto:lums@cs.indiana.edu">lums@cs.indiana.edu</a>)</td>
</tr>
</table>
<hr>
<address>
<a href="mailto:garcia@.cs.indiana.edu">Ronald Garcia</a>
</address>
<!-- hhmts start -->
Last modified: Wed Oct 31 19:46:44 EST 2001
<!-- hhmts end -->
</body>
</html>

View File

@@ -0,0 +1,675 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
== 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.
-->
<head>
<title>The Boost Multidimensional Array Library (Boost.MultiArray)</title>
</head>
<body>
<h1>
<img src="../../../boost.png" alt="boost logo"
width="277" align="middle" height="86">
<br>The Boost Multidimensional Array Library
<br>(Boost.MultiArray)
</h1>
<h2>Synopsis</h2>
<p>
The Boost Multidimensional Array Library provides a class template for
multidimensional arrays, as well as semantically equivalent
adaptors for arrays of contiguous data. The classes in this library
implement a common interface, formalized as a generic programming
concept. The interface design is in line with the precedent set by the
C++ Standard Library containers. Boost MultiArray is a more efficient
and convenient way to express N-dimensional arrays than existing
alternatives (especially the
<tt>std::vector&lt;std::vector&lt;...&gt;&gt;</tt> formulation
of N-dimensional arrays). The arrays provided by the library may be
accessed using the familiar syntax of native C++ arrays. Additional
features, such as resizing, reshaping, and creating views are
available (and described below).
<h2>Table of Contents</h2>
<ol>
<li><a href="#sec_introduction">Introduction</a>
<li><a href="#sec_example">Short Example</a>
<li><a href="#sec_components">MultiArray Components</a>
<li><a href="#sec_assignment">Construction and Assignment</a>
<li><a href="#sec_generators">Array View and Subarray Type Generators</a>
<li><a href="#sec_dimensions">Specifying Array Dimensions</a>
<li><a href="#sec_access">Accessing Elements</a>
<li><a href="#sec_views">Creating Views</a>
<li><a href="#sec_storage">Storage Ordering</a>
<li><a href="#sec_base">Setting the Array Base</a>
<li><a href="#sec_reshape">Changing an Array's Shape</a>
<li><a href="#sec_resize">Resizing an Array</a>
<li><a href="#sec_concepts">MultiArray Concept</a>
<li><a href="#sec_testcases">Test Cases</a>
<li><a href="#sec_related">Related Work</a>
<li><a href="#sec_credits">Credits</a>
</ol>
<a name="sec_introduction"></a>
<h2>Introduction</h2>
<p>
The C++ standard library provides several generic containers, but it
does not provide any multidimensional array types. The
<tt>std::vector</tt> class template can be used to implement
N-dimensional arrays, for example expressing a 2-dimensional array of
<tt>double</tt> elements using the type
<tt>std::vector&lt;std::vector&lt;double&gt;&gt;</tt>, but the
resulting interface is unwieldy and the memory overhead can be quite
high. Native C++ arrays (i.e. <tt>int arr[2][2][2];</tt>) do not
immediately interoperate well with the C++ Standard Library, and they
also lose information at function call boundaries (specifically the
extent of the last dimension). Finally, a dynamically allocated
contiguous block of elements can be treated as an array, though this
method requires manual bookkeeping that is error prone and obfuscates
the intent of the programmer.
</p>
<p>
The Boost MultiArray library enhances the C++ standard containers with
versatile multi-dimensional array abstractions. It includes a general
array class template and native array adaptors that support idiomatic
array operations and interoperate with C++ Standard Library containers
and algorithms. The arrays share a common interface, expressed as a
generic programming in terms of which generic array algorithms can be
implemented.
</p>
<p>
This document is meant to provide an introductory tutorial and user's
guide for the most basic and common usage patterns of MultiArray
components. The <a href="./reference.html">reference manual</a>
provides more complete and formal documentation of library features.
</p>
<a name="sec_example"></a>
<h2>Short Example</h2>
What follows is a brief example of the use of <tt>multi_array</tt>:
<blockquote>
<pre>
#include "boost/multi_array.hpp"
#include &lt;cassert&gt;
int
main () {
// Create a 3D array that is 3 x 4 x 2
typedef boost::multi_array&lt;double, 3&gt; array_type;
typedef array_type::index index;
array_type A(boost::extents[3][4][2]);
// Assign values to the elements
int values = 0;
for(index i = 0; i != 3; ++i)
for(index j = 0; j != 4; ++j)
for(index k = 0; k != 2; ++k)
A[i][j][k] = values++;
// Verify values
int verify = 0;
for(index i = 0; i != 3; ++i)
for(index j = 0; j != 4; ++j)
for(index k = 0; k != 2; ++k)
assert(A[i][j][k] == verify++);
return 0;
}
</pre>
</blockquote>
<a name="sec_components"></a>
<h2>MultiArray Components</h2>
Boost.MultiArray's implementation (boost/multi_array.hpp) provides three user-level class templates:
<ol>
<li><a href="./reference.html#multi_array"><tt>multi_array</tt></a>,
<li><a href="./reference.html#multi_array_ref"><tt>multi_array_ref</tt></a>, and
<li><a href="./reference.html#const_multi_array_ref"><tt>const_multi_array_ref</tt></a>
</ol>
<tt>multi_array</tt> is a container template. When instantiated, it
allocates space for the number of elements corresponding to the
dimensions specified at construction time. A <tt>multi_array</tt> may
also be default constructed and resized as needed.
<p>
<tt>multi_array_ref</tt> adapts an existing array of data to provide
the <tt>multi_array</tt> interface. <tt>multi_array_ref</tt> does not own the
data passed to it.
<p>
<tt>const_multi_array_ref</tt> is similar to <tt>multi_array_ref</tt>
but guarantees that the contents of the array are immutable. It can
thus wrap pointers of type <i>T const*</i>.
<p>
The three components exhibit very similar behavior. Aside from
constructor parameters, <tt>multi_array</tt> and
<tt>multi_array_ref</tt> export the same interface.
<tt>const_multi_array_ref</tt> provides only the constness-preserving
portions of the <tt>multi_array_ref</tt> interface.
<a name="sec_assignment"></a>
<h2>Construction and Assignment</h2>
<p>Each of the array types -
<a href="./reference.html#multi_array"><tt>multi_array</tt></a>,
<a href="./reference.html#multi_array_ref"><tt>multi_array_ref</tt></a>, and
<a href="./reference.html#const_multi_array_ref"><tt>const_multi_array_ref</tt></a> -
provides a specialized set of constructors. For further information,
consult their reference pages.
<p>All of the non-const array types in this library provide assignment
operators<tt>operator=()</tt>. Each of the array types <tt>multi_array</tt>,
<tt>multi_array_ref</tt>, <tt>subarray</tt>, and
<tt>array_view</tt> can be assigned from any
of the others, so long as their shapes match. The
const variants, <tt>const_multi_array_ref</tt>,
<tt>const_subarray</tt>, and <tt>const_array_view</tt>, can be the
source of a copy to an array with matching shape.
Assignment results in a deep (element by element) copy of the data
contained within an array.
<a name="sec_generators"></a>
<h2>Array View and Subarray Type Generators</h2>
In some situations, the use of nested generators for array_view and
subarray types is inconvenient. For example, inside a
function template parameterized upon array type, the extra
"template" keywords can be obfuscating. More likely though, some
compilers cannot handle templates nested within template parameters.
For this reason the type generators, <tt>subarray_gen</tt>,
<tt>const_subarray_gen</tt>, <tt>array_view_gen</tt>, and
<tt>const_array_view_gen</tt> are provided. Thus, the two typedefs
in the following example result in the same type:
<blockquote>
<pre>
template &lt;typename Array&gt;
void my_function() {
typedef typename Array::template array_view&lt;3&gt;::type view1_t;
typedef typename boost::array_view_gen&lt;Array,3&gt;::type view2_t;
// ...
}
</pre>
</blockquote>
<a name="sec_dimensions"></a>
<h2>Specifying Array Dimensions</h2>
When creating most of the Boost.MultiArray components, it is necessary
to specify both the number of dimensions and the extent of each
(<tt>boost::multi_array</tt> also provides a default constructor).
Though the number of dimensions is always specified as a template
parameter, two separate mechanisms have been provided to specify the
extent of each.
<p>The first method involves passing a
<a href="../../utility/Collection.html">
Collection</a> of extents to a
constructor, most commonly a <tt>boost::array</tt>. The constructor
will retrieve the beginning iterator from the container and retrieve N
elements, corresponding to extents for the N dimensions. This is
useful for writing dimension-independent code.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
boost::array&lt;array_type::index, 3&gt; shape = {{ 3, 4, 2 }};
array_type A(shape);
</pre>
</blockquote>
<p>The second method involves passing the constructor an <tt>extent_gen</tt>
object, specifying the matrix dimensions. The <tt>extent_gen</tt> type
is defined in the <tt>multi_array_types</tt> namespace and as a
member of every array type, but by default, the library constructs a
global <tt>extent_gen</tt> object <tt>boost::extents</tt>. In case of
concern about memory used by these objects, defining
<tt>BOOST_MULTI_ARRAY_NO_GENERATORS</tt> before including the library
header inhibits its construction.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
array_type A(boost::extents[3][4][2]);
</pre>
</blockquote>
<a name="sec_access"></a>
<h2>Accessing Elements</h2>
The Boost.MultiArray components provide two ways of accessing
specific elements within a container. The first uses the traditional
C array notation, provided by <tt>operator[]</tt>.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
array_type A(boost::extents[3][4][2]);
A[0][0][0] = 3.14;
assert(A[0][0][0] == 3.14);
</pre>
</blockquote>
<p> The second method involves passing a
<a href="../../utility/Collection.html">
Collection</a> of indices to <tt>operator()</tt>. N indices will be retrieved
from the Collection for the N dimensions of the container.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
array_type A(boost::extents[3][4][2]);
boost::array&lt;array_type::index,3&gt; idx = {{0,0,0}};
A(idx) = 3.14;
assert(A(idx) == 3.14);
</pre>
</blockquote>
This can be useful for writing dimension-independent code, and under
some compilers may yield higher performance than <tt>operator[].</tt>
<p>
By default, both of the above element access methods perform range
checking. If a supplied index is out of the range defined for an
array, an assertion will abort the program. To disable range
checking (for performance reasons in production releases), define
the <tt>BOOST_DISABLE_ASSERTS</tt> preprocessor macro prior to
including multi_array.hpp in your application.
<a name="sec_views"></a>
<h2>Creating Views</h2>
Boost.MultiArray provides the facilities for creating a sub-view of an
already existing array component. It allows you to create a sub-view that
retains the same number of dimensions as the original array or one
that has less dimensions than the original as well.
<p>Sub-view creation occurs by placing a call to operator[], passing
it an <tt>index_gen</tt> type. The <tt>index_gen</tt> is populated by
passing <tt>index_range</tt> objects to its <tt>operator[]</tt>.
The <tt>index_range</tt> and <tt>index_gen</tt> types are defined in
the <tt>multi_array_types</tt> namespace and as nested members of
every array type. Similar to <tt>boost::extents</tt>, the library by
default constructs the object <tt>boost::indices</tt>. You can
suppress this object by
defining <tt>BOOST_MULTI_ARRAY_NO_GENERATORS</tt> before including the
library header. A simple sub-view creation example follows.
<h3>Example</h3>
<blockquote>
<pre>
// myarray = 2 x 3 x 4
//
// array_view dims: [base,bound) (dimension striding default = 1)
// dim 0: [0,2)
// dim 1: [1,3)
// dim 2: [0,4) (strided by 2),
//
typedef boost::multi_array_types::index_range range;
// OR typedef array_type::index_range range;
array_type::array_view&lt;3&gt;::type myview =
myarray[ boost::indices[range(0,2)][range(1,3)][range(0,4,2)] ];
for (array_type::index i = 0; i != 2; ++i)
for (array_type::index j = 0; j != 2; ++j)
for (array_type::index k = 0; k != 2; ++k)
assert(myview[i][j][k] == myarray[i][j+1][k*2]);
</pre>
</blockquote>
<p>By passing an integral value to the index_gen, one may create a
subview with fewer dimensions than the original array component (also
called slicing).
<h3>Example</h3>
<blockquote>
<pre>
// myarray = 2 x 3 x 4
//
// array_view dims:
// [base,stride,bound)
// [0,1,2), 1, [0,2,4)
//
typedef boost::multi_array_types::index_range range;
array_type::index_gen indices;
array_type::array_view&lt;2&gt;::type myview =
myarray[ indices[range(0,2)][1][range(0,4,2)] ];
for (array_type::index i = 0; i != 2; ++i)
for (array_type::index j = 0; j != 2; ++j)
assert(myview[i][j] == myarray[i][1][j*2]);
</pre>
</blockquote>
<h3>More on <tt>index_range</tt></h3>
The <tt>index_range</tt> type provides several methods of specifying
ranges for subview generation. Here are a few range instantiations
that specify the same range.
<h3>Example</h3>
<blockquote>
<pre>
// [base,stride,bound)
// [0,2,4)
typedef boost::multi_array_types::index_range range;
range a_range;
a_range = range(0,4,2);
a_range = range().start(0).finish(4).stride(2);
a_range = range().start(0).stride(2).finish(4);
a_range = 0 &lt;= range().stride(2) &lt; 4;
a_range = 0 &lt;= range().stride(2) &lt;= 3;
</pre>
</blockquote>
An <tt>index_range</tt> object passed to a slicing operation will
inherit its start and/or finish value from the array being sliced if
you do not supply one. This conveniently prevents you from having to
know the bounds of the array dimension in certain cases. For example,
the default-constructed range will take the full extent of the
dimension it is used to specify.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array_types::index_range range;
range a_range;
// All elements in this dimension
a_range = range();
// indices i where 3 &lt;= i
a_range = range().start(3)
a_range = 3 &lt;= range();
a_range = 2 &lt; range();
// indices i where i &lt; 7
a_range = range().finish(7)
a_range = range() &lt; 7;
a_range = range() &lt;= 6;
</pre>
</blockquote>
The following example slicing operations exhibit some of the
alternatives shown above
<blockquote>
<pre>
// take all of dimension 1
// take i &lt; 5 for dimension 2
// take 4 &lt;= j &lt;= 7 for dimension 3 with stride 2
myarray[ boost::indices[range()][range() &lt; 5 ][4 &lt;= range().stride(2) &lt;= 7] ];
</pre>
</blockquote>
<a name="sec_storage"></a>
<h2>Storage Ordering</h2>
Each array class provides constructors that accept a storage ordering
parameter. This is most
useful when interfacing with legacy codes that require an ordering
different from standard C, such as FORTRAN. The possibilities are
<tt>c_storage_order</tt>, <tt>fortran_storage_order</tt>, and
<tt>general_storage_order</tt>.
<p><tt>c_storage_order</tt>, which is the default, will store elements
in memory in the same order as a C array would, that is, the
dimensions are stored from last to first.
<p><tt>fortran_storage_order</tt> will store elements in memory in the same order
as FORTRAN would: from the first dimension to
the last. Note that with use of this parameter, the array
indices will remain zero-based.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double,3&gt; array_type;
array_type A(boost::extents[3][4][2],boost::fortran_storage_order());
call_fortran_function(A.data());
</pre>
</blockquote>
<p><tt>general_storage_order</tt> allows one to customize both the order in
which dimensions are stored in memory and whether dimensions are
stored in ascending or descending order.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::general_storage_order&lt;3&gt; storage;
typedef boost::multi_array&lt;int,3&gt; array_type;
// Store last dimension, then first, then middle
array_type::size_type ordering[] = {2,0,1};
// Store the first dimension(dimension 0) in descending order
bool ascending[] = {false,true,true};
array_type A(extents[3][4][2],storage(ordering,ascending));
</pre>
</blockquote>
<a name="sec_base"></a>
<h2>Setting The Array Base</h2>
In some situations, it may be inconvenient or awkward to use an
array that is zero-based.
the Boost.MultiArray components provide two facilities for changing the
bases of an array. One may specify a pair of range values, with
the <tt>extent_range</tt> type, to
the <tt>extent_gen</tt> constructor in order to set the base value.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
typedef boost::multi_array_types::extent_range range;
// OR typedef array_type::extent_range range;
array_type::extent_gen extents;
// dimension 0: 0-based
// dimension 1: 1-based
// dimension 2: -1 - based
array_type A(extents[2][range(1,4)][range(-1,3)]);
</pre>
</blockquote>
<p>
An alternative is to first construct the array normally then
reset the bases. To set all bases to the same value, use the
<tt>reindex</tt> member function, passing it a single new index value.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
array_type::extent_gen extents;
array_type A(extents[2][3][4]);
// change to 1-based
A.reindex(1)
</pre>
</blockquote>
<p>
An alternative is to set each base separately using the
<tt>reindex</tt> member function, passing it a Collection of index bases.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
array_type::extent_gen extents;
// dimension 0: 0-based
// dimension 1: 1-based
// dimension 2: (-1)-based
array_type A(extents[2][3][4]);
boost::array&lt;array_type::index,ndims&gt; bases = {{0, 1, -1}};
A.reindex(bases);
</pre>
</blockquote>
<a name="sec_reshape"></a>
<h2>Changing an Array's Shape</h2>
The Boost.MultiArray arrays provide a reshape operation. While the
number of dimensions must remain the same, the shape of the array may
change so long as the total number of
elements contained remains the same.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;double, 3&gt; array_type;
array_type::extent_gen extents;
array_type A(extents[2][3][4]);
boost::array&lt;array_type::index,ndims&gt; dims = {{4, 3, 2}};
A.reshape(dims);
</pre>
</blockquote>
<p>
Note that reshaping an array does not affect the indexing.
<a name="sec_resize"></a>
<h2>Resizing an Array</h2>
The <tt>boost::multi_array</tt> class provides an element-preserving
resize operation. The number of dimensions must remain the same, but
the extent of each dimension may be increased and decreased as
desired. When an array is made strictly larger, the existing elements
will be preserved by copying them into the new underlying memory and
subsequently destructing the elements in the old underlying memory.
Any new elements in the array are default constructed. However, if
the new array size shrinks some of the dimensions, some elements will
no longer be available.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;int, 3&gt; array_type;
array_type::extent_gen extents;
array_type A(extents[3][3][3]);
A[0][0][0] = 4;
A[2][2][2] = 5;
A.resize(extents[2][3][4]);
assert(A[0][0][0] == 4);
// A[2][2][2] is no longer valid.
</pre>
</blockquote>
<a name="sec_concepts"></a>
<h2>MultiArray Concept</h2>
Boost.MultiArray defines and uses the
<a href="./reference.html#MultiArray">MultiArray</a>
concept. It specifies an interface for N-dimensional containers.
<a name="sec_testcases"></a>
<h2>Test Cases</h2>
Boost.MultiArray comes with a suite of test cases meant to exercise
the features and semantics of the library. A description of the test
cases can be found <a href="./test_cases.html">here</a>.
<a name="sec_related"></a>
<h2>Related Work</h2>
<a href="../../array/index.html">boost::array</a>
and <a href="http://www.sgi.com/tech/stl/Vector.html">std::vector</a> are
one-dimensional containers of user data. Both manage their own
memory. <tt>std::valarray</tt> is a low-level
C++ Standard Library component
meant to provide portable high performance for numerical applications.
<a href="http://www.oonumerics.org/blitz/">Blitz++</a> is
an array library developed by Todd
Veldhuizen. It uses
advanced C++ techniques to provide near-Fortran performance for
array-based numerical applications.
<b>array_traits</b> is a beta library, formerly distributed with
Boost, that provides a means to create iterators over native C++
arrays.
This library is analogous to
<a href="../../array/index.html">boost::array</a> in that it augments C style N-dimensional
arrays, as <tt>boost::array</tt> does for C one-dimensional arrays.
<a name="sec_credits"></a>
<h2>Credits</h2>
<ul>
<li><a href="mailto:garcia@osl.iu.edu">Ronald Garcia</a>
is the primary author of the library.
<li><a href="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>
helped with the library and provided a sounding board for ideas,
advice, and assistance porting to Microsoft Visual C++.
<li><a href="mailto:gbavestrelli@yahoo.com">Giovanni Bavestrelli</a>
provided an early implementation of an
N-dimensional array which inspired feedback from the
<a href="http://www.boost.org/">Boost</a> mailing list
members. Some design decisions in this work were based upon this
implementation and the comments it elicited.
<li><a href="mailto:tveldhui@acm.org">Todd Veldhuizen</a> wrote
<a href="http://oonumerics.org/blitz/">Blitz++</a>, which
inspired some aspects of this design. In addition, he supplied
feedback on the design and implementation of the library.
<li><a href="mailto:jewillco@osl.iu.edu">Jeremiah Willcock</a>
provided feedback on the implementation and design of the
library and some suggestions for features.
<li><a href="mailto:bdawes@acm.org">Beman Dawes</a>
helped immensely with porting the library to Microsoft Windows
compilers.
</ul>
<hr>
<address>
<a href="mailto:garcia@.cs.indiana.edu">Ronald Garcia</a>
</address>
<!-- Created: Fri Jun 29 10:53:07 EST 2001 -->
<!-- hhmts start -->Last modified: Tue Feb 7 17:15:50 EST 2006 <!-- hhmts end -->
</body>
</html>

View File

@@ -0,0 +1,19 @@
# Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
# Distributed under 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)
project multi_array/doc ;
import boostbook : boostbook ;
path-constant here : . ;
boostbook multi_array-doc
:
bbref.xml
:
<xsl:param>boost.root=../../../../..
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
<format>pdf:<xsl:param>img.src.path=$(here)/../
;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,806 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [
<!ENTITY concepts SYSTEM "MultiArray.xml">
<!ENTITY multi_array SYSTEM "multi_array.xml">
<!ENTITY multi_array_ref SYSTEM "multi_array_ref.xml">
<!ENTITY const_multi_array_ref SYSTEM "const_multi_array_ref.xml">
]>
<library name="MultiArray" dirname="multi_array" id="multi_array"
xmlns:xi="http://www.w3.org/2001/XInclude"
last-revision="$Date$">
<libraryinfo>
<author>
<firstname>Ronald</firstname>
<surname>Garcia</surname>
<affiliation>
<orgname>Indiana University</orgname>
<orgdiv>Open Systems Lab</orgdiv>
</affiliation>
</author>
<orgname>BOOST</orgname>
<copyright>
<year>2002</year>
<holder>The Trustees of Indiana University</holder>
</copyright>
<librarypurpose>Multidimensional containers and adaptors for
arrays of contiguous data</librarypurpose>
<librarycategory name="category:math"/>
<librarycategory name="category:containers"/>
</libraryinfo>
<title>Boost.MultiArray Reference Manual</title>
<para>Boost.MultiArray is composed of several components.
The MultiArray concept defines a generic interface to multidimensional
containers.
<literal>multi_array</literal> is a general purpose container class
that models MultiArray. <literal>multi_array_ref</literal>
and <literal>const_multi_array_ref</literal> are adapter
classes. Using them,
you can manipulate any block of contiguous data as though it were a
<literal>multi_array</literal>.
<literal>const_multi_array_ref</literal> differs from
<literal>multi_array_ref</literal> in that its elements cannot
be modified through its interface. Finally, several auxiliary classes are used
to create and specialize arrays and some global objects are defined as
part of the library interface.</para>
<sect1 id="synopsis">
<title>Library Synopsis</title>
<para>To use Boost.MultiArray, you must include the header
<filename>boost/multi_array.hpp</filename> in your source. This file
brings the following declarations into scope:</para>
<programlisting>
<![CDATA[namespace boost {
namespace multi_array_types {
typedef *unspecified* index;
typedef *unspecified* size_type;
typedef *unspecified* difference_type;
typedef *unspecified* index_range;
typedef *unspecified* extent_range;
typedef *unspecified* index_gen;
typedef *unspecified* extent_gen;
}
template <typename ValueType,
std::size_t NumDims,
typename Allocator = std::allocator<ValueType> >
class multi_array;
template <typename ValueType,
std::size_t NumDims>
class multi_array_ref;
template <typename ValueType,
std::size_t NumDims>
class const_multi_array_ref;
multi_array_types::extent_gen extents;
multi_array_types::index_gen indices;
template <typename Array, int N> class subarray_gen;
template <typename Array, int N> class const_subarray_gen;
template <typename Array, int N> class array_view_gen;
template <typename Array, int N> class const_array_view_gen;
class c_storage_order;
class fortran_storage_order;
template <std::size_t NumDims> class general_storage_order;
}]]>
</programlisting>
</sect1>
&concepts;
<sect1 id="array_types">
<title>Array Components</title>
<para>
Boost.MultiArray defines an array class,
<literal>multi_array</literal>, and two adapter classes,
<literal>multi_array_ref</literal> and
<literal>const_multi_array_ref</literal>. The three classes model
MultiArray and so they share a lot of functionality.
<literal>multi_array_ref</literal> differs from
<literal>multi_array</literal> in that the
<literal>multi_array</literal> manages its own memory, while
<literal>multi_array_ref</literal> is passed a block of memory that it
expects to be externally managed.
<literal>const_multi_array_ref</literal> differs from
<literal>multi_array_ref</literal> in that the underlying elements it
adapts cannot be modified through its interface, though some array
properties, including the array shape and index bases, can be altered.
Functionality the classes have in common is described
below.
</para>
<formalpara>
<title>Note: Preconditions, Effects, and Implementation</title>
<para>
Throughout the following sections, small pieces of C++ code are
used to specify constraints such as preconditions, effects, and
postconditions. These do not necessarily describe the underlying
implementation of array components; rather, they describe the
expected input to and
behavior of the specified operations. Failure to meet
preconditions results in undefined behavior. Not all effects
(i.e. copy constructors, etc.) must be mimicked exactly. The code
snippets for effects intend to capture the essence of the described
operation.
</para>
</formalpara>
<formalpara>
<title>Queries</title>
<variablelist>
<varlistentry>
<term><programlisting>element* data();
const element* data() const;</programlisting></term>
<listitem>
<para>This returns a pointer to the beginning of the
contiguous block that contains the array's data. If all dimensions of
the array are 0-indexed and stored in ascending order, this is
equivalent to <literal>origin()</literal>. Note that
<literal>const_multi_array_ref</literal> only provides the const
version of this function.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><programlisting>element* origin();
const element* origin() const;</programlisting></term>
<listitem>
<para>This returns the origin element of the
<literal>multi_array</literal>. Note that
<literal>const_multi_array_ref</literal> only provides the const
version of this function. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>const index* index_bases();</function></term>
<listitem>
<para>This returns the index bases for the
<literal>multi_array</literal>. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>const index* strides();</function></term>
<listitem>
<para>This returns the strides for the
<literal>multi_array</literal>. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>const size_type* shape();</function></term>
<listitem>
<para>This returns the shape of the
<literal>multi_array</literal>. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
<formalpara>
<title>Comparators</title>
<variablelist>
<varlistentry>
<term><programlisting><![CDATA[
bool operator==(const *array-type*& rhs);
bool operator!=(const *array-type*& rhs);
bool operator<(const *array-type*& rhs);
bool operator>(const *array-type*& rhs);
bool operator>=(const *array-type*& rhs);
bool operator<=(const *array-type*& rhs);]]></programlisting></term>
<listitem>
<para>Each comparator executes a lexicographical compare over
the value types of the two arrays.
(Required by MultiArray)
</para>
<formalpara>
<title>Preconditions</title>
<para><literal>element</literal> must support the
comparator corresponding to that called on
<literal>multi_array</literal>.</para>
</formalpara>
<formalpara>
<title>Complexity</title>
<para>O(<literal>num_elements()</literal>).</para>
</formalpara>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
<formalpara>
<title>Modifiers</title>
<variablelist>
<varlistentry>
<term>
<programlisting>
<![CDATA[
template <typename SizeList>
void reshape(const SizeList& sizes)
]]>
</programlisting>
</term>
<listitem>
<para>This changes the shape of the <literal>multi_array</literal>. The
number of elements and the index bases remain the same, but the number
of values at each level of the nested container hierarchy may
change.</para>
<formalpara><title><literal>SizeList</literal> Requirements</title>
<para><literal>SizeList</literal> must model
<ulink url="../../utility/Collection.html">Collection</ulink>.</para>
</formalpara>
<formalpara><title>Preconditions</title>
<para>
<programlisting>
<![CDATA[std::accumulate(sizes.begin(),sizes.end(),size_type(1),std::times<size_type>()) == this->num_elements();
sizes.size() == NumDims;]]>
</programlisting></para>
</formalpara>
<formalpara><title>Postconditions</title>
<para>
<literal>std::equal(sizes.begin(),sizes.end(),this->shape) == true;</literal>
</para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting>
<![CDATA[
template <typename BaseList>
void reindex(const BaseList& values);
]]>
</programlisting>
</term>
<listitem>
<para>This changes the index bases of the <literal>multi_array</literal> to
correspond to the the values in <literal>values</literal>.</para>
<formalpara>
<title><literal>BaseList</literal> Requirements</title>
<para><literal>BaseList</literal> must model
<ulink url="../../utility/Collection.html">Collection</ulink>.</para>
</formalpara>
<formalpara>
<title>Preconditions</title>
<para><literal>values.size() == NumDims;</literal></para>
</formalpara>
<formalpara>
<title>Postconditions</title>
<para><literal>std::equal(values.begin(),values.end(),this->index_bases());
</literal></para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting>
<![CDATA[
void reindex(index value);
]]>
</programlisting>
</term>
<listitem>
<para>This changes the index bases of all dimensions of the
<literal>multi_array</literal> to <literal>value</literal>.</para>
<formalpara>
<title>Postconditions</title>
<para>
<programlisting>
<![CDATA[
std::count_if(this->index_bases(),this->index_bases()+this->num_dimensions(),
std::bind_2nd(std::equal_to<index>(),value)) ==
this->num_dimensions();
]]>
</programlisting>
</para>
</formalpara>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
&multi_array;
&multi_array_ref;
&const_multi_array_ref;
</sect1>
<sect1 id="auxiliary">
<title>Auxiliary Components</title>
<sect2 id="multi_array_types">
<title><literal>multi_array_types</literal></title>
<programlisting>
<![CDATA[namespace multi_array_types {
typedef *unspecified* index;
typedef *unspecified* size_type;
typedef *unspecified* difference_type;
typedef *unspecified* index_range;
typedef *unspecified* extent_range;
typedef *unspecified* index_gen;
typedef *unspecified* extent_gen;
}]]>
</programlisting>
<para>Namespace <literal>multi_array_types</literal> defines types
associated with <literal>multi_array</literal>,
<literal>multi_array_ref</literal>, and
<literal>const_multi_array_ref</literal> that are not
dependent upon template parameters. These types find common use with
all Boost.Multiarray components. They are defined
in a namespace from which they can be accessed conveniently.
With the exception of <literal>extent_gen</literal> and
<literal>extent_range</literal>, these types fulfill the roles of the
same name required by MultiArray and are described in its
concept definition. <literal>extent_gen</literal> and
<literal>extent_range</literal> are described below.
</para>
</sect2>
<sect2 id="extent_range">
<title><classname>extent_range</classname></title>
<para><classname>extent_range</classname> objects define half open
intervals. They provide shape and index base information to
<literal>multi_array</literal>, <literal>multi_array_ref</literal>,
and <literal>const_multi_array_ref</literal> constructors.
<classname>extent_range</classname>s are passed in
aggregate to an array constructor (see
<classname>extent_gen</classname> for more details).
</para>
<formalpara>
<title>Synopsis</title>
<programlisting><![CDATA[
class extent_range {
public:
typedef multi_array_types::index index;
typedef multi_array_types::size_type size_type;
// Structors
extent_range(index start, index finish);
extent_range(index finish);
~extent_range();
// Queries
index start();
index finish();
size_type size();
};]]></programlisting>
</formalpara>
<formalpara>
<title>Model Of</title>
<para>DefaultConstructible,CopyConstructible</para>
</formalpara>
<formalpara><title>Methods and Types</title>
<variablelist>
<varlistentry>
<term><function>extent_range(index start, index finish)</function></term>
<listitem>
<para> This constructor defines the half open interval
<literal>[start,finish)</literal>. The expression
<literal>finish</literal> must be greater than <literal>start</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry><term><function>extent_range(index finish)</function></term>
<listitem>
<para>This constructor defines the half open interval
<literal>[0,finish)</literal>. The value of <literal>finish</literal>
must be positive.</para>
</listitem>
</varlistentry>
<varlistentry><term><function>index start()</function></term>
<listitem>
<para>This function returns the first index represented by the range</para>
</listitem>
</varlistentry>
<varlistentry><term><function>index finish()</function></term>
<listitem>
<para>This function returns the upper boundary value of the half-open
interval. Note that the range does not include this value.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>size_type size()</function></term>
<listitem>
<para>This function returns the size of the specified range. It is
equivalent to <literal>finish()-start()</literal>.</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
</sect2>
<sect2 id="extent_gen">
<title><classname>extent_gen</classname></title>
<para>The <classname>extent_gen</classname> class defines an
interface for aggregating array shape and indexing information to be
passed to a <literal>multi_array</literal>,
<literal>multi_array_ref</literal>, or <literal>const_multi_array_ref</literal>
constructor. Its interface mimics
the syntax used to declare built-in array types
in C++. For example, while a 3-dimensional array of
<classname>int</classname> values in C++ would be
declared as:
<programlisting>int A[3][4][5],</programlisting>
a similar <classname>multi_array</classname> would be declared:
<programlisting>multi_array&lt;int,3&gt; A(extents[3][4][5]).</programlisting>
</para>
<formalpara><title>Synopsis</title>
<programlisting><![CDATA[
template <std::size_t NumRanges>
class *implementation_defined* {
public:
typedef multi_array_types::index index;
typedef multi_array_types::size_type size_type;
template <std::size_t NumRanges> class gen_type;
gen_type<NumRanges+1>::type operator[](const range& a_range) const;
gen_type<NumRanges+1>::type operator[](index idx) const;
};
typedef *implementation_defined*<0> extent_gen;
]]></programlisting>
</formalpara>
<formalpara><title>Methods and Types</title>
<variablelist>
<varlistentry>
<term><function>template gen_type&lt;Ranges&gt;::type</function></term>
<listitem>
<para>This type generator is used to specify the result of
<literal>Ranges</literal> chained calls to
<literal>extent_gen::operator[].</literal> The types
<classname>extent_gen</classname> and
<classname>gen_type&lt;0&gt;::type</classname> are the same.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>gen_type&lt;NumRanges+1&gt;::type
operator[](const extent_range&amp; a_range) const;</function></term>
<listitem>
<para>This function returns a new object containing all previous
<classname>extent_range</classname> objects in addition to
<literal>a_range.</literal> <classname>extent_range</classname>
objects are aggregated by chained calls to
<function>operator[]</function>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>gen_type&lt;NumRanges+1&gt;::type
operator[](index idx) const;</function></term>
<listitem>
<para>This function returns a new object containing all previous
<classname>extent_range</classname> objects in addition to
<literal>extent_range(0,idx).</literal> This function gives the array
constructors a similar syntax to traditional C multidimensional array
declaration.</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
</sect2>
<sect2>
<title>Global Objects</title>
<para>For syntactic convenience, Boost.MultiArray defines two
global objects as part of its
interface. These objects play the role of object generators;
expressions involving them create other objects of interest.
</para>
<para> Under some circumstances, the two global objects may be
considered excessive overhead. Their construction can be prevented by
defining the preprocessor symbol
<literal>BOOST_MULTI_ARRAY_NO_GENERATORS</literal> before including
<filename>boost/multi_array.hpp.</filename></para>
<sect3 id="extents">
<title><literal>extents</literal></title>
<programlisting>
<![CDATA[namespace boost {
multi_array_base::extent_gen extents;
}]]>
</programlisting>
<para>Boost.MultiArray's array classes use the
<literal>extents</literal> global object to specify
array shape during their construction.
For example,
a 3 by 3 by 3 <classname>multi_array</classname> is constructed as follows:
<programlisting>multi_array&lt;int,3&gt; A(extents[3][3][3]);</programlisting>
The same array could also be created by explicitly declaring an <literal>extent_gen</literal>
object locally,, but the global object makes this declaration unnecessary.
</para>
</sect3>
<sect3 id="indices">
<title><literal>indices</literal></title>
<programlisting>
<![CDATA[namespace boost {
multi_array_base::index_gen indices;
}]]>
</programlisting>
<para>The MultiArray concept specifies an
<literal>index_gen</literal> associated type that is used to
create views.
<literal>indices</literal> is a global object that serves the role of
<literal>index_gen</literal> for all array components provided by this
library and their associated subarrays and views.
</para>
<para>For example, using the <literal>indices</literal> object,
a view of an array <literal>A</literal> is constructed as follows:
<programlisting>
A[indices[index_range(0,5)][2][index_range(2,4)]];
</programlisting>
</para>
</sect3>
</sect2>
<sect2 id="generators">
<title>View and SubArray Generators</title>
<para>
Boost.MultiArray provides traits classes, <literal>subarray_gen</literal>,
<literal>const_subarray_gen</literal>,
<literal>array_view_gen</literal>,
and <literal>const_array_view_gen</literal>, for naming of
array associated types within function templates.
In general this is no more convenient to use than the nested
type generators, but the library author found that some C++ compilers do not
properly handle templates nested within function template parameter types.
These generators constitute a workaround for this deficit.
The following code snippet illustrates
the correspondence between the <literal>array_view_gen</literal>
traits class and the <literal>array_view</literal> type associated to
an array:
<programlisting>
template &lt;typename Array&gt;
void my_function() {
typedef typename Array::template array_view&lt;3&gt;::type view1_t;
typedef typename boost::array_view_gen&lt;Array,3&gt;::type view2_t;
// ...
}
</programlisting>
In the above example, <literal>view1_t</literal> and
<literal>view2_t</literal> have the same type.
</para>
</sect2>
<sect2 id="memory_layout">
<title>Memory Layout Specifiers</title>
<para>
While a multidimensional array represents a hierarchy of containers of
elements, at some point the elements must be laid out in
memory. As a result, a single multidimensional array
can be represented in memory more than one way.
</para>
<para>For example, consider the two dimensional array shown below in
matrix notation:
<graphic fileref="matrix.gif"/>
Here is how the above array is expressed in C++:
<programlisting>
int a[3][4] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
</programlisting>
This is an example of row-major storage, where elements of each row
are stored contiguously.
While C++ transparently handles accessing elements of an array, you
can also manage the array and its indexing manually. One way that
this may be expressed in memory is as follows:
<programlisting>
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int s[] = { 4, 1 };
</programlisting>
With the latter declaration of <literal>a</literal> and
strides <literal>s</literal>, element <literal>a(i,j)</literal>
of the array can be
accessed using the expression
<programlisting>*a+i*s[0]+j*s[1]</programlisting>.
</para>
<para>The same two dimensional array could be laid out by column as follows:
<programlisting>
int a[] = { 0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11 };
int s[] = { 3, 1 };
</programlisting>
Notice that the strides here are different. As a result,
The expression given above to access values will work with this pair
of data and strides as well.
</para>
<para>In addition to dimension order, it is also possible to
store any dimension in descending order. For example, returning to the
first example, the first dimension of the example array, the
rows, could be stored in
reverse, resulting in the following:
<programlisting>
int data[] = { 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 };
int *a = data + 8;
int s[] = { -4, 1 };
</programlisting>
Note that in this example <literal>a</literal> must be explicitly set
to the origin. In the previous examples, the
first element stored in memory was the origin; here this is no longer
the case.
</para>
<para>
Alternatively, the second dimension, or the columns, could be reversed
and the rows stored in ascending order:
<programlisting>
int data[] = { 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8 };
int *a = data + 3;
int s[] = { 4, -1 };
</programlisting>
</para>
<para>
Finally, both dimensions could be stored in descending order:
<programlisting>
int data[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
int *a = data + 11;
int s[] = { -4, -1 };
</programlisting>
<literal>
</literal>
</para>
<para>
All of the above arrays are equivalent. The expression
given above for <literal>a(i,j)</literal> will yield the same value
regardless of the memory layout.
Boost.MultiArray arrays can be created with customized storage
parameters as described above. Thus, existing data can be adapted
(with <literal>multi_array_ref</literal> or
<literal>const_multi_array_ref</literal>) as suited to the array
abstraction. A common usage of this feature would be to wrap arrays
that must interoperate with Fortran routines so they can be
manipulated naturally at both the C++ and Fortran levels. The
following sections describe the Boost.MultiArray components used to
specify memory layout.
</para>
<sect3 id="c_storage_order">
<title><literal>c_storage_order</literal></title>
<programlisting>
<![CDATA[class c_storage_order {
c_storage_order();
};]]>
</programlisting>
<para><literal>c_storage_order</literal> is used to specify that an
array should store its elements using the same layout as that used by
primitive C++ multidimensional arrays, that is, from last dimension
to first. This is the default storage order for the arrays provided by
this library.</para>
</sect3>
<sect3 id="fortran_storage_order">
<title><literal>fortran_storage_order</literal></title>
<programlisting>
<![CDATA[class fortran_storage_order {
fortran_storage_order();
};]]>
</programlisting>
<para><literal>fortran_storage_order</literal> is used to specify that
an array should store its elements using the same memory layout as a
Fortran multidimensional array would, that is, from first dimension to
last.</para>
</sect3>
<sect3 id="general_storage_order">
<title><literal>general_storage_order</literal></title>
<programlisting>
<![CDATA[template <std::size_t NumDims>
class general_storage_order {
template <typename OrderingIter, typename AscendingIter>
general_storage_order(OrderingIter ordering, AscendingIter ascending);
};]]>
</programlisting>
<para><literal>general_storage_order</literal> allows the user to
specify an arbitrary memory layout for the contents of an array. The
constructed object is passed to the array constructor in order to
specify storage order.</para>
<para>
<literal>OrderingIter</literal> and <literal>AscendingIter</literal>
must model the <literal>InputIterator</literal> concept. Both
iterators must refer to a range of <literal>NumDims</literal>
elements. <literal>AscendingIter</literal> points to objects
convertible to <literal>bool</literal>. A value of
<literal>true</literal> means that a dimension is stored in ascending
order while <literal>false</literal> means that a dimension is stored
in descending order. <literal>OrderingIter</literal> specifies the
order in which dimensions are stored.
</para>
</sect3>
</sect2>
<sect2 id="range_checking">
<title>Range Checking</title>
<para>
By default, the array access methods <literal>operator()</literal> and
<literal>operator[]</literal> perform range
checking. If a supplied index is out of the range defined for an
array, an assertion will abort the program. To disable range
checking (for performance reasons in production releases), define
the <literal>BOOST_DISABLE_ASSERTS</literal> preprocessor macro prior to
including multi_array.hpp in an application.
</para>
</sect2>
</sect1>
</library>

View File

@@ -0,0 +1,190 @@
<sect2 id="const_multi_array_ref">
<title><literal>const_multi_array_ref</literal></title>
<para>
<literal>const_multi_array_ref</literal> is a multi-dimensional container
adaptor. It provides the MultiArray interface over any contiguous
block of elements. <literal>const_multi_array_ref</literal> exports the
same interface as <literal>multi_array</literal>, with the exception
of the constructors.
</para>
<formalpara>
<title>Model Of.</title>
<para>
<literal>const_multi_array_ref</literal> models
<link linkend="MultiArray">MultiArray</link>,
<ulink url="../../../libs/utility/CopyConstructible.html">CopyConstructible</ulink>.
and depending on the element type, it may also model
<ulink url="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</ulink> and <ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink>.
Detailed descriptions are provided here only for operations that are
not described in the <literal>multi_array</literal> reference.
</para>
</formalpara>
<formalpara>
<title>Synopsis</title>
<programlisting>
<![CDATA[
namespace boost {
template <typename ValueType,
std::size_t NumDims,
typename TPtr = const T*>
class const_multi_array_ref {
public:
// types:
typedef ValueType element;
typedef *unspecified* value_type;
typedef *unspecified* reference;
typedef *unspecified* const_reference;
typedef *unspecified* difference_type;
typedef *unspecified* iterator;
typedef *unspecified* const_iterator;
typedef *unspecified* reverse_iterator;
typedef *unspecified* const_reverse_iterator;
typedef multi_array_types::size_type size_type;
typedef multi_array_types::index index;
typedef multi_array_types::index_gen index_gen;
typedef multi_array_types::index_range index_range;
typedef multi_array_types::extent_gen extent_gen;
typedef multi_array_types::extent_range extent_range;
typedef *unspecified* storage_order_type;
// template typedefs
template <std::size_t Dims> struct subarray;
template <std::size_t Dims> struct const_subarray;
template <std::size_t Dims> struct array_view;
template <std::size_t Dims> struct const_array_view;
// structors
template <typename ExtentList>
explicit const_multi_array_ref(TPtr data, const ExtentList& sizes,
const storage_order_type& store = c_storage_order());
explicit const_multi_array_ref(TPtr data, const extents_tuple& ranges,
const storage_order_type& store = c_storage_order());
const_multi_array_ref(const const_multi_array_ref& x);
~const_multi_array_ref();
// iterators:
const_iterator begin() const;
const_iterator end() const;
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
// capacity:
size_type size() const;
size_type num_elements() const;
size_type num_dimensions() const;
// element access:
template <typename IndexList>
const element& operator()(const IndexList& indices) const;
const_reference operator[](index i) const;
const_array_view<Dims>::type operator[](const indices_tuple& r) const;
// queries
const element* data() const;
const element* origin() const;
const size_type* shape() const;
const index* strides() const;
const index* index_bases() const;
const storage_order_type& storage_order() const;
// comparators
bool operator==(const const_multi_array_ref& rhs);
bool operator!=(const const_multi_array_ref& rhs);
bool operator<(const const_multi_array_ref& rhs);
bool operator>(const const_multi_array_ref& rhs);
bool operator>=(const const_multi_array_ref& rhs);
bool operator<=(const const_multi_array_ref& rhs);
// modifiers:
template <typename SizeList>
void reshape(const SizeList& sizes)
template <typename BaseList> void reindex(const BaseList& values);
void reindex(index value);
};
]]>
</programlisting>
</formalpara>
<formalpara>
<title>Constructors</title>
<variablelist>
<varlistentry>
<term><programlisting>template &lt;typename ExtentList&gt;
explicit const_multi_array_ref(TPtr data,
const ExtentList&amp; sizes,
const storage_order&amp; store = c_storage_order());
</programlisting></term>
<listitem>
<para>
This constructs a <literal>const_multi_array_ref</literal> using the specified
parameters. <literal>sizes</literal> specifies the shape of the
constructed <literal>const_multi_array_ref</literal>. <literal>store</literal>
specifies the storage order or layout in memory of the array
dimensions.
</para>
<formalpara><title><literal>ExtentList</literal> Requirements</title>
<para>
<literal>ExtentList</literal> must model <ulink url="../../utility/Collection.html">Collection</ulink>.
</para>
</formalpara>
<formalpara><title>Preconditions</title>
<para><literal>sizes.size() == NumDims;</literal></para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting><![CDATA[explicit const_multi_array_ref(TPtr data,
extent_gen::gen_type<NumDims>::type ranges,
const storage_order& store = c_storage_order());]]>
</programlisting></term>
<listitem>
<formalpara><title>Effects</title>
<para>
This constructs a <literal>const_multi_array_ref</literal> using the specified
parameters. <literal>ranges</literal> specifies the shape and
index bases of the constructed const_multi_array_ref. It is the result of
<literal>NumDims</literal> chained calls to
<literal>extent_gen::operator[]</literal>. <literal>store</literal>
specifies the storage order or layout in memory of the array
dimensions.
</para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term><programlisting>
<![CDATA[const_multi_array_ref(const const_multi_array_ref& x);]]>
</programlisting></term>
<listitem>
<formalpara>
<title>Effects</title>
<para>This constructs a shallow copy of <literal>x</literal>.
</para></formalpara>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
</sect2>

View File

@@ -0,0 +1,375 @@
<sect2 id="multi_array_class">
<title><literal>multi_array</literal></title>
<para>
<literal>multi_array</literal> is a multi-dimensional container that
supports random access iteration. Its number of dimensions is
fixed at compile time, but its shape and the number of elements it
contains are specified during its construction. The number of elements
will remain fixed for the duration of a
<literal>multi_array</literal>'s lifetime, but the shape of the container can
be changed. A <literal>multi_array</literal> manages its data elements
using a replaceable allocator.
</para>
<formalpara>
<title>Model Of.</title>
<para>
<link linkend="MultiArray">MultiArray</link>,
<ulink url="../../../libs/utility/CopyConstructible.html">CopyConstructible</ulink>. Depending on the element type,
it may also model <ulink url="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</ulink> and <ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink>.
</para>
</formalpara>
<formalpara>
<title>Synopsis</title>
<programlisting>
<![CDATA[
namespace boost {
template <typename ValueType,
std::size_t NumDims,
typename Allocator = std::allocator<ValueType> >
class multi_array {
public:
// types:
typedef ValueType element;
typedef *unspecified* value_type;
typedef *unspecified* reference;
typedef *unspecified* const_reference;
typedef *unspecified* difference_type;
typedef *unspecified* iterator;
typedef *unspecified* const_iterator;
typedef *unspecified* reverse_iterator;
typedef *unspecified* const_reverse_iterator;
typedef multi_array_types::size_type size_type;
typedef multi_array_types::index index;
typedef multi_array_types::index_gen index_gen;
typedef multi_array_types::index_range index_range;
typedef multi_array_types::extent_gen extent_gen;
typedef multi_array_types::extent_range extent_range;
typedef *unspecified* storage_order_type;
// template typedefs
template <std::size_t Dims> struct subarray;
template <std::size_t Dims> struct const_subarray;
template <std::size_t Dims> struct array_view;
template <std::size_t Dims> struct const_array_view;
static const std::size_t dimensionality = NumDims;
// constructors and destructors
multi_array();
template <typename ExtentList>
explicit multi_array(const ExtentList& sizes,
const storage_order_type& store = c_storage_order(),
const Allocator& alloc = Allocator());
explicit multi_array(const extents_tuple& ranges,
const storage_order_type& store = c_storage_order(),
const Allocator& alloc = Allocator());
multi_array(const multi_array& x);
multi_array(const const_multi_array_ref<ValueType,NumDims>& x);
multi_array(const const_subarray<NumDims>::type& x);
multi_array(const const_array_view<NumDims>::type& x);
multi_array(const multi_array_ref<ValueType,NumDims>& x);
multi_array(const subarray<NumDims>::type& x);
multi_array(const array_view<NumDims>::type& x);
~multi_array();
// modifiers
multi_array& operator=(const multi_array& x);
template <class Array> multi_array& operator=(const Array& x);
// iterators:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
// capacity:
size_type size() const;
size_type num_elements() const;
size_type num_dimensions() const;
// element access:
template <typename IndexList>
element& operator()(const IndexList& indices);
template <typename IndexList>
const element& operator()(const IndexList& indices) const;
reference operator[](index i);
const_reference operator[](index i) const;
array_view<Dims>::type operator[](const indices_tuple& r);
const_array_view<Dims>::type operator[](const indices_tuple& r) const;
// queries
element* data();
const element* data() const;
element* origin();
const element* origin() const;
const size_type* shape() const;
const index* strides() const;
const index* index_bases() const;
const storage_order_type& storage_order() const;
// comparators
bool operator==(const multi_array& rhs);
bool operator!=(const multi_array& rhs);
bool operator<(const multi_array& rhs);
bool operator>(const multi_array& rhs);
bool operator>=(const multi_array& rhs);
bool operator<=(const multi_array& rhs);
// modifiers:
template <typename InputIterator>
void assign(InputIterator begin, InputIterator end);
template <typename SizeList>
void reshape(const SizeList& sizes)
template <typename BaseList> void reindex(const BaseList& values);
void reindex(index value);
template <typename ExtentList>
multi_array& resize(const ExtentList& extents);
multi_array& resize(extents_tuple& extents);
};
]]>
</programlisting>
</formalpara>
<formalpara>
<title>Constructors</title>
<variablelist>
<varlistentry>
<term><programlisting>template &lt;typename ExtentList&gt;
explicit multi_array(const ExtentList&amp; sizes,
const storage_order_type&amp; store = c_storage_order(),
const Allocator&amp; alloc = Allocator());
</programlisting></term>
<listitem>
<para>
This constructs a <literal>multi_array</literal> using the specified
parameters. <literal>sizes</literal> specifies the shape of the
constructed <literal>multi_array</literal>. <literal>store</literal>
specifies the storage order or layout in memory of the array
dimensions. <literal>alloc</literal> is used to
allocate the contained elements.
</para>
<formalpara><title><literal>ExtentList</literal> Requirements</title>
<para>
<literal>ExtentList</literal> must model <ulink url="../../utility/Collection.html">Collection</ulink>.
</para>
</formalpara>
<formalpara><title>Preconditions</title>
<para><literal>sizes.size() == NumDims;</literal></para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting><![CDATA[explicit multi_array(extent_gen::gen_type<NumDims>::type ranges,
const storage_order_type& store = c_storage_order(),
const Allocator& alloc = Allocator());]]>
</programlisting></term>
<listitem>
<para>
This constructs a <literal>multi_array</literal> using the specified
parameters. <literal>ranges</literal> specifies the shape and
index bases of the constructed multi_array. It is the result of
<literal>NumDims</literal> chained calls to
<literal>extent_gen::operator[]</literal>. <literal>store</literal>
specifies the storage order or layout in memory of the array
dimensions. <literal>alloc</literal> is the allocator used to
allocate the memory used to store <literal>multi_array</literal>
elements.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><programlisting>
<![CDATA[multi_array(const multi_array& x);
multi_array(const const_multi_array_ref<ValueType,NumDims>& x);
multi_array(const const_subarray<NumDims>::type& x);
multi_array(const const_array_view<NumDims>::type& x);
multi_array(const multi_array_ref<ValueType,NumDims>& x);
multi_array(const subarray<NumDims>::type& x);
multi_array(const array_view<NumDims>::type& x);]]>
</programlisting></term>
<listitem>
<para>These constructors all constructs a <literal>multi_array</literal> and
perform a deep copy of <literal>x</literal>.
</para>
<formalpara>
<title>Complexity</title>
<para> This performs O(<literal>x.num_elements()</literal>) calls to
<literal>element</literal>'s copy
constructor.
</para></formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term><programlisting>
<![CDATA[multi_array();]]>
</programlisting></term>
<listitem>
<para>This constructs a <literal>multi_array</literal> whose shape is (0,...,0) and contains no elements.
</para>
</listitem>
</varlistentry>
</variablelist>
<formalpara><title>Note on Constructors</title>
<para>
The <literal>multi_array</literal> construction expressions,
<programlisting>
multi_array&lt;int,3&gt; A(boost::extents[5][4][3]);
</programlisting>
and
<programlisting>
boost::array&lt;multi_array_base::index,3&gt; my_extents = {{5, 4, 3}};
multi_array&lt;int,3&gt; A(my_extents);
</programlisting>
are equivalent.
</para>
</formalpara>
</formalpara>
<formalpara>
<title>Modifiers</title>
<variablelist>
<varlistentry>
<term><programlisting>
<![CDATA[multi_array& operator=(const multi_array& x);
template <class Array> multi_array& operator=(const Array& x);]]>
</programlisting>
</term>
<listitem>
<para>This performs an element-wise copy of <literal>x</literal>
into the current <literal>multi_array</literal>.</para>
<formalpara>
<title><literal>Array</literal> Requirements</title>
<para><literal>Array</literal> must model MultiArray.
</para></formalpara>
<formalpara>
<title>Preconditions</title>
<para>
<programlisting>std::equal(this->shape(),this->shape()+this->num_dimensions(),
x.shape());</programlisting></para>
</formalpara>
<formalpara>
<title>Postconditions</title>
<para>
<programlisting>(*.this) == x;</programlisting>
</para>
</formalpara>
<formalpara>
<title>Complexity</title>
<para>The assignment operators perform
O(<literal>x.num_elements()</literal>) calls to <literal>element</literal>'s
copy constructor.</para></formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting>
<![CDATA[
template <typename InputIterator>
void assign(InputIterator begin, InputIterator end);]]>
</programlisting>
</term>
<listitem>
<para>This copies the elements in the range
<literal>[begin,end)</literal> into the array. It is equivalent to
<literal>std::copy(begin,end,this->data())</literal>.
</para>
<formalpara><title>Preconditions</title>
<para><literal>std::distance(begin,end) == this->num_elements();</literal>
</para>
</formalpara>
<formalpara>
<title>Complexity</title>
<para>
The <literal>assign</literal> member function performs
O(<literal>this->num_elements()</literal>) calls to
<literal>ValueType</literal>'s copy constructor.
</para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting><![CDATA[multi_array& resize(extent_gen::gen_type<NumDims>::type extents);
template <typename ExtentList>
multi_array& resize(const ExtentList& extents);
]]>
</programlisting></term>
<listitem>
<para>
This function resizes an array to the shape specified by
<literal>extents</literal>, which is either a generated list of
extents or a model of the <literal>Collection</literal> concept. The
contents of the array are preserved whenever possible; if the new
array size is smaller, then some data will be lost. Any new elements
created by resizing the array are initialized with the
<literal>element</literal> default constructor.
</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
<formalpara>
<title>Queries</title>
<variablelist>
<varlistentry>
<term><programlisting>
<![CDATA[storage_order_type& storage_order() const;]]>
</programlisting>
</term>
<listitem>
<para>This query returns the storage order object associated with the
<literal>multi_array</literal> in question. It can be used to construct a new array with the same storage order.</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
</sect2>

View File

@@ -0,0 +1,257 @@
<sect2 id="multi_array_ref">
<title><literal>multi_array_ref</literal></title>
<para>
<literal>multi_array_ref</literal> is a multi-dimensional container
adaptor. It provides the MultiArray interface over any contiguous
block of elements. <literal>multi_array_ref</literal> exports the
same interface as <literal>multi_array</literal>, with the exception
of the constructors.
</para>
<formalpara>
<title>Model Of.</title>
<para>
<literal>multi_array_ref</literal> models
<link linkend="MultiArray">MultiArray</link>,
<ulink url="../../../libs/utility/CopyConstructible.html">CopyConstructible</ulink>.
and depending on the element type, it may also model
<ulink url="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</ulink> and <ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink>.
Detailed descriptions are provided here only for operations that are
not described in the <literal>multi_array</literal> reference.
</para>
</formalpara>
<formalpara>
<title>Synopsis</title>
<programlisting>
<![CDATA[
namespace boost {
template <typename ValueType,
std::size_t NumDims>
class multi_array_ref {
public:
// types:
typedef ValueType element;
typedef *unspecified* value_type;
typedef *unspecified* reference;
typedef *unspecified* const_reference;
typedef *unspecified* difference_type;
typedef *unspecified* iterator;
typedef *unspecified* const_iterator;
typedef *unspecified* reverse_iterator;
typedef *unspecified* const_reverse_iterator;
typedef multi_array_types::size_type size_type;
typedef multi_array_types::index index;
typedef multi_array_types::index_gen index_gen;
typedef multi_array_types::index_range index_range;
typedef multi_array_types::extent_gen extent_gen;
typedef multi_array_types::extent_range extent_range;
typedef *unspecified* storage_order_type;
// template typedefs
template <std::size_t Dims> struct subarray;
template <std::size_t Dims> struct const_subarray;
template <std::size_t Dims> struct array_view;
template <std::size_t Dims> struct const_array_view;
static const std::size_t dimensionality = NumDims;
// constructors and destructors
template <typename ExtentList>
explicit multi_array_ref(element* data, const ExtentList& sizes,
const storage_order_type& store = c_storage_order());
explicit multi_array_ref(element* data, const extents_tuple& ranges,
const storage_order_type& store = c_storage_order());
multi_array_ref(const multi_array_ref& x);
~multi_array_ref();
// modifiers
multi_array_ref& operator=(const multi_array_ref& x);
template <class Array> multi_array_ref& operator=(const Array& x);
// iterators:
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
// capacity:
size_type size() const;
size_type num_elements() const;
size_type num_dimensions() const;
// element access:
template <typename IndexList>
element& operator()(const IndexList& indices);
template <typename IndexList>
const element& operator()(const IndexList& indices) const;
reference operator[](index i);
const_reference operator[](index i) const;
array_view<Dims>::type operator[](const indices_tuple& r);
const_array_view<Dims>::type operator[](const indices_tuple& r) const;
// queries
element* data();
const element* data() const;
element* origin();
const element* origin() const;
const size_type* shape() const;
const index* strides() const;
const index* index_bases() const;
const storage_order_type& storage_order() const;
// comparators
bool operator==(const multi_array_ref& rhs);
bool operator!=(const multi_array_ref& rhs);
bool operator<(const multi_array_ref& rhs);
bool operator>(const multi_array_ref& rhs);
bool operator>=(const multi_array_ref& rhs);
bool operator<=(const multi_array_ref& rhs);
// modifiers:
template <typename InputIterator>
void assign(InputIterator begin, InputIterator end);
template <typename SizeList>
void reshape(const SizeList& sizes)
template <typename BaseList> void reindex(const BaseList& values);
void reindex(index value);
};
]]>
</programlisting>
</formalpara>
<formalpara>
<title>Constructors</title>
<variablelist>
<varlistentry>
<term><programlisting>template &lt;typename ExtentList&gt;
explicit multi_array_ref(element* data,
const ExtentList&amp; sizes,
const storage_order&amp; store = c_storage_order(),
const Allocator&amp; alloc = Allocator());
</programlisting></term>
<listitem>
<para>
This constructs a <literal>multi_array_ref</literal> using the specified
parameters. <literal>sizes</literal> specifies the shape of the
constructed <literal>multi_array_ref</literal>. <literal>store</literal>
specifies the storage order or layout in memory of the array
dimensions. <literal>alloc</literal> is used to
allocate the contained elements.
</para>
<formalpara><title><literal>ExtentList</literal> Requirements</title>
<para>
<literal>ExtentList</literal> must model <ulink url="../../utility/Collection.html">Collection</ulink>.
</para>
</formalpara>
<formalpara><title>Preconditions</title>
<para><literal>sizes.size() == NumDims;</literal></para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting><![CDATA[explicit multi_array_ref(element* data,
extent_gen::gen_type<NumDims>::type ranges,
const storage_order& store = c_storage_order());]]>
</programlisting></term>
<listitem>
<para>
This constructs a <literal>multi_array_ref</literal> using the specified
parameters. <literal>ranges</literal> specifies the shape and
index bases of the constructed multi_array_ref. It is the result of
<literal>NumDims</literal> chained calls to
<literal>extent_gen::operator[]</literal>. <literal>store</literal>
specifies the storage order or layout in memory of the array
dimensions.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><programlisting>
<![CDATA[multi_array_ref(const multi_array_ref& x);]]>
</programlisting></term>
<listitem>
<para>This constructs a shallow copy of <literal>x</literal>.
</para>
<formalpara>
<title>Complexity</title>
<para> Constant time (for contrast, compare this to
the <literal>multi_array</literal> class copy constructor.
</para></formalpara>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
<formalpara>
<title>Modifiers</title>
<variablelist>
<varlistentry>
<term><programlisting>
<![CDATA[multi_array_ref& operator=(const multi_array_ref& x);
template <class Array> multi_array_ref& operator=(const Array& x);]]>
</programlisting>
</term>
<listitem>
<para>This performs an element-wise copy of <literal>x</literal>
into the current <literal>multi_array_ref</literal>.</para>
<formalpara>
<title><literal>Array</literal> Requirements</title>
<para><literal>Array</literal> must model MultiArray.
</para></formalpara>
<formalpara>
<title>Preconditions</title>
<para>
<programlisting>std::equal(this->shape(),this->shape()+this->num_dimensions(),
x.shape());</programlisting></para>
</formalpara>
<formalpara>
<title>Postconditions</title>
<para>
<programlisting>(*.this) == x;</programlisting>
</para>
</formalpara>
<formalpara>
<title>Complexity</title>
<para>The assignment operators perform
O(<literal>x.num_elements()</literal>) calls to <literal>element</literal>'s
copy constructor.</para></formalpara>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
</sect2>

View File

@@ -0,0 +1,800 @@
<?xml version='1.0' encoding="ISO-Latin-1" ?>
<!DOCTYPE article
PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd" [
<!ENTITY concepts SYSTEM "MultiArray.xml">
<!ENTITY multi_array SYSTEM "multi_array.xml">
<!ENTITY multi_array_ref SYSTEM "multi_array_ref.xml">
<!ENTITY const_multi_array_ref SYSTEM "const_multi_array_ref.xml">
]>
<article>
<articleinfo>
<title>Boost.MultiArray Reference Manual</title>
<author>
<surname>Garcia</surname><firstname>Ronald</firstname>
<affiliation>
<orgname>Indiana University</orgname>
<orgdiv>Open Systems Lab</orgdiv>
</affiliation>
</author>
<orgname>BOOST</orgname>
<copyright>
<year>2002</year>
<holder>The Trustees of Indiana University</holder>
</copyright>
</articleinfo>
<para>Boost.MultiArray is composed of several components.
The MultiArray concept defines a generic interface to multidimensional
containers.
<literal>multi_array</literal> is a general purpose container class
that models MultiArray. <literal>multi_array_ref</literal>
and <literal>const_multi_array_ref</literal> are adapter
classes. Using them,
you can manipulate any block of contiguous data as though it were a
<literal>multi_array</literal>.
<literal>const_multi_array_ref</literal> differs from
<literal>multi_array_ref</literal> in that its elements cannot
be modified through its interface. Finally, several auxiliary classes are used
to create and specialize arrays and some global objects are defined as
part of the library interface.</para>
<sect1 id="synopsis">
<title>Library Synopsis</title>
<para>To use Boost.MultiArray, you must include the header
<filename>boost/multi_array.hpp</filename> in your source. This file
brings the following declarations into scope:</para>
<programlisting>
<![CDATA[namespace boost {
namespace multi_array_types {
typedef *unspecified* index;
typedef *unspecified* size_type;
typedef *unspecified* difference_type;
typedef *unspecified* index_range;
typedef *unspecified* extent_range;
typedef *unspecified* index_gen;
typedef *unspecified* extent_gen;
}
template <typename ValueType,
std::size_t NumDims,
typename Allocator = std::allocator<ValueType> >
class multi_array;
template <typename ValueType,
std::size_t NumDims>
class multi_array_ref;
template <typename ValueType,
std::size_t NumDims>
class const_multi_array_ref;
multi_array_types::extent_gen extents;
multi_array_types::index_gen indices;
template <typename Array, int N> class subarray_gen;
template <typename Array, int N> class const_subarray_gen;
template <typename Array, int N> class array_view_gen;
template <typename Array, int N> class const_array_view_gen;
class c_storage_order;
class fortran_storage_order;
template <std::size_t NumDims> class general_storage_order;
}]]>
</programlisting>
</sect1>
&concepts;
<sect1 id="array_types">
<title>Array Components</title>
<para>
Boost.MultiArray defines an array class,
<literal>multi_array</literal>, and two adapter classes,
<literal>multi_array_ref</literal> and
<literal>const_multi_array_ref</literal>. The three classes model
MultiArray and so they share a lot of functionality.
<literal>multi_array_ref</literal> differs from
<literal>multi_array</literal> in that the
<literal>multi_array</literal> manages its own memory, while
<literal>multi_array_ref</literal> is passed a block of memory that it
expects to be externally managed.
<literal>const_multi_array_ref</literal> differs from
<literal>multi_array_ref</literal> in that the underlying elements it
adapts cannot be modified through its interface, though some array
properties, including the array shape and index bases, can be altered.
Functionality the classes have in common is described
below.
</para>
<formalpara>
<title>Note: Preconditions, Effects, and Implementation</title>
<para>
Throughout the following sections, small pieces of C++ code are
used to specify constraints such as preconditions, effects, and
postconditions. These do not necessarily describe the underlying
implementation of array components; rather, they describe the
expected input to and
behavior of the specified operations. Failure to meet
preconditions results in undefined behavior. Not all effects
(i.e. copy constructors, etc.) must be mimicked exactly. The code
snippets for effects intend to capture the essence of the described
operation.
</para>
</formalpara>
<formalpara>
<title>Queries</title>
<variablelist>
<varlistentry>
<term><programlisting>element* data();
const element* data() const;</programlisting></term>
<listitem>
<para>This returns a pointer to the beginning of the
contiguous block that contains the array's data. If all dimensions of
the array are 0-indexed and stored in ascending order, this is
equivalent to <literal>origin()</literal>. Note that
<literal>const_multi_array_ref</literal> only provides the const
version of this function.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><programlisting>element* origin();
const element* origin() const;</programlisting></term>
<listitem>
<para>This returns the origin element of the
<literal>multi_array</literal>. Note that
<literal>const_multi_array_ref</literal> only provides the const
version of this function. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>const index* index_bases();</function></term>
<listitem>
<para>This returns the index bases for the
<literal>multi_array</literal>. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>const index* strides();</function></term>
<listitem>
<para>This returns the strides for the
<literal>multi_array</literal>. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>const size_type* shape();</function></term>
<listitem>
<para>This returns the shape of the
<literal>multi_array</literal>. (Required by MultiArray)
</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
<formalpara>
<title>Comparators</title>
<variablelist>
<varlistentry>
<term><programlisting><![CDATA[
bool operator==(const *array-type*& rhs);
bool operator!=(const *array-type*& rhs);
bool operator<(const *array-type*& rhs);
bool operator>(const *array-type*& rhs);
bool operator>=(const *array-type*& rhs);
bool operator<=(const *array-type*& rhs);]]></programlisting></term>
<listitem>
<para>Each comparator executes a lexicographical compare over
the value types of the two arrays.
(Required by MultiArray)
</para>
<formalpara>
<title>Preconditions</title>
<para><literal>element</literal> must support the
comparator corresponding to that called on
<literal>multi_array</literal>.</para>
</formalpara>
<formalpara>
<title>Complexity</title>
<para>O(<literal>num_elements()</literal>).</para>
</formalpara>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
<formalpara>
<title>Modifiers</title>
<variablelist>
<varlistentry>
<term>
<programlisting>
<![CDATA[
template <typename SizeList>
void reshape(const SizeList& sizes)
]]>
</programlisting>
</term>
<listitem>
<para>This changes the shape of the <literal>multi_array</literal>. The
number of elements and the index bases remain the same, but the number
of values at each level of the nested container hierarchy may
change.</para>
<formalpara><title><literal>SizeList</literal> Requirements</title>
<para><literal>SizeList</literal> must model
<ulink url="../../utility/Collection.html">Collection</ulink>.</para>
</formalpara>
<formalpara><title>Preconditions</title>
<para>
<programlisting>
<![CDATA[std::accumulate(sizes.begin(),sizes.end(),size_type(1),std::times<size_type>()) == this->num_elements();
sizes.size() == NumDims;]]>
</programlisting></para>
</formalpara>
<formalpara><title>Postconditions</title>
<para>
<literal>std::equal(sizes.begin(),sizes.end(),this->shape) == true;</literal>
</para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting>
<![CDATA[
template <typename BaseList>
void reindex(const BaseList& values);
]]>
</programlisting>
</term>
<listitem>
<para>This changes the index bases of the <literal>multi_array</literal> to
correspond to the the values in <literal>values</literal>.</para>
<formalpara>
<title><literal>BaseList</literal> Requirements</title>
<para><literal>BaseList</literal> must model
<ulink url="../../utility/Collection.html">Collection</ulink>.</para>
</formalpara>
<formalpara>
<title>Preconditions</title>
<para><literal>values.size() == NumDims;</literal></para>
</formalpara>
<formalpara>
<title>Postconditions</title>
<para><literal>std::equal(values.begin(),values.end(),this->index_bases());
</literal></para>
</formalpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
<programlisting>
<![CDATA[
void reindex(index value);
]]>
</programlisting>
</term>
<listitem>
<para>This changes the index bases of all dimensions of the
<literal>multi_array</literal> to <literal>value</literal>.</para>
<formalpara>
<title>Postconditions</title>
<para>
<programlisting>
<![CDATA[
std::count_if(this->index_bases(),this->index_bases()+this->num_dimensions(),
std::bind_2nd(std::equal_to<index>(),value)) ==
this->num_dimensions();
]]>
</programlisting>
</para>
</formalpara>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
&multi_array;
&multi_array_ref;
&const_multi_array_ref;
</sect1>
<sect1 id="auxiliary">
<title>Auxiliary Components</title>
<sect2 id="multi_array_types">
<title><literal>multi_array_types</literal></title>
<programlisting>
<![CDATA[namespace multi_array_types {
typedef *unspecified* index;
typedef *unspecified* size_type;
typedef *unspecified* difference_type;
typedef *unspecified* index_range;
typedef *unspecified* extent_range;
typedef *unspecified* index_gen;
typedef *unspecified* extent_gen;
}]]>
</programlisting>
<para>Namespace <literal>multi_array_types</literal> defines types
associated with <literal>multi_array</literal>,
<literal>multi_array_ref</literal>, and
<literal>const_multi_array_ref</literal> that are not
dependent upon template parameters. These types find common use with
all Boost.Multiarray components. They are defined
in a namespace from which they can be accessed conveniently.
With the exception of <literal>extent_gen</literal> and
<literal>extent_range</literal>, these types fulfill the roles of the
same name required by MultiArray and are described in its
concept definition. <literal>extent_gen</literal> and
<literal>extent_range</literal> are described below.
</para>
</sect2>
<sect2 id="extent_range">
<title><classname>extent_range</classname></title>
<para><classname>extent_range</classname> objects define half open
intervals. They provide shape and index base information to
<literal>multi_array</literal>, <literal>multi_array_ref</literal>,
and <literal>const_multi_array_ref</literal> constructors.
<classname>extent_range</classname>s are passed in
aggregate to an array constructor (see
<classname>extent_gen</classname> for more details).
</para>
<formalpara>
<title>Synopsis</title>
<programlisting><![CDATA[
class extent_range {
public:
typedef multi_array_types::index index;
typedef multi_array_types::size_type size_type;
// Structors
extent_range(index start, index finish);
extent_range(index finish);
~extent_range();
// Queries
index start();
index finish();
size_type size();
};]]></programlisting>
</formalpara>
<formalpara>
<title>Model Of</title>
<para>DefaultConstructible,CopyConstructible</para>
</formalpara>
<formalpara><title>Methods and Types</title>
<variablelist>
<varlistentry>
<term><function>extent_range(index start, index finish)</function></term>
<listitem>
<para> This constructor defines the half open interval
<literal>[start,finish)</literal>. The expression
<literal>finish</literal> must be greater than <literal>start</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry><term><function>extent_range(index finish)</function></term>
<listitem>
<para>This constructor defines the half open interval
<literal>[0,finish)</literal>. The value of <literal>finish</literal>
must be positive.</para>
</listitem>
</varlistentry>
<varlistentry><term><function>index start()</function></term>
<listitem>
<para>This function returns the first index represented by the range</para>
</listitem>
</varlistentry>
<varlistentry><term><function>index finish()</function></term>
<listitem>
<para>This function returns the upper boundary value of the half-open
interval. Note that the range does not include this value.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>size_type size()</function></term>
<listitem>
<para>This function returns the size of the specified range. It is
equivalent to <literal>finish()-start()</literal>.</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
</sect2>
<sect2 id="extent_gen">
<title><classname>extent_gen</classname></title>
<para>The <classname>extent_gen</classname> class defines an
interface for aggregating array shape and indexing information to be
passed to a <literal>multi_array</literal>,
<literal>multi_array_ref</literal>, or <literal>const_multi_array_ref</literal>
constructor. Its interface mimics
the syntax used to declare built-in array types
in C++. For example, while a 3-dimensional array of
<classname>int</classname> values in C++ would be
declared as:
<programlisting>int A[3][4][5],</programlisting>
a similar <classname>multi_array</classname> would be declared:
<programlisting>multi_array&lt;int,3&gt; A(extents[3][4][5]).</programlisting>
</para>
<formalpara><title>Synopsis</title>
<programlisting><![CDATA[
template <std::size_t NumRanges>
class *implementation_defined* {
public:
typedef multi_array_types::index index;
typedef multi_array_types::size_type size_type;
template <std::size_t NumRanges> class gen_type;
gen_type<NumRanges+1>::type operator[](const range& a_range) const;
gen_type<NumRanges+1>::type operator[](index idx) const;
};
typedef *implementation_defined*<0> extent_gen;
]]></programlisting>
</formalpara>
<formalpara><title>Methods and Types</title>
<variablelist>
<varlistentry>
<term><function>template gen_type&lt;Ranges&gt;::type</function></term>
<listitem>
<para>This type generator is used to specify the result of
<literal>Ranges</literal> chained calls to
<literal>extent_gen::operator[].</literal> The types
<classname>extent_gen</classname> and
<classname>gen_type&lt;0&gt;::type</classname> are the same.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>gen_type&lt;NumRanges+1&gt;::type
operator[](const extent_range&amp; a_range) const;</function></term>
<listitem>
<para>This function returns a new object containing all previous
<classname>extent_range</classname> objects in addition to
<literal>a_range.</literal> <classname>extent_range</classname>
objects are aggregated by chained calls to
<function>operator[]</function>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><function>gen_type&lt;NumRanges+1&gt;::type
operator[](index idx) const;</function></term>
<listitem>
<para>This function returns a new object containing all previous
<classname>extent_range</classname> objects in addition to
<literal>extent_range(0,idx).</literal> This function gives the array
constructors a similar syntax to traditional C multidimensional array
declaration.</para>
</listitem>
</varlistentry>
</variablelist>
</formalpara>
</sect2>
<sect2>
<title>Global Objects</title>
<para>For syntactic convenience, Boost.MultiArray defines two
global objects as part of its
interface. These objects play the role of object generators;
expressions involving them create other objects of interest.
</para>
<para> Under some circumstances, the two global objects may be
considered excessive overhead. Their construction can be prevented by
defining the preprocessor symbol
<literal>BOOST_MULTI_ARRAY_NO_GENERATORS</literal> before including
<filename>boost/multi_array.hpp.</filename></para>
<sect3 id="extents">
<title><literal>extents</literal></title>
<programlisting>
<![CDATA[namespace boost {
multi_array_base::extent_gen extents;
}]]>
</programlisting>
<para>Boost.MultiArray's array classes use the
<literal>extents</literal> global object to specify
array shape during their construction.
For example,
a 3 by 3 by 3 <classname>multi_array</classname> is constructed as follows:
<programlisting>multi_array&lt;int,3&gt; A(extents[3][3][3]);</programlisting>
The same array could also be created by explicitly declaring an <literal>extent_gen</literal>
object locally,, but the global object makes this declaration unnecessary.
</para>
</sect3>
<sect3 id="indices">
<title><literal>indices</literal></title>
<programlisting>
<![CDATA[namespace boost {
multi_array_base::index_gen indices;
}]]>
</programlisting>
<para>The MultiArray concept specifies an
<literal>index_gen</literal> associated type that is used to
create views.
<literal>indices</literal> is a global object that serves the role of
<literal>index_gen</literal> for all array components provided by this
library and their associated subarrays and views.
</para>
<para>For example, using the <literal>indices</literal> object,
a view of an array <literal>A</literal> is constructed as follows:
<programlisting>
A[indices[index_range(0,5)][2][index_range(2,4)]];
</programlisting>
</para>
</sect3>
</sect2>
<sect2 id="generators">
<title>View and SubArray Generators</title>
<para>
Boost.MultiArray provides traits classes, <literal>subarray_gen</literal>,
<literal>const_subarray_gen</literal>,
<literal>array_view_gen</literal>,
and <literal>const_array_view_gen</literal>, for naming of
array associated types within function templates.
In general this is no more convenient to use than the nested
type generators, but the library author found that some C++ compilers do not
properly handle templates nested within function template parameter types.
These generators constitute a workaround for this deficit.
The following code snippet illustrates
the correspondence between the <literal>array_view_gen</literal>
traits class and the <literal>array_view</literal> type associated to
an array:
<programlisting>
template &lt;typename Array&gt;
void my_function() {
typedef typename Array::template array_view&lt;3&gt;::type view1_t;
typedef typename boost::array_view_gen&lt;Array,3&gt;::type view2_t;
// ...
}
</programlisting>
In the above example, <literal>view1_t</literal> and
<literal>view2_t</literal> have the same type.
</para>
</sect2>
<sect2 id="memory_layout">
<title>Memory Layout Specifiers</title>
<para>
While a multidimensional array represents a hierarchy of containers of
elements, at some point the elements must be laid out in
memory. As a result, a single multidimensional array
can be represented in memory more than one way.
</para>
<para>For example, consider the two dimensional array shown below in
matrix notation:
<graphic fileref="matrix.gif"/>
Here is how the above array is expressed in C++:
<programlisting>
int a[3][4] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
</programlisting>
This is an example of row-major storage, where elements of each row
are stored contiguously.
While C++ transparently handles accessing elements of an array, you
can also manage the array and its indexing manually. One way that
this may be expressed in memory is as follows:
<programlisting>
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int s[] = { 4, 1 };
</programlisting>
With the latter declaration of <literal>a</literal> and
strides <literal>s</literal>, element <literal>a(i,j)</literal>
of the array can be
accessed using the expression
<programlisting>*a+i*s[0]+j*s[1]</programlisting>.
</para>
<para>The same two dimensional array could be laid out by column as follows:
<programlisting>
int a[] = { 0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11 };
int s[] = { 3, 1 };
</programlisting>
Notice that the strides here are different. As a result,
The expression given above to access values will work with this pair
of data and strides as well.
</para>
<para>In addition to dimension order, it is also possible to
store any dimension in descending order. For example, returning to the
first example, the first dimension of the example array, the
rows, could be stored in
reverse, resulting in the following:
<programlisting>
int data[] = { 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 };
int *a = data + 8;
int s[] = { -4, 1 };
</programlisting>
Note that in this example <literal>a</literal> must be explicitly set
to the origin. In the previous examples, the
first element stored in memory was the origin; here this is no longer
the case.
</para>
<para>
Alternatively, the second dimension, or the columns, could be reversed
and the rows stored in ascending order:
<programlisting>
int data[] = { 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8 };
int *a = data + 3;
int s[] = { 4, -1 };
</programlisting>
</para>
<para>
Finally, both dimensions could be stored in descending order:
<programlisting>
int data[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
int *a = data + 11;
int s[] = { -4, -1 };
</programlisting>
<literal>
</literal>
</para>
<para>
All of the above arrays are equivalent. The expression
given above for <literal>a(i,j)</literal> will yield the same value
regardless of the memory layout.
Boost.MultiArray arrays can be created with customized storage
parameters as described above. Thus, existing data can be adapted
(with <literal>multi_array_ref</literal> or
<literal>const_multi_array_ref</literal>) as suited to the array
abstraction. A common usage of this feature would be to wrap arrays
that must interoperate with Fortran routines so they can be
manipulated naturally at both the C++ and Fortran levels. The
following sections describe the Boost.MultiArray components used to
specify memory layout.
</para>
<sect3 id="c_storage_order">
<title><literal>c_storage_order</literal></title>
<programlisting>
<![CDATA[class c_storage_order {
c_storage_order();
};]]>
</programlisting>
<para><literal>c_storage_order</literal> is used to specify that an
array should store its elements using the same layout as that used by
primitive C++ multidimensional arrays, that is, from last dimension
to first. This is the default storage order for the arrays provided by
this library.</para>
</sect3>
<sect3 id="fortran_storage_order">
<title><literal>fortran_storage_order</literal></title>
<programlisting>
<![CDATA[class fortran_storage_order {
fortran_storage_order();
};]]>
</programlisting>
<para><literal>fortran_storage_order</literal> is used to specify that
an array should store its elements using the same memory layout as a
Fortran multidimensional array would, that is, from first dimension to
last.</para>
</sect3>
<sect3 id="general_storage_order">
<title><literal>general_storage_order</literal></title>
<programlisting>
<![CDATA[template <std::size_t NumDims>
class general_storage_order {
template <typename OrderingIter, typename AscendingIter>
general_storage_order(OrderingIter ordering, AscendingIter ascending);
};]]>
</programlisting>
<para><literal>general_storage_order</literal> allows the user to
specify an arbitrary memory layout for the contents of an array. The
constructed object is passed to the array constructor in order to
specify storage order.</para>
<para>
<literal>OrderingIter</literal> and <literal>AscendingIter</literal>
must model the <literal>InputIterator</literal> concept. Both
iterators must refer to a range of <literal>NumDims</literal>
elements. <literal>AscendingIter</literal> points to objects
convertible to <literal>bool</literal>. A value of
<literal>true</literal> means that a dimension is stored in ascending
order while <literal>false</literal> means that a dimension is stored
in descending order. <literal>OrderingIter</literal> specifies the
order in which dimensions are stored.
</para>
</sect3>
</sect2>
<sect2 id="range_checking">
<title>Range Checking</title>
<para>
By default, the array access methods <literal>operator()</literal> and
<literal>operator[]</literal> perform range
checking. If a supplied index is out of the range defined for an
array, an assertion will abort the program. To disable range
checking (for performance reasons in production releases), define
the <literal>BOOST_DISABLE_ASSERTS</literal> preprocessor macro prior to
including multi_array.hpp in an application.
</para>
</sect2>
</sect1>
</article>

View File

@@ -0,0 +1,25 @@
// 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 <cassert>
#include "boost/multi_array.hpp"
#include "boost/cstdlib.hpp"
int main () {
// Create a 3D array that is 3 x 4 x 2
typedef boost::multi_array<double, 3> array;
array A(boost::extents[3][4][2]);
// Assign a value to an element in the array
A[0][0][0] = 3.14;
assert(A[0][0][0] == 3.14);
return boost::exit_success;
}

View File

@@ -0,0 +1,27 @@
// 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 <cassert>
#include "boost/multi_array.hpp"
#include "boost/array.hpp"
#include "boost/cstdlib.hpp"
int main () {
// Create a 3D array that is 3 x 4 x 2
boost::array<int, 3> shape = {{ 3, 4, 2 }};
boost::multi_array<double, 3> A(shape);
// Assign a value to an element in the array
A[0][0][0] = 3.14;
assert(A[0][0][0] == 3.14);
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.
#ifndef FOR_EACH_HPP
#define FOR_EACH_HPP
//
// for_each.hpp - Writing an algorithm to transform each element of
// a multi_array
//
#include "boost/type.hpp"
template <typename Array, typename Element, typename Functor>
void for_each (const boost::type<Element>& type_dispatch,
Array A, Functor& xform) {
for_each(type_dispatch,A.begin(),A.end(),xform);
}
template <typename Element, typename Functor>
void for_each (const boost::type<Element>&,Element& Val, Functor& xform) {
Val = xform(Val);
}
template <typename Element, typename Iterator, typename Functor>
void for_each (const boost::type<Element>& type_dispatch,
Iterator begin, Iterator end,
Functor& xform) {
while (begin != end) {
for_each(type_dispatch,*begin,xform);
++begin;
}
}
template <typename Array, typename Functor>
void for_each (Array& A, Functor xform) {
// Dispatch to the proper function
for_each(boost::type<typename Array::element>(),A.begin(),A.end(),xform);
}
#endif // FOR_EACH_HPP

View File

@@ -0,0 +1,54 @@
// 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.
// foreach_test.cpp
// Let's see if this stuff works
#include "boost/multi_array.hpp"
#include "for_each.hpp"
#include <algorithm>
struct times_five {
double operator()(const int& val) { return val*5.0; }
};
int main() {
typedef boost::multi_array<double,2> array;
double data[] = {
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0
};
const int data_size=9;
array A(boost::extents[3][3]);
A.assign(data,data+data_size);
#if 0
std::copy(A.data(),A.data()+A.num_elements(),
std::ostream_iterator<double>(std::cout,","));
std::cout << "\n";
#endif
for_each(A,times_five());
#if 0
std::copy(A.data(),A.data()+A.num_elements(),
std::ostream_iterator<double>(std::cout,","));
std::cout << "\n";
#endif
return 0;
}

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.
#include "boost/multi_array.hpp"
#include "for_each.hpp"
#include <algorithm>
struct times_five {
double operator()(const int& val) { return val*5.0; }
};
int main() {
typedef boost::multi_array<double,1> array;
double data[] = {
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
7.0, 8.0, 9.0
};
const int data_size=9;
array A(boost::extents[9]);
A.assign(data,data+data_size);
#if 0
std::copy(A.begin(),A.end(),
std::ostream_iterator<double>(std::cout,","));
std::cout << "\n";
#endif
for_each(A,times_five());
#if 0
std::copy(A.begin(),A.end(),
std::ostream_iterator<double>(std::cout,","));
std::cout << "\n";
#endif
return 0;
}

View File

@@ -0,0 +1,29 @@
// 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 <cassert>
#include "boost/multi_array.hpp"
#include "boost/array.hpp"
#include "boost/cstdlib.hpp"
int main () {
// Create a 3D array that is 3 x 4 x 2
boost::array<int, 3> shape = {{ 3, 4, 2 }};
boost::multi_array<double, 3> A(shape);
typedef boost::multi_array<double, 3>::index index;
// Assign a value to an element in the array
boost::array<index, 3> idx = {{ 0, 0, 0 }};
A(idx) = 3.14;
assert(A(idx) == 3.14);
return boost::exit_success;
}

View File

@@ -0,0 +1,50 @@
// 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 <iostream>
#include "boost/multi_array.hpp"
#include "boost/array.hpp"
#include "boost/cstdlib.hpp"
template <typename Array>
void print(std::ostream& os, const Array& A)
{
typename Array::const_iterator i;
os << "[";
for (i = A.begin(); i != A.end(); ++i) {
print(os, *i);
if (boost::next(i) != A.end())
os << ',';
}
os << "]";
}
void print(std::ostream& os, const double& x)
{
os << x;
}
int main()
{
typedef boost::multi_array<double, 2> array;
double values[] = {
0, 1, 2,
3, 4, 5
};
const int values_size=6;
array A(boost::extents[2][3]);
A.assign(values,values+values_size);
print(std::cout, A);
return boost::exit_success;
}
// The output is:
// [[0,1,2],[3,4,5]]

View File

@@ -0,0 +1,57 @@
// Copyright 2008 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_from_other.cpp - an experiment in writing a resize function for
// multi_arrays that will use the extents from another to build itself.
//
#include <boost/multi_array.hpp>
#include <boost/static_assert.hpp>
#include <boost/array.hpp>
#include <algorithm>
template <typename T, typename U, std::size_t N>
void
resize_from_MultiArray(boost::multi_array<T,N>& marray, U& other) {
// U must be a model of MultiArray
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<U,U::dimensionality> >();
// U better have U::dimensionality == N
BOOST_STATIC_ASSERT(U::dimensionality == N);
boost::array<typename boost::multi_array<T,N>::size_type, N> shape;
std::copy(other.shape(), other.shape()+N, shape.begin());
marray.resize(shape);
}
#include <iostream>
int main () {
boost::multi_array<int,2> A(boost::extents[5][4]), B;
boost::multi_array<int,3> C;
resize_from_MultiArray(B,A);
#if 0
resize_from_MultiArray(C,A); // Compile-time error
#endif
std::cout << B.shape()[0] << ", " << B.shape()[1] << '\n';
}

View File

@@ -0,0 +1,53 @@
// 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/cstdlib.hpp"
int
main()
{
const int ndims=3;
typedef boost::multi_array<int,ndims> array;
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 myarray(boost::extents[2][3][4]);
myarray.assign(data,data+data_size);
//
// array_view dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
typedef array::index_range range;
array::array_view<ndims>::type myview =
myarray[boost::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)
assert(myview[i][j][k] == myarray[i][j+1][k*2]);
return boost::exit_success;
}

View File

@@ -0,0 +1,54 @@
// 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/cstdlib.hpp"
int
main()
{
using boost::extents;
using boost::indices;
typedef boost::multi_array<int,3> array;
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 myarray(extents[2][3][4]);
myarray.assign(data,data+data_size);
//
// array_view dims:
// [base,stride,bound)
// [0,1,2), [1,1,3), [0,2,4)
//
typedef boost::multi_array_types::index_range range;
array::array_view<3>::type myview =
myarray[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)
assert(myview[i][j][k] == myarray[i][j+1][k*2]);
return boost::exit_success;
}

View File

@@ -0,0 +1,13 @@
<html>
<head>
<meta http-equiv="refresh" content="0; URL=doc/index.html">
</head>
<body>
Automatic redirection failed, please go to
<a href="doc/index.html">doc/index.html</a>.&nbsp;<hr>
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body>
</html>

View File

@@ -0,0 +1,15 @@
{
"key": "multi_array",
"name": "Multi-Array",
"authors": [
"Ron Garcia"
],
"description": "Boost.MultiArray provides a generic N-dimensional array concept definition and common implementations of that interface.",
"category": [
"Containers",
"Math"
],
"maintainers": [
"Ronald Garcia <garcia -at- osl.iu.edu>"
]
}

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;
}