1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Boost.MultiArray Reference Manual</title><meta name="generator" content="DocBook XSL Stylesheets V1.62.4"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="article" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="id727825"></a>Boost.MultiArray Reference Manual</h1></div><div><div class="author"><h3 class="author"><span class="firstname">Ronald</span> <span class="surname">Garcia</span></h3><div class="affiliation"><span class="orgname">Indiana University<br></span><span class="orgdiv">Open Systems Lab<br></span></div></div></div><div><p class="copyright">Copyright © 2002 The Trustees of Indiana University</p></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="#synopsis">Library Synopsis</a></span></dt><dt><span class="sect1"><a href="#MultiArray">MultiArray Concept</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id832486">Notation</a></span></dt><dt><span class="sect2"><a href="#id832654">Associated Types</a></span></dt><dt><span class="sect2"><a href="#id833164">Valid expressions</a></span></dt><dt><span class="sect2"><a href="#id833954">Complexity guarantees</a></span></dt><dt><span class="sect2"><a href="#id833978">Invariants</a></span></dt><dt><span class="sect2"><a href="#view_types">Associated Types for Views</a></span></dt><dt><span class="sect2"><a href="#id835348">Models</a></span></dt></dl></dd><dt><span class="sect1"><a href="#array_types">Array Components</a></span></dt><dd><dl><dt><span class="sect2"><a href="#multi_array">multi_array</a></span></dt><dt><span class="sect2"><a href="#multi_array_ref">multi_array_ref</a></span></dt><dt><span class="sect2"><a href="#const_multi_array_ref">const_multi_array_ref</a></span></dt></dl></dd><dt><span class="sect1"><a href="#auxiliary">Auxiliary Components</a></span></dt><dd><dl><dt><span class="sect2"><a href="#multi_array_types">multi_array_types</a></span></dt><dt><span class="sect2"><a href="#extent_range">extent_range</a></span></dt><dt><span class="sect2"><a href="#extent_gen">extent_gen</a></span></dt><dt><span class="sect2"><a href="#id860298">Global Objects</a></span></dt><dt><span class="sect2"><a href="#generators">View and SubArray Generators</a></span></dt><dt><span class="sect2"><a href="#memory_layout">Memory Layout Specifiers</a></span></dt></dl></dd></dl></div><p>Boost.MultiArray is composed of several components. |
---|
2 | The MultiArray concept defines a generic interface to multidimensional |
---|
3 | containers. |
---|
4 | <tt class="literal">multi_array</tt> is a general purpose container class |
---|
5 | that models MultiArray. <tt class="literal">multi_array_ref</tt> |
---|
6 | and <tt class="literal">const_multi_array_ref</tt> are adapter |
---|
7 | classes. Using them, |
---|
8 | you can manipulate any block of contiguous data as though it were a |
---|
9 | <tt class="literal">multi_array</tt>. |
---|
10 | <tt class="literal">const_multi_array_ref</tt> differs from |
---|
11 | <tt class="literal">multi_array_ref</tt> in that its elements cannot |
---|
12 | be modified through its interface. Finally, several auxiliary classes are used |
---|
13 | to create and specialize arrays and some global objects are defined as |
---|
14 | part of the library interface.</p><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="synopsis"></a>Library Synopsis</h2></div></div><div></div></div><p>To use Boost.MultiArray, you must include the header |
---|
15 | <tt class="filename">boost/multi_array.hpp</tt> in your source. This file |
---|
16 | brings the following declarations into scope:</p><pre class="programlisting"> |
---|
17 | namespace boost { |
---|
18 | |
---|
19 | namespace multi_array_types { |
---|
20 | typedef *implementation-defined* index; |
---|
21 | typedef *implementation-defined* size_type; |
---|
22 | typedef *implementation-defined* difference_type; |
---|
23 | typedef *implementation-defined* index_range; |
---|
24 | typedef *implementation-defined* extent_range; |
---|
25 | typedef *implementation-defined* index_gen; |
---|
26 | typedef *implementation-defined* extent_gen; |
---|
27 | } |
---|
28 | |
---|
29 | template <typename ValueType, |
---|
30 | std::size_t NumDims, |
---|
31 | typename Allocator = std::allocator<ValueType> > |
---|
32 | class multi_array; |
---|
33 | |
---|
34 | template <typename ValueType, |
---|
35 | std::size_t NumDims> |
---|
36 | class multi_array_ref; |
---|
37 | |
---|
38 | template <typename ValueType, |
---|
39 | std::size_t NumDims> |
---|
40 | class const_multi_array_ref; |
---|
41 | |
---|
42 | multi_array_types::extent_gen extents; |
---|
43 | multi_array_types::index_gen indices; |
---|
44 | |
---|
45 | template <typename Array, int N> class subarray_gen; |
---|
46 | template <typename Array, int N> class const_subarray_gen; |
---|
47 | template <typename Array, int N> class array_view_gen; |
---|
48 | template <typename Array, int N> class const_array_view_gen; |
---|
49 | |
---|
50 | class c_storage_order; |
---|
51 | class fortran_storage_order; |
---|
52 | template <std::size_t NumDims> class general_storage_order; |
---|
53 | |
---|
54 | } |
---|
55 | </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="MultiArray"></a>MultiArray Concept</h2></div></div><div></div></div><p>The MultiArray |
---|
56 | concept defines an interface to hierarchically nested |
---|
57 | containers. It specifies operations for accessing elements, |
---|
58 | traversing containers, and creating views |
---|
59 | of array data. |
---|
60 | MultiArray defines |
---|
61 | a flexible memory model that accomodates |
---|
62 | a variety of data layouts. |
---|
63 | </p><p> |
---|
64 | At each level (or dimension) of a MultiArray's |
---|
65 | container hierarchy lie a set of ordered containers, each of which |
---|
66 | contains the same number and type of values. The depth of this |
---|
67 | container hierarchy is the MultiArray's <span class="emphasis"><em>dimensionality</em></span>. |
---|
68 | MultiArray is recursively defined; the |
---|
69 | containers at each level of the container hierarchy model |
---|
70 | MultiArray as well. While each dimension of a MultiArray |
---|
71 | has its own size, the list of sizes for all dimensions |
---|
72 | defines the <span class="emphasis"><em>shape</em></span> of the entire MultiArray. |
---|
73 | At the base of this hierarchy lie 1-dimensional |
---|
74 | MultiArrays. Their values are the contained |
---|
75 | objects of interest and not part of the container hierarchy. These are |
---|
76 | the MultiArray's elements. |
---|
77 | </p><p> |
---|
78 | Like other container concepts, MultiArray exports |
---|
79 | iterators to traverse its values. In addition, values can be |
---|
80 | addressed directly using the familiar bracket notation. |
---|
81 | </p><p> |
---|
82 | MultiArray also specifies |
---|
83 | routines for creating |
---|
84 | specialized views. A <span class="emphasis"><em>view</em></span> lets you treat a |
---|
85 | subset of the underlying |
---|
86 | elements in a MultiArray as though it were a separate |
---|
87 | MultiArray. Since a view refers to the same underlying elements, |
---|
88 | changes made to a view's elements will be reflected in the original |
---|
89 | MultiArray. For |
---|
90 | example, given a 3-dimensional "cube" of elements, a 2-dimensional |
---|
91 | slice can be viewed as if it were an independent |
---|
92 | MultiArray. |
---|
93 | |
---|
94 | Views are created using <tt class="literal">index_gen</tt> and |
---|
95 | <tt class="literal">index_range</tt> objects. |
---|
96 | <tt class="literal">index_range</tt>s denote elements from a certain |
---|
97 | dimension that are to be included in a |
---|
98 | view. <tt class="literal">index_gen</tt> aggregates range data and performs |
---|
99 | bookkeeping to determine the view type to be returned. |
---|
100 | |
---|
101 | MultiArray's <tt class="literal">operator[]</tt> |
---|
102 | must be passed the result |
---|
103 | of <tt class="literal">N</tt> chained calls to |
---|
104 | <tt class="literal">index_gen::operator[]</tt>, i.e. |
---|
105 | |
---|
106 | </p><pre class="programlisting">indices[a0][a1]...[aN]; |
---|
107 | </pre><p> |
---|
108 | |
---|
109 | where <tt class="literal">N</tt> is the |
---|
110 | MultiArray's dimensionality and |
---|
111 | <tt class="literal">indices</tt> an object of type <tt class="literal">index_gen</tt>. |
---|
112 | |
---|
113 | The view type is dependent upon the number of degenerate dimensions |
---|
114 | specified to <tt class="literal">index_gen</tt>. A degenerate dimension |
---|
115 | occurs when a single-index is specified to |
---|
116 | <tt class="literal">index_gen</tt> for a certain dimension. For example, if |
---|
117 | <tt class="literal">indices</tt> is an object of type |
---|
118 | <tt class="literal">index_gen</tt>, then the following example: |
---|
119 | |
---|
120 | </p><pre class="programlisting">indices[index_range(0,5)][2][index_range(0,4)]; |
---|
121 | </pre><p> |
---|
122 | |
---|
123 | has a degenerate second dimension. The view generated from the above |
---|
124 | specification will have 2 dimensions with shape <tt class="literal">5 x 4</tt>. |
---|
125 | If the "<tt class="literal">2</tt>" above were replaced with |
---|
126 | another <tt class="literal">index_range</tt> object, for example: |
---|
127 | |
---|
128 | </p><pre class="programlisting">indices[index_range(0,5)][index_range(0,2)][index_range(0,4)]; |
---|
129 | </pre><p> |
---|
130 | |
---|
131 | then the view would have 3 dimensions.</p><p> |
---|
132 | MultiArray exports |
---|
133 | information regarding the memory |
---|
134 | layout of its contained elements. Its memory model for elements is |
---|
135 | completely defined by 4 properties: the origin, shape, index bases, |
---|
136 | and strides. The origin is the address in memory of the element |
---|
137 | accessed as <tt class="literal">a[0][0]...[0]</tt>, where |
---|
138 | <tt class="literal">a</tt> is a MultiArray. The shape is a list of numbers |
---|
139 | specifying the size of containers at each dimension. For example, the |
---|
140 | first extent is the size of the outermost container, the second extent |
---|
141 | is the size of its subcontainers, and so on. The index bases are a |
---|
142 | list of signed values specifying the index of the first value in a |
---|
143 | container. All containers at the same dimension share the same index |
---|
144 | base. Note that since positive index bases are |
---|
145 | possible, the origin need not exist in order to determine the location |
---|
146 | in memory of the MultiArray's elements. |
---|
147 | The strides determine how index values are mapped to memory offsets. |
---|
148 | They accomodate a |
---|
149 | number of possible element layouts. For example, the elements of a 2 |
---|
150 | dimensional array can be stored by row (i.e., the elements of each row |
---|
151 | are stored contiguously) or by column (i.e., the elements of each |
---|
152 | column are stored contiguously). |
---|
153 | </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id832486"></a>Notation</h3></div></div><div></div></div><p>What follows are the descriptions of symbols that will be used |
---|
154 | to describe the MultiArray interface.</p><div class="table"><a name="id832495"></a><p class="title"><b>Table 1. Notation</b></p><table summary="Notation" border="1"><colgroup><col><col></colgroup><tbody><tr><td><tt class="literal">A</tt></td><td>A type that is a model of MultiArray |
---|
155 | </td></tr><tr><td><tt class="literal">a</tt></td><td>An object of type <tt class="literal">A</tt></td></tr><tr><td><tt class="literal">NumDims</tt></td><td>The numeric dimension parameter associated with |
---|
156 | <tt class="literal">A</tt>.</td></tr><tr><td><tt class="literal">Dims</tt></td><td>Some numeric dimension parameter such that |
---|
157 | <tt class="literal">0<Dims<NumDims</tt>. |
---|
158 | </td></tr><tr><td><tt class="literal">indices</tt></td><td>An object created by some number of chained calls |
---|
159 | to <tt class="literal">index_gen::operator[](index_range)</tt>.</td></tr><tr><td><tt class="literal">index_list</tt></td><td>An object whose type models |
---|
160 | <a href="../../utility/Collection.html" target="_top">Collection</a></td></tr><tr><td><tt class="literal">idx</tt></td><td>A signed integral value.</td></tr><tr><td><tt class="literal">tmp</tt></td><td>An object of type |
---|
161 | <tt class="literal">boost::array<index,NumDims></tt></td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id832654"></a>Associated Types</h3></div></div><div></div></div><p> |
---|
162 | </p><div class="table"><a name="id832662"></a><p class="title"><b>Table 2. Associated Types</b></p><table summary="Associated Types" border="1"><colgroup><col><col></colgroup><thead><tr><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><tt class="literal">value_type</tt></td><td>This is the value type of the container. |
---|
163 | If <tt class="literal">NumDims == 1</tt>, then this is |
---|
164 | <tt class="literal">element</tt>. Otherwise, this is the value type of the |
---|
165 | immediately nested containers. |
---|
166 | </td></tr><tr><td><tt class="literal">reference</tt></td><td> |
---|
167 | This is the reference type of the contained value. |
---|
168 | If <tt class="literal">NumDims == 1</tt>, then this is |
---|
169 | <tt class="literal">element&</tt>. Otherwise, this is the same type as |
---|
170 | <tt class="literal">template subarray<NumDims-1>::type</tt>. |
---|
171 | </td></tr><tr><td><tt class="literal">const_reference</tt></td><td> |
---|
172 | This is the const reference type of the contained value. |
---|
173 | If <tt class="literal">NumDims == 1</tt>, then this is |
---|
174 | <tt class="literal">const element&</tt>. Otherwise, this is the same |
---|
175 | type as |
---|
176 | <tt class="literal">template const_subarray<NumDims-1>::type</tt>. |
---|
177 | </td></tr><tr><td><tt class="literal">size_type</tt></td><td> |
---|
178 | This is an unsigned integral type. It is primarily used to specify array shape. |
---|
179 | </td></tr><tr><td><tt class="literal">difference_type</tt></td><td> |
---|
180 | This is a signed integral type used to represent the distance between two |
---|
181 | iterators. It is the same type as |
---|
182 | <tt class="literal">std::iterator_traits<iterator>::difference_type</tt>. |
---|
183 | </td></tr><tr><td><tt class="literal">iterator</tt></td><td> |
---|
184 | This is an iterator over the values of <tt class="literal">A</tt>. |
---|
185 | If <tt class="literal">NumDims == 1</tt>, then it models |
---|
186 | <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html" target="_top"> |
---|
187 | <tt class="literal">Random Access Iterator</tt></a>. |
---|
188 | Otherwise it models |
---|
189 | <a href="./iterator_categories.html#concept_RandomAccessTraversalIterator" target="_top"> |
---|
190 | Random Access Traversal Iterator</a>, |
---|
191 | <a href="./iterator_categories.html#concept_ReadableIterator" target="_top"> |
---|
192 | Readable Iterator</a>, and |
---|
193 | <a href="./iterator_categories.html#concept_WritableIterator" target="_top"> |
---|
194 | Writable Iterator</a>. |
---|
195 | </td></tr><tr><td><tt class="literal">const_iterator</tt></td><td> |
---|
196 | This is the const iterator over the values of <tt class="literal">A</tt>. |
---|
197 | </td></tr><tr><td><tt class="literal">reverse_iterator</tt></td><td> |
---|
198 | This is the reversed iterator, used to iterate backwards over the values of |
---|
199 | <tt class="literal">A</tt>. |
---|
200 | </td></tr><tr><td><tt class="literal">const_reverse_iterator</tt></td><td> |
---|
201 | This is the reversed const iterator. |
---|
202 | <tt class="literal">A</tt>. |
---|
203 | </td></tr><tr><td><tt class="literal">element</tt></td><td> |
---|
204 | This is the type of objects stored at the base of the |
---|
205 | hierarchy of MultiArrays. It is the same as |
---|
206 | <tt class="literal">template subarray<1>::value_type</tt></td></tr><tr><td><tt class="literal">index</tt></td><td> |
---|
207 | This is a signed integral type used for indexing into <tt class="literal">A</tt>. It |
---|
208 | is also used to represent strides and index bases. |
---|
209 | </td></tr><tr><td><tt class="literal">index_gen</tt></td><td> |
---|
210 | This type is used to create a tuple of <tt class="literal">index_range</tt>s |
---|
211 | passed to <tt class="literal">operator[]</tt> to create |
---|
212 | an <tt class="literal">array_view<Dims>::type</tt> object. |
---|
213 | </td></tr><tr><td><tt class="literal">index_range</tt></td><td> |
---|
214 | This type specifies a range of indices over some dimension of a |
---|
215 | MultiArray. This range will be visible through an |
---|
216 | <tt class="literal">array_view<Dims>::type</tt> object. |
---|
217 | </td></tr><tr><td><tt class="literal">template subarray<Dims>::type</tt></td><td> |
---|
218 | This is subarray type with <tt class="literal">Dims</tt> dimensions. |
---|
219 | It is the reference type of the <tt class="literal">(NumDims - Dims)</tt> |
---|
220 | dimension of <tt class="literal">A</tt> and also models |
---|
221 | MultiArray. |
---|
222 | </td></tr><tr><td><tt class="literal">template const_subarray<Dims>::type</tt></td><td> |
---|
223 | This is the const subarray type. |
---|
224 | </td></tr><tr><td><tt class="literal">template array_view<Dims>::type</tt></td><td> |
---|
225 | This is the view type with <tt class="literal">Dims</tt> dimensions. It is |
---|
226 | returned by calling <tt class="literal">operator[](<tt class="literal">indices</tt>)</tt>. |
---|
227 | It models MultiArray. |
---|
228 | </td></tr><tr><td><tt class="literal">template |
---|
229 | const_array_view<Dims>::type</tt></td><td> |
---|
230 | This is the const view type with <tt class="literal">Dims</tt> dimensions. |
---|
231 | </td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id833164"></a>Valid expressions</h3></div></div><div></div></div><div class="table"><a name="id833168"></a><p class="title"><b>Table 3. Valid Expressions</b></p><table summary="Valid Expressions" border="1"><colgroup><col><col><col></colgroup><thead><tr><th>Expression</th><th>Return type</th><th>Semantics</th></tr></thead><tbody><tr><td><tt class="literal">a.shape()</tt></td><td><tt class="literal">const size_type*</tt></td><td> |
---|
232 | This returns a list of <tt class="literal">NumDims</tt> elements specifying the |
---|
233 | extent of each array dimension. |
---|
234 | </td></tr><tr><td><tt class="literal">a.strides()</tt></td><td><tt class="literal">const index*</tt></td><td> |
---|
235 | This returns a list of <tt class="literal">NumDims</tt> elements specifying the |
---|
236 | stride associated with each array dimension. When accessing values, |
---|
237 | strides is used to calculate an element's location in memory. |
---|
238 | </td></tr><tr><td><tt class="literal">a.index_bases()</tt></td><td><tt class="literal">const index*</tt></td><td> |
---|
239 | This returns a list of <tt class="literal">NumDims</tt> elements specifying the |
---|
240 | numeric index of the first element for each array dimension. |
---|
241 | </td></tr><tr><td><tt class="literal">a.origin()</tt></td><td><tt class="literal">element*</tt> if <tt class="literal">a</tt> is mutable, |
---|
242 | <tt class="literal">const element*</tt> otherwise. |
---|
243 | </td><td> |
---|
244 | This returns the address of the element accessed by the expression |
---|
245 | <tt class="literal">a[0][0]...[0].</tt>. If the index bases are positive, |
---|
246 | this element won't exist, but the address can still be used to locate |
---|
247 | a valid element given its indices. |
---|
248 | </td></tr><tr><td><tt class="literal">a.num_dimensions()</tt></td><td><tt class="literal">size_type</tt></td><td>This returns the number of dimensions of the array |
---|
249 | (note that <tt class="literal">a.num_dimensions() == NumDims</tt>).</td></tr><tr><td><tt class="literal">a.num_elements()</tt></td><td><tt class="literal">size_type</tt></td><td>This returns the number of elements contained |
---|
250 | in the array. It is equivalent to the following code: |
---|
251 | <pre class="programlisting"> |
---|
252 | std::accumulate(a.shape(),a.shape+a.num_dimensions(), |
---|
253 | size_type(1),std::multiplies<size_type>()); |
---|
254 | </pre></td></tr><tr><td><tt class="literal">a.size()</tt></td><td><tt class="literal">size_type</tt></td><td> |
---|
255 | This returns the number of values contained in |
---|
256 | <tt class="literal">a</tt>. It is equivalent to <tt class="literal">a.shape()[0];</tt></td></tr><tr><td><tt class="literal">a(index_list)</tt></td><td><tt class="literal">element&</tt>; if <tt class="literal">a</tt> is mutable, |
---|
257 | <tt class="literal">const element&</tt> otherwise. |
---|
258 | </td><td> |
---|
259 | This expression accesses a specific element of |
---|
260 | <tt class="literal">a</tt>.<tt class="literal">index_list</tt> is the unique set |
---|
261 | of indices that address the element returned. It is |
---|
262 | equivalent to the following code (disregarding intermediate temporaries): |
---|
263 | <pre class="programlisting"> |
---|
264 | // multiply indices by strides |
---|
265 | std::transform(index_list.begin(), index_list.end(), |
---|
266 | a.strides(), tmp.begin(), std::multiplies<index>()), |
---|
267 | |
---|
268 | // add the sum of the products to the origin |
---|
269 | *std::accumulate(tmp.begin(), tmp.end(), a.origin()); |
---|
270 | </pre></td></tr><tr><td><tt class="literal">a.begin()</tt></td><td><tt class="literal">iterator</tt> if <tt class="literal">a</tt> is mutable, |
---|
271 | <tt class="literal">const_iterator</tt> otherwise. |
---|
272 | </td><td>This returns an iterator pointing to the beginning of |
---|
273 | <tt class="literal">a</tt>.</td></tr><tr><td><tt class="literal">a.end()</tt></td><td><tt class="literal">iterator</tt> if <tt class="literal">a</tt> is mutable, |
---|
274 | <tt class="literal">const_iterator</tt> otherwise. |
---|
275 | </td><td>This returns an iterator pointing to the end of |
---|
276 | <tt class="literal">a</tt>.</td></tr><tr><td><tt class="literal">a.rbegin()</tt></td><td><tt class="literal">reverse_iterator</tt> if <tt class="literal">a</tt> is mutable, |
---|
277 | <tt class="literal">const_reverse_iterator</tt> otherwise. |
---|
278 | </td><td>This returns a reverse iterator pointing to the |
---|
279 | beginning of <tt class="literal">a</tt> reversed. |
---|
280 | </td></tr><tr><td><tt class="literal">a.rend()</tt></td><td><tt class="literal">reverse_iterator</tt> if <tt class="literal">a</tt> is mutable, |
---|
281 | <tt class="literal">const_reverse_iterator</tt> otherwise. |
---|
282 | </td><td> |
---|
283 | This returns a reverse iterator pointing to the end of <tt class="literal">a</tt> |
---|
284 | reversed. |
---|
285 | </td></tr><tr><td><tt class="literal">a[idx]</tt></td><td><tt class="literal">reference</tt> if <tt class="literal">a</tt> is mutable, |
---|
286 | <tt class="literal">const_reference</tt> otherwise. |
---|
287 | </td><td> |
---|
288 | This returns a reference type that is bound to the index |
---|
289 | <tt class="literal">idx</tt> value of <tt class="literal">a</tt>. Note that if |
---|
290 | <tt class="literal">i</tt> is the index base for this dimension, the above |
---|
291 | expression returns the <tt class="literal">(idx-i)</tt>th element (counting |
---|
292 | from zero). The expression is equivalent to |
---|
293 | <tt class="literal">*(a.begin()+idx-a.index_bases()[0]);</tt>. |
---|
294 | </td></tr><tr><td><tt class="literal">a[indices]</tt></td><td><tt class="literal">array_view<Dims>::type</tt> if |
---|
295 | <tt class="literal">a</tt> is mutable, |
---|
296 | <tt class="literal">const_array_view<Dims>::type</tt> otherwise. |
---|
297 | </td><td> |
---|
298 | This expression generates a view of the array determined by the |
---|
299 | <tt class="literal">index_range</tt> and <tt class="literal">index</tt> values |
---|
300 | used to construct <tt class="literal">indices</tt>. |
---|
301 | </td></tr><tr><td><tt class="literal">a == b</tt></td><td>bool</td><td>This performs a lexicographical comparison of the |
---|
302 | values of <tt class="literal">a</tt> and <tt class="literal">b</tt>. The element |
---|
303 | type must model <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top">EqualityComparable</a> for this |
---|
304 | expression to be valid.</td></tr><tr><td><tt class="literal">a < b</tt></td><td>bool</td><td>This performs a lexicographical comparison of the |
---|
305 | values of <tt class="literal">a</tt> and <tt class="literal">b</tt>. The element |
---|
306 | type must model <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top">LessThanComparable</a> for this |
---|
307 | expression to be valid.</td></tr><tr><td><tt class="literal">a <= b</tt></td><td>bool</td><td>This performs a lexicographical comparison of the |
---|
308 | values of <tt class="literal">a</tt> and <tt class="literal">b</tt>. The element |
---|
309 | type must model <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top">EqualityComparable</a> and |
---|
310 | <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top">LessThanComparable</a> for this |
---|
311 | expression to be valid.</td></tr><tr><td><tt class="literal">a > b</tt></td><td>bool</td><td>This performs a lexicographical comparison of the |
---|
312 | values of <tt class="literal">a</tt> and <tt class="literal">b</tt>. The element |
---|
313 | type must model <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top">EqualityComparable</a> and |
---|
314 | <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top">LessThanComparable</a> for this |
---|
315 | expression to be valid.</td></tr><tr><td><tt class="literal">a >= b</tt></td><td>bool</td><td>This performs a lexicographical comparison of the |
---|
316 | values of <tt class="literal">a</tt> and <tt class="literal">b</tt>. The element |
---|
317 | type must model <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top">LessThanComparable</a> for this |
---|
318 | expression to be valid.</td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id833954"></a>Complexity guarantees</h3></div></div><div></div></div><tt class="literal">begin()</tt> and <tt class="literal">end()</tt> execute in amortized |
---|
319 | constant time. |
---|
320 | <tt class="literal">size()</tt> executes in at most linear time in the |
---|
321 | MultiArray's size. |
---|
322 | </div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id833978"></a>Invariants</h3></div></div><div></div></div><div class="table"><a name="id833984"></a><p class="title"><b>Table 4. Invariants</b></p><table summary="Invariants" border="1"><colgroup><col><col></colgroup><tbody><tr><td>Valid range</td><td><tt class="literal">[a.begin(),a.end())</tt> is a valid range. |
---|
323 | </td></tr><tr><td>Range size</td><td><tt class="literal">a.size() == std::distance(a.begin(),a.end());</tt>. |
---|
324 | </td></tr><tr><td>Completeness</td><td> |
---|
325 | Iteration through the range |
---|
326 | <tt class="literal">[a.begin(),a.end())</tt> will traverse across every |
---|
327 | <tt class="literal">value_type</tt> of <tt class="literal">a</tt>. |
---|
328 | </td></tr><tr><td>Accessor Equivalence</td><td> |
---|
329 | Calling <tt class="literal">a[a1][a2]...[aN]</tt> where <tt class="literal">N==NumDims</tt> |
---|
330 | yields the same result as calling |
---|
331 | <tt class="literal">a(index_list)</tt>, where <tt class="literal">index_list</tt> |
---|
332 | is a <a href="../../utility/Collection.html" target="_top">Collection</a> containing the values <tt class="literal">a1...aN</tt>. |
---|
333 | </td></tr></tbody></table></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="view_types"></a>Associated Types for Views</h3></div></div><div></div></div><p>The following MultiArray associated |
---|
334 | types define the interface for creating views of existing |
---|
335 | MultiArrays. Their interfaces and roles in the |
---|
336 | concept are described below.</p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="index_range"></a><tt class="literal">index_range</tt></h4></div></div><div></div></div><p><tt class="literal">index_range</tt> objects represent half-open |
---|
337 | strided intervals. They are aggregated (using an |
---|
338 | <tt class="literal">index_gen</tt> object) and passed to |
---|
339 | a MultiArray's <tt class="literal">operator[]</tt> |
---|
340 | to create an array view. When creating a view, |
---|
341 | each <tt class="literal">index_range</tt> denotes a range of |
---|
342 | valid indices along one dimension of a MultiArray. |
---|
343 | Elements that are accessed through the set of ranges specified will be |
---|
344 | included in the constructed view. In some cases, an |
---|
345 | <tt class="literal">index_range</tt> is created without specifying start |
---|
346 | or finish values. In those cases, the object is interpreted to |
---|
347 | start at the beginning of a MultiArray dimension |
---|
348 | and end at its end.</p><p> |
---|
349 | <tt class="literal">index_range</tt> objects can be constructed and modified |
---|
350 | several ways in order to allow convenient and clear expression of a |
---|
351 | range of indices. To specify ranges, <tt class="literal">index_range</tt> |
---|
352 | supports a set of constructors, mutating member functions, and a novel |
---|
353 | specification involving inequality operators. Using inequality |
---|
354 | operators, a half open range [5,10) can be specified as follows: |
---|
355 | </p><pre class="programlisting">5 <= index_range() < 10;</pre><p> or |
---|
356 | </p><pre class="programlisting">4 < index_range() <= 9;</pre><p> and so on. |
---|
357 | |
---|
358 | The following describes the |
---|
359 | <tt class="literal">index_range</tt> interface. |
---|
360 | </p><div class="table"><a name="id834212"></a><p class="title"><b>Table 5. Notation</b></p><table summary="Notation" border="1"><colgroup><col><col></colgroup><tbody><tr><td><tt class="literal">i</tt></td><td>An object of type <tt class="literal">index_range</tt>.</td></tr><tr><td><tt class="literal">idx,idx1,idx2,idx3</tt></td><td>Objects of type <tt class="literal">index</tt>.</td></tr></tbody></table></div><div class="table"><a name="id834265"></a><p class="title"><b>Table 6. Associated Types</b></p><table summary="Associated Types" border="1"><colgroup><col><col></colgroup><thead><tr><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><tt class="literal">index</tt></td><td>This is a signed integral type. It is used to |
---|
361 | specify the start, finish, and stride values.</td></tr><tr><td><tt class="literal">size_type</tt></td><td>This is an unsigned integral type. It is used to |
---|
362 | report the size of the range an <tt class="literal">index_range</tt> |
---|
363 | represents.</td></tr></tbody></table></div><div class="table"><a name="id834328"></a><p class="title"><b>Table 7. Valid Expressions</b></p><table summary="Valid Expressions" border="1"><colgroup><col><col><col></colgroup><thead><tr><th>Expression</th><th>Return type</th><th>Semantics</th></tr></thead><tbody><tr><td><tt class="literal">index_range(idx1,idx2,idx3)</tt></td><td><tt class="literal">index_range</tt></td><td>This constructs an <tt class="literal">index_range</tt> |
---|
364 | representing the interval <tt class="literal">[idx1,idx2)</tt> |
---|
365 | with stride <tt class="literal">idx3</tt>.</td></tr><tr><td><tt class="literal">index_range(idx1,idx2)</tt></td><td><tt class="literal">index_range</tt></td><td>This constructs an <tt class="literal">index_range</tt> |
---|
366 | representing the interval <tt class="literal">[idx1,idx2)</tt> |
---|
367 | with unit stride. It is equivalent to |
---|
368 | <tt class="literal">index_range(idx1,idx2,1)</tt>.</td></tr><tr><td><tt class="literal">index_range()</tt></td><td><tt class="literal">index_range</tt></td><td>This construct an <tt class="literal">index_range</tt> |
---|
369 | with unspecified start and finish values.</td></tr><tr><td><tt class="literal">i.start(idx1)</tt></td><td><tt class="literal">index&</tt></td><td>This sets the start index of <tt class="literal">i</tt> to |
---|
370 | <tt class="literal">idx</tt>.</td></tr><tr><td><tt class="literal">i.finish(idx)</tt></td><td><tt class="literal">index&</tt></td><td>This sets the finish index of <tt class="literal">i</tt> to |
---|
371 | <tt class="literal">idx</tt>.</td></tr><tr><td><tt class="literal">i.stride(idx)</tt></td><td><tt class="literal">index&</tt></td><td>This sets the stride length of <tt class="literal">i</tt> to |
---|
372 | <tt class="literal">idx</tt>.</td></tr><tr><td><tt class="literal">i.start()</tt></td><td><tt class="literal">index</tt></td><td>This returns the start index of <tt class="literal">i</tt>.</td></tr><tr><td><tt class="literal">i.finish()</tt></td><td><tt class="literal">index</tt></td><td>This returns the finish index of <tt class="literal">i</tt>.</td></tr><tr><td><tt class="literal">i.stride()</tt></td><td><tt class="literal">index</tt></td><td>This returns the stride length of <tt class="literal">i</tt>.</td></tr><tr><td><tt class="literal">i.get_start(idx)</tt></td><td><tt class="literal">index</tt></td><td>If <tt class="literal">i</tt> specifies a start |
---|
373 | value, this is equivalent to <tt class="literal">i.start()</tt>. Otherwise it |
---|
374 | returns <tt class="literal">idx</tt>.</td></tr><tr><td><tt class="literal">i.get_finish(idx)</tt></td><td><tt class="literal">index</tt></td><td>If <tt class="literal">i</tt> specifies a finish |
---|
375 | value, this is equivalent to <tt class="literal">i.finish()</tt>. Otherwise it |
---|
376 | returns <tt class="literal">idx</tt>.</td></tr><tr><td><tt class="literal">i.size(idx)</tt></td><td><tt class="literal">size_type</tt></td><td>If <tt class="literal">i</tt> specifies a both finish and |
---|
377 | start values, this is equivalent to |
---|
378 | <tt class="literal">(i.finish()-i.start())/i.stride()</tt>. Otherwise it |
---|
379 | returns <tt class="literal">idx</tt>.</td></tr><tr><td><tt class="literal">i < idx</tt></td><td><tt class="literal">index</tt></td><td>This is another syntax for specifying the finish |
---|
380 | value. This notation does not include |
---|
381 | <tt class="literal">idx</tt> in the range of valid indices. It is equivalent to |
---|
382 | <tt class="literal">index_range(r.start(), idx, r.stride())</tt></td></tr><tr><td><tt class="literal">i <= idx</tt></td><td><tt class="literal">index</tt></td><td>This is another syntax for specifying the finish |
---|
383 | value. This notation includes |
---|
384 | <tt class="literal">idx</tt> in the range of valid indices. It is equivalent to |
---|
385 | <tt class="literal">index_range(r.start(), idx + 1, r.stride())</tt></td></tr><tr><td><tt class="literal">idx < i</tt></td><td><tt class="literal">index</tt></td><td>This is another syntax for specifying the start |
---|
386 | value. This notation does not include |
---|
387 | <tt class="literal">idx</tt> in the range of valid indices. It is equivalent to |
---|
388 | <tt class="literal">index_range(idx + 1, i.finish(), i.stride())</tt>.</td></tr><tr><td><tt class="literal">idx <= i</tt></td><td><tt class="literal">index</tt></td><td>This is another syntax for specifying the start |
---|
389 | value. This notation includes |
---|
390 | <tt class="literal">idx1</tt> in the range of valid indices. It is equivalent to |
---|
391 | <tt class="literal">index_range(idx, i.finish(), i.stride())</tt>.</td></tr><tr><td><tt class="literal">i + idx</tt></td><td><tt class="literal">index</tt></td><td>This expression shifts the start and finish values |
---|
392 | of <tt class="literal">i</tt> up by <tt class="literal">idx</tt>. It is equivalent to |
---|
393 | <tt class="literal">index_range(r.start()+idx1, r.finish()+idx, r.stride())</tt></td></tr><tr><td><tt class="literal">i - idx</tt></td><td><tt class="literal">index</tt></td><td>This expression shifts the start and finish values |
---|
394 | of <tt class="literal">i</tt> up by <tt class="literal">idx</tt>. It is equivalent to |
---|
395 | <tt class="literal">index_range(r.start()-idx1, r.finish()-idx, r.stride())</tt></td></tr></tbody></table></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="index_gen"></a><tt class="literal">index_gen</tt></h4></div></div><div></div></div><p> <tt class="literal">index_gen</tt> aggregates |
---|
396 | <tt class="literal">index_range</tt> objects in order to specify view |
---|
397 | parameters. Chained calls to <tt class="literal">operator[]</tt> store |
---|
398 | range and dimension information used to |
---|
399 | instantiate a new view into a MultiArray. |
---|
400 | </p><div class="table"><a name="id834994"></a><p class="title"><b>Table 8. Notation</b></p><table summary="Notation" border="1"><colgroup><col><col></colgroup><tbody><tr><td><tt class="literal">Dims,Ranges</tt></td><td>Unsigned integral values.</td></tr><tr><td><tt class="literal">x</tt></td><td>An object of type |
---|
401 | <tt class="literal">template gen_type<Dims,Ranges>::type</tt>.</td></tr><tr><td><tt class="literal">i</tt></td><td>An object of type |
---|
402 | <tt class="literal">index_range</tt>.</td></tr><tr><td><tt class="literal">idx</tt></td><td>Objects of type <tt class="literal">index</tt>.</td></tr></tbody></table></div><div class="table"><a name="id835080"></a><p class="title"><b>Table 9. Associated Types</b></p><table summary="Associated Types" border="1"><colgroup><col><col></colgroup><thead><tr><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><tt class="literal">index</tt></td><td>This is a signed integral type. It is used to |
---|
403 | specify degenerate dimensions.</td></tr><tr><td><tt class="literal">size_type</tt></td><td>This is an unsigned integral type. It is used to |
---|
404 | report the size of the range an <tt class="literal">index_range</tt> |
---|
405 | represents.</td></tr><tr><td><tt class="literal">template gen_type::<Dims,Ranges>::type</tt></td><td>This type generator names the result of |
---|
406 | <tt class="literal">Dims</tt> chained calls to |
---|
407 | <tt class="literal">index_gen::operator[]</tt>. The |
---|
408 | <tt class="literal">Ranges</tt> parameter is determined by the number of |
---|
409 | degenerate ranges specified (i.e. calls to |
---|
410 | <tt class="literal">operator[](index)</tt>). Note that |
---|
411 | <tt class="classname">index_gen</tt> and |
---|
412 | <tt class="classname">gen_type<0,0>::type</tt> are the same type.</td></tr></tbody></table></div><div class="table"><a name="id835192"></a><p class="title"><b>Table 10. Valid Expressions</b></p><table summary="Valid Expressions" border="1"><colgroup><col><col><col></colgroup><thead><tr><th>Expression</th><th>Return type</th><th>Semantics</th></tr></thead><tbody><tr><td><tt class="literal">index_gen()</tt></td><td><tt class="literal">gen_type<0,0>::type</tt></td><td>This constructs an <tt class="literal">index_gen</tt> |
---|
413 | object. This object can then be used to generate tuples of |
---|
414 | <tt class="literal">index_range</tt> values.</td></tr><tr><td><tt class="literal">x[i]</tt></td><td><tt class="literal">gen_type<Dims+1,Ranges+1>::type</tt></td><td>Returns a new object containing all previous |
---|
415 | <tt class="classname">index_range</tt> objects in addition to |
---|
416 | <tt class="literal">i.</tt> Chained calls to |
---|
417 | <tt class="function">operator[]</tt> are the means by which |
---|
418 | <tt class="classname">index_range</tt> objects are aggregated.</td></tr><tr><td><tt class="literal">x[idx]</tt></td><td><tt class="literal">gen_type<Dims,Ranges>::type</tt></td><td>Returns a new object containing all previous |
---|
419 | <tt class="classname">index_range</tt> objects in addition to a degenerate |
---|
420 | range, <tt class="literal">index_range(idx,idx).</tt> Note that this is NOT |
---|
421 | equivalent to <tt class="literal">x[index_range(idx,idx)].</tt>, which will |
---|
422 | return an object of type |
---|
423 | <tt class="literal">gen_type<Dims+1,Ranges+1>::type</tt>. |
---|
424 | </td></tr></tbody></table></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id835348"></a>Models</h3></div></div><div></div></div><div class="itemizedlist"><ul type="disc"><li><tt class="literal">multi_array</tt></li><li><tt class="literal">multi_array_ref</tt></li><li><tt class="literal">const_multi_array_ref</tt></li><li><tt class="literal">template array_view<Dims>::type</tt></li><li><tt class="literal">template const_array_view<Dims>::type</tt></li><li><tt class="literal">template subarray<Dims>::type</tt></li><li><tt class="literal">template const_subarray<Dims>::type</tt></li></ul></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="array_types"></a>Array Components</h2></div></div><div></div></div><p> |
---|
425 | Boost.MultiArray defines an array class, |
---|
426 | <tt class="literal">multi_array</tt>, and two adapter classes, |
---|
427 | <tt class="literal">multi_array_ref</tt> and |
---|
428 | <tt class="literal">const_multi_array_ref</tt>. The three classes model |
---|
429 | MultiArray and so they share a lot of functionality. |
---|
430 | <tt class="literal">multi_array_ref</tt> differs from |
---|
431 | <tt class="literal">multi_array</tt> in that the |
---|
432 | <tt class="literal">multi_array</tt> manages its own memory, while |
---|
433 | <tt class="literal">multi_array_ref</tt> is passed a block of memory that it |
---|
434 | expects to be externally managed. |
---|
435 | <tt class="literal">const_multi_array_ref</tt> differs from |
---|
436 | <tt class="literal">multi_array_ref</tt> in that the underlying elements it |
---|
437 | adapts cannot be modified through its interface, though some array |
---|
438 | properties, including the array shape and index bases, can be altered. |
---|
439 | Functionality the classes have in common is described |
---|
440 | below. |
---|
441 | </p><p><b>Note: Preconditions, Effects, and Implementation. </b> |
---|
442 | Throughout the following sections, small pieces of C++ code are |
---|
443 | used to specify constraints such as preconditions, effects, and |
---|
444 | postconditions. These do not necessarily describe the underlying |
---|
445 | implementation of array components; rather, they describe the |
---|
446 | expected input to and |
---|
447 | behavior of the specified operations. Failure to meet |
---|
448 | preconditions results in undefined behavior. Not all effects |
---|
449 | (i.e. copy constructors, etc.) must be mimicked exactly. The code |
---|
450 | snippets for effects intend to capture the essence of the described |
---|
451 | operation. |
---|
452 | </p><p><b>Queries. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting">element* data(); |
---|
453 | const element* data() const;</pre></span></dt><dd><p>This returns a pointer to the beginning of the |
---|
454 | contiguous block that contains the array's data. If all dimensions of |
---|
455 | the array are 0-indexed and stored in ascending order, this is |
---|
456 | equivalent to <tt class="literal">origin()</tt>. Note that |
---|
457 | <tt class="literal">const_multi_array_ref</tt> only provides the const |
---|
458 | version of this function. |
---|
459 | </p></dd><dt><span class="term"><pre class="programlisting">element* origin(); |
---|
460 | const element* origin() const;</pre></span></dt><dd><p>This returns the origin element of the |
---|
461 | <tt class="literal">multi_array</tt>. Note that |
---|
462 | <tt class="literal">const_multi_array_ref</tt> only provides the const |
---|
463 | version of this function. (Required by MultiArray) |
---|
464 | </p></dd><dt><span class="term"><tt class="function">const index* index_bases();</tt></span></dt><dd><p>This returns the index bases for the |
---|
465 | <tt class="literal">multi_array</tt>. (Required by MultiArray) |
---|
466 | </p></dd><dt><span class="term"><tt class="function">const index* strides();</tt></span></dt><dd><p>This returns the strides for the |
---|
467 | <tt class="literal">multi_array</tt>. (Required by MultiArray) |
---|
468 | </p></dd><dt><span class="term"><tt class="function">const size_type* shape();</tt></span></dt><dd><p>This returns the shape of the |
---|
469 | <tt class="literal">multi_array</tt>. (Required by MultiArray) |
---|
470 | </p></dd></dl></div><p><b>Comparators. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting"> |
---|
471 | bool operator==(const *array-type*& rhs); |
---|
472 | bool operator!=(const *array-type*& rhs); |
---|
473 | bool operator<(const *array-type*& rhs); |
---|
474 | bool operator>(const *array-type*& rhs); |
---|
475 | bool operator>=(const *array-type*& rhs); |
---|
476 | bool operator<=(const *array-type*& rhs);</pre></span></dt><dd><p>Each comparator executes a lexicographical compare over |
---|
477 | the value types of the two arrays. |
---|
478 | (Required by MultiArray) |
---|
479 | </p><p><b>Preconditions. </b><tt class="literal">element</tt> must support the |
---|
480 | comparator corresponding to that called on |
---|
481 | <tt class="literal">multi_array</tt>.</p><p><b>Complexity. </b>O(<tt class="literal">num_elements()</tt>).</p></dd></dl></div><p><b>Modifiers. </b></p><div class="variablelist"><dl><dt><span class="term"> |
---|
482 | <pre class="programlisting"> |
---|
483 | |
---|
484 | template <typename SizeList> |
---|
485 | void reshape(const SizeList& sizes) |
---|
486 | |
---|
487 | </pre> |
---|
488 | </span></dt><dd><p>This changes the shape of the <tt class="literal">multi_array</tt>. The |
---|
489 | number of elements and the index bases remain the same, but the number |
---|
490 | of values at each level of the nested container hierarchy may |
---|
491 | change.</p><p><b><tt class="literal">SizeList</tt> Requirements. </b><tt class="literal">SizeList</tt> must model |
---|
492 | <a href="../../utility/Collection.html" target="_top">Collection</a>.</p><p><b>Preconditions. </b> |
---|
493 | </p><pre class="programlisting"> |
---|
494 | std::accumulate(sizes.begin(),sizes.end(),size_type(1),std::times<size_type>()) == this->num_elements(); |
---|
495 | sizes.size() == NumDims; |
---|
496 | </pre><p><b>Postconditions. </b> |
---|
497 | <tt class="literal">std::equal(sizes.begin(),sizes.end(),this->shape) == true;</tt> |
---|
498 | </p></dd><dt><span class="term"> |
---|
499 | <pre class="programlisting"> |
---|
500 | |
---|
501 | template <typename BaseList> |
---|
502 | void reindex(const BaseList& values); |
---|
503 | |
---|
504 | </pre> |
---|
505 | </span></dt><dd><p>This changes the index bases of the <tt class="literal">multi_array</tt> to |
---|
506 | correspond to the the values in <tt class="literal">values</tt>.</p><p><b><tt class="literal">BaseList</tt> Requirements. </b><tt class="literal">BaseList</tt> must model |
---|
507 | <a href="../../utility/Collection.html" target="_top">Collection</a>.</p><p><b>Preconditions. </b><tt class="literal">values.size() == NumDims;</tt></p><p><b>Postconditions. </b><tt class="literal">std::equal(values.begin(),values.end(),this->index_bases()); |
---|
508 | </tt></p></dd><dt><span class="term"> |
---|
509 | <pre class="programlisting"> |
---|
510 | |
---|
511 | void reindex(index value); |
---|
512 | |
---|
513 | </pre> |
---|
514 | </span></dt><dd><p>This changes the index bases of all dimensions of the |
---|
515 | <tt class="literal">multi_array</tt> to <tt class="literal">value</tt>.</p><p><b>Postconditions. </b> |
---|
516 | </p><pre class="programlisting"> |
---|
517 | |
---|
518 | std::count_if(this->index_bases(),this->index_bases()+this->num_dimensions(), |
---|
519 | std::bind_2nd(std::equal_to<index>(),value)) == |
---|
520 | this->num_dimensions(); |
---|
521 | |
---|
522 | </pre><p> |
---|
523 | </p></dd></dl></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="multi_array"></a><tt class="literal">multi_array</tt></h3></div></div><div></div></div><p> |
---|
524 | <tt class="literal">multi_array</tt> is a multi-dimensional container that |
---|
525 | supports random access iteration. Its number of dimensions is |
---|
526 | fixed at compile time, but its shape and the number of elements it |
---|
527 | contains are specified during its construction. The number of elements |
---|
528 | will remain fixed for the duration of a |
---|
529 | <tt class="literal">multi_array</tt>'s lifetime, but the shape of the container can |
---|
530 | be changed. A <tt class="literal">multi_array</tt> manages its data elements |
---|
531 | using a replaceable allocator. |
---|
532 | </p><p><b>Model Of. </b> |
---|
533 | <a href="#MultiArray" title="MultiArray Concept">MultiArray</a>, |
---|
534 | <a href="../../../libs/utility/CopyConstructible.html" target="_top">CopyConstructible</a>. Depending on the element type, |
---|
535 | it may also model <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top">EqualityComparable</a> and <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top">LessThanComparable</a>. |
---|
536 | </p><p><b>Synopsis. </b></p><pre class="programlisting"> |
---|
537 | |
---|
538 | namespace boost { |
---|
539 | |
---|
540 | template <typename ValueType, |
---|
541 | std::size_t NumDims, |
---|
542 | typename Allocator = std::allocator<ValueType> > |
---|
543 | class multi_array { |
---|
544 | public: |
---|
545 | // types: |
---|
546 | typedef ValueType element; |
---|
547 | typedef *implementation-defined* value_type; |
---|
548 | typedef *implementation-defined* reference; |
---|
549 | typedef *implementation-defined* const_reference; |
---|
550 | typedef *implementation-defined* difference_type; |
---|
551 | typedef *implementation-defined* iterator; |
---|
552 | typedef *implementation-defined* const_iterator; |
---|
553 | typedef *implementation-defined* reverse_iterator; |
---|
554 | typedef *implementation-defined* const_reverse_iterator; |
---|
555 | typedef multi_array_types::size_type size_type; |
---|
556 | typedef multi_array_types::index index; |
---|
557 | typedef multi_array_types::index_gen index_gen; |
---|
558 | typedef multi_array_types::index_range index_range; |
---|
559 | typedef multi_array_types::extent_gen extent_gen; |
---|
560 | typedef multi_array_types::extent_range extent_range; |
---|
561 | typedef *implementation-defined* storage_order_type; |
---|
562 | |
---|
563 | |
---|
564 | // template typedefs |
---|
565 | template <std::size_t Dims> struct subarray; |
---|
566 | template <std::size_t Dims> struct const_subarray; |
---|
567 | template <std::size_t Dims> struct array_view; |
---|
568 | template <std::size_t Dims> struct const_array_view; |
---|
569 | |
---|
570 | |
---|
571 | // constructors and destructors |
---|
572 | |
---|
573 | multi_array(); |
---|
574 | |
---|
575 | template <typename ExtentList> |
---|
576 | explicit multi_array(const ExtentList& sizes, |
---|
577 | const storage_order_type& store = c_storage_order(), |
---|
578 | const Allocator& alloc = Allocator()); |
---|
579 | explicit multi_array(const extents_tuple& ranges, |
---|
580 | const storage_order_type& store = c_storage_order(), |
---|
581 | const Allocator& alloc = Allocator()); |
---|
582 | multi_array(const multi_array& x); |
---|
583 | multi_array(const const_multi_array_ref<ValueType,NumDims>& x); |
---|
584 | multi_array(const const_subarray<NumDims>::type& x); |
---|
585 | multi_array(const const_array_view<NumDims>::type& x); |
---|
586 | |
---|
587 | multi_array(const multi_array_ref<ValueType,NumDims>& x); |
---|
588 | multi_array(const subarray<NumDims>::type& x); |
---|
589 | multi_array(const array_view<NumDims>::type& x); |
---|
590 | |
---|
591 | ~multi_array(); |
---|
592 | |
---|
593 | // modifiers |
---|
594 | |
---|
595 | multi_array& operator=(const multi_array& x); |
---|
596 | template <class Array> multi_array& operator=(const Array& x); |
---|
597 | |
---|
598 | // iterators: |
---|
599 | iterator begin(); |
---|
600 | iterator end(); |
---|
601 | const_iterator begin() const; |
---|
602 | const_iterator end() const; |
---|
603 | reverse_iterator rbegin(); |
---|
604 | reverse_iterator rend(); |
---|
605 | const_reverse_iterator rbegin() const; |
---|
606 | const_reverse_iterator rend() const; |
---|
607 | |
---|
608 | // capacity: |
---|
609 | size_type size() const; |
---|
610 | size_type num_elements() const; |
---|
611 | size_type num_dimensions() const; |
---|
612 | |
---|
613 | // element access: |
---|
614 | template <typename IndexList> |
---|
615 | element& operator()(const IndexList& indices); |
---|
616 | template <typename IndexList> |
---|
617 | const element& operator()(const IndexList& indices) const; |
---|
618 | reference operator[](index i); |
---|
619 | const_reference operator[](index i) const; |
---|
620 | array_view<Dims>::type operator[](const indices_tuple& r); |
---|
621 | const_array_view<Dims>::type operator[](const indices_tuple& r) const; |
---|
622 | |
---|
623 | // queries |
---|
624 | element* data(); |
---|
625 | const element* data() const; |
---|
626 | element* origin(); |
---|
627 | const element* origin() const; |
---|
628 | const size_type* shape() const; |
---|
629 | const index* strides() const; |
---|
630 | const index* index_bases() const; |
---|
631 | const storage_order_type& storage_order() const; |
---|
632 | |
---|
633 | // comparators |
---|
634 | bool operator==(const multi_array& rhs); |
---|
635 | bool operator!=(const multi_array& rhs); |
---|
636 | bool operator<(const multi_array& rhs); |
---|
637 | bool operator>(const multi_array& rhs); |
---|
638 | bool operator>=(const multi_array& rhs); |
---|
639 | bool operator<=(const multi_array& rhs); |
---|
640 | |
---|
641 | // modifiers: |
---|
642 | template <typename InputIterator> |
---|
643 | void assign(InputIterator begin, InputIterator end); |
---|
644 | template <typename SizeList> |
---|
645 | void reshape(const SizeList& sizes) |
---|
646 | template <typename BaseList> void reindex(const BaseList& values); |
---|
647 | void reindex(index value); |
---|
648 | multi_array& resize(extents_tuple& extents); |
---|
649 | }; |
---|
650 | |
---|
651 | </pre><p><b>Constructors. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting">template <typename ExtentList> |
---|
652 | explicit multi_array(const ExtentList& sizes, |
---|
653 | const storage_order_type& store = c_storage_order(), |
---|
654 | const Allocator& alloc = Allocator()); |
---|
655 | </pre></span></dt><dd><p> |
---|
656 | This constructs a <tt class="literal">multi_array</tt> using the specified |
---|
657 | parameters. <tt class="literal">sizes</tt> specifies the shape of the |
---|
658 | constructed <tt class="literal">multi_array</tt>. <tt class="literal">store</tt> |
---|
659 | specifies the storage order or layout in memory of the array |
---|
660 | dimensions. <tt class="literal">alloc</tt> is used to |
---|
661 | allocate the contained elements. |
---|
662 | </p><p><b><tt class="literal">ExtentList</tt> Requirements. </b> |
---|
663 | <tt class="literal">ExtentList</tt> must model <a href="../../utility/Collection.html" target="_top">Collection</a>. |
---|
664 | </p><p><b>Preconditions. </b><tt class="literal">sizes.size() == NumDims;</tt></p></dd><dt><span class="term"> |
---|
665 | <pre class="programlisting">explicit multi_array(extent_gen::gen_type<NumDims>::type ranges, |
---|
666 | const storage_order_type& store = c_storage_order(), |
---|
667 | const Allocator& alloc = Allocator()); |
---|
668 | </pre></span></dt><dd><p> |
---|
669 | This constructs a <tt class="literal">multi_array</tt> using the specified |
---|
670 | parameters. <tt class="literal">ranges</tt> specifies the shape and |
---|
671 | index bases of the constructed multi_array. It is the result of |
---|
672 | <tt class="literal">NumDims</tt> chained calls to |
---|
673 | <tt class="literal">extent_gen::operator[]</tt>. <tt class="literal">store</tt> |
---|
674 | specifies the storage order or layout in memory of the array |
---|
675 | dimensions. <tt class="literal">alloc</tt> is the allocator used to |
---|
676 | allocate the memory used to store <tt class="literal">multi_array</tt> |
---|
677 | elements. |
---|
678 | </p></dd><dt><span class="term"><pre class="programlisting"> |
---|
679 | multi_array(const multi_array& x); |
---|
680 | multi_array(const const_multi_array_ref<ValueType,NumDims>& x); |
---|
681 | multi_array(const const_subarray<NumDims>::type& x); |
---|
682 | multi_array(const const_array_view<NumDims>::type& x); |
---|
683 | multi_array(const multi_array_ref<ValueType,NumDims>& x); |
---|
684 | multi_array(const subarray<NumDims>::type& x); |
---|
685 | multi_array(const array_view<NumDims>::type& x); |
---|
686 | </pre></span></dt><dd><p>These constructors all constructs a <tt class="literal">multi_array</tt> and |
---|
687 | perform a deep copy of <tt class="literal">x</tt>. |
---|
688 | </p><p><b>Complexity. </b> This performs O(<tt class="literal">x.num_elements()</tt>) calls to |
---|
689 | <tt class="literal">element</tt>'s copy |
---|
690 | constructor. |
---|
691 | </p></dd><dt><span class="term"><pre class="programlisting"> |
---|
692 | multi_array(); |
---|
693 | </pre></span></dt><dd><p>This constructs a <tt class="literal">multi_array</tt> whose shape is (0,...,0) and contains no elements. |
---|
694 | </p></dd></dl></div><p><b>Note on Constructors. </b> |
---|
695 | The <tt class="literal">multi_array</tt> construction expressions, |
---|
696 | </p><pre class="programlisting"> |
---|
697 | multi_array<int,3> A(boost::extents[5][4][3]); |
---|
698 | </pre><p> |
---|
699 | and |
---|
700 | </p><pre class="programlisting"> |
---|
701 | boost::array<multi_array_base::index,3> my_extents = {{5, 4, 3}}; |
---|
702 | multi_array<int,3> A(my_extents); |
---|
703 | </pre><p> |
---|
704 | are equivalent. |
---|
705 | </p><p><b>Modifiers. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting"> |
---|
706 | multi_array& operator=(const multi_array& x); |
---|
707 | template <class Array> multi_array& operator=(const Array& x); |
---|
708 | </pre> |
---|
709 | </span></dt><dd><p>This performs an element-wise copy of <tt class="literal">x</tt> |
---|
710 | into the current <tt class="literal">multi_array</tt>.</p><p><b><tt class="literal">Array</tt> Requirements. </b><tt class="literal">Array</tt> must model MultiArray. |
---|
711 | </p><p><b>Preconditions. </b> |
---|
712 | </p><pre class="programlisting">std::equal(this->shape(),this->shape()+this->num_dimensions(), |
---|
713 | x.shape());</pre><p><b>Postconditions. </b> |
---|
714 | </p><pre class="programlisting">(*.this) == x;</pre><p> |
---|
715 | </p><p><b>Complexity. </b>The assignment operators perform |
---|
716 | O(<tt class="literal">x.num_elements()</tt>) calls to <tt class="literal">element</tt>'s |
---|
717 | copy constructor.</p></dd><dt><span class="term"> |
---|
718 | <pre class="programlisting"> |
---|
719 | |
---|
720 | template <typename InputIterator> |
---|
721 | void assign(InputIterator begin, InputIterator end); |
---|
722 | </pre> |
---|
723 | </span></dt><dd><p>This copies the elements in the range |
---|
724 | <tt class="literal">[begin,end)</tt> into the array. It is equivalent to |
---|
725 | <tt class="literal">std::copy(begin,end,this->data())</tt>. |
---|
726 | </p><p><b>Preconditions. </b><tt class="literal">std::distance(begin,end) == this->num_elements();</tt> |
---|
727 | </p><p><b>Complexity. </b> |
---|
728 | The <tt class="literal">assign</tt> member function performs |
---|
729 | O(<tt class="literal">this->num_elements()</tt>) calls to |
---|
730 | <tt class="literal">ValueType</tt>'s copy constructor. |
---|
731 | </p></dd><dt><span class="term"> |
---|
732 | <pre class="programlisting">multi_array& resize(extent_gen::gen_type<NumDims>::type ranges); |
---|
733 | </pre></span></dt><dd><p> |
---|
734 | This function resizes an array to the shape specified by |
---|
735 | <tt class="literal">ranges</tt>. The contents of the array are preserved |
---|
736 | whenever possible; if the new array size is smaller, then some data will |
---|
737 | be lost. Any new elements created by resizing the array are initialized with |
---|
738 | the <tt class="literal">element</tt> default constructor. |
---|
739 | </p></dd></dl></div><p><b>Queries. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting"> |
---|
740 | storage_order_type& storage_order() const; |
---|
741 | </pre> |
---|
742 | </span></dt><dd><p>This query returns the storage order object associated with the |
---|
743 | <tt class="literal">multi_array</tt> in question. It can be used to construct a new array with the same storage order.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="multi_array_ref"></a><tt class="literal">multi_array_ref</tt></h3></div></div><div></div></div><p> |
---|
744 | <tt class="literal">multi_array_ref</tt> is a multi-dimensional container |
---|
745 | adaptor. It provides the MultiArray interface over any contiguous |
---|
746 | block of elements. <tt class="literal">multi_array_ref</tt> exports the |
---|
747 | same interface as <tt class="literal">multi_array</tt>, with the exception |
---|
748 | of the constructors. |
---|
749 | </p><p><b>Model Of. </b> |
---|
750 | <tt class="literal">multi_array_ref</tt> models |
---|
751 | <a href="#MultiArray" title="MultiArray Concept">MultiArray</a>, |
---|
752 | <a href="../../../libs/utility/CopyConstructible.html" target="_top">CopyConstructible</a>. |
---|
753 | and depending on the element type, it may also model |
---|
754 | <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top">EqualityComparable</a> and <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top">LessThanComparable</a>. |
---|
755 | Detailed descriptions are provided here only for operations that are |
---|
756 | not described in the <tt class="literal">multi_array</tt> reference. |
---|
757 | </p><p><b>Synopsis. </b></p><pre class="programlisting"> |
---|
758 | |
---|
759 | namespace boost { |
---|
760 | |
---|
761 | template <typename ValueType, |
---|
762 | std::size_t NumDims, |
---|
763 | typename Allocator = std::allocator<ValueType> > |
---|
764 | class multi_array_ref { |
---|
765 | public: |
---|
766 | // types: |
---|
767 | typedef ValueType element; |
---|
768 | typedef *implementation-defined* value_type; |
---|
769 | typedef *implementation-defined* reference; |
---|
770 | typedef *implementation-defined* const_reference; |
---|
771 | typedef *implementation-defined* difference_type; |
---|
772 | typedef *implementation-defined* iterator; |
---|
773 | typedef *implementation-defined* const_iterator; |
---|
774 | typedef *implementation-defined* reverse_iterator; |
---|
775 | typedef *implementation-defined* const_reverse_iterator; |
---|
776 | typedef multi_array_types::size_type size_type; |
---|
777 | typedef multi_array_types::index index; |
---|
778 | typedef multi_array_types::index_gen index_gen; |
---|
779 | typedef multi_array_types::index_range index_range; |
---|
780 | typedef multi_array_types::extent_gen extent_gen; |
---|
781 | typedef multi_array_types::extent_range extent_range; |
---|
782 | typedef *implementation-defined* storage_order_type; |
---|
783 | |
---|
784 | // template typedefs |
---|
785 | template <std::size_t Dims> struct subarray; |
---|
786 | template <std::size_t Dims> struct const_subarray; |
---|
787 | template <std::size_t Dims> struct array_view; |
---|
788 | template <std::size_t Dims> struct const_array_view; |
---|
789 | |
---|
790 | |
---|
791 | // structors |
---|
792 | |
---|
793 | template <typename ExtentList> |
---|
794 | explicit multi_array_ref(element* data, const ExtentList& sizes, |
---|
795 | const storage_order_type& store = c_storage_order()); |
---|
796 | explicit multi_array_ref(element* data, const extents_tuple& ranges, |
---|
797 | const storage_order_type& store = c_storage_order()); |
---|
798 | multi_array_ref(const multi_array_ref& x); |
---|
799 | ~multi_array_ref(); |
---|
800 | |
---|
801 | // modifiers |
---|
802 | |
---|
803 | multi_array_ref& operator=(const multi_array_ref& x); |
---|
804 | template <class Array> multi_array_ref& operator=(const Array& x); |
---|
805 | |
---|
806 | // iterators: |
---|
807 | iterator begin(); |
---|
808 | iterator end(); |
---|
809 | const_iterator begin() const; |
---|
810 | const_iterator end() const; |
---|
811 | reverse_iterator rbegin(); |
---|
812 | reverse_iterator rend(); |
---|
813 | const_reverse_iterator rbegin() const; |
---|
814 | const_reverse_iterator rend() const; |
---|
815 | |
---|
816 | // capacity: |
---|
817 | size_type size() const; |
---|
818 | size_type num_elements() const; |
---|
819 | size_type num_dimensions() const; |
---|
820 | |
---|
821 | // element access: |
---|
822 | template <typename IndexList> |
---|
823 | element& operator()(const IndexList& indices); |
---|
824 | template <typename IndexList> |
---|
825 | const element& operator()(const IndexList& indices) const; |
---|
826 | reference operator[](index i); |
---|
827 | const_reference operator[](index i) const; |
---|
828 | array_view<Dims>::type operator[](const indices_tuple& r); |
---|
829 | const_array_view<Dims>::type operator[](const indices_tuple& r) const; |
---|
830 | |
---|
831 | // queries |
---|
832 | element* data(); |
---|
833 | const element* data() const; |
---|
834 | element* origin(); |
---|
835 | const element* origin() const; |
---|
836 | const size_type* shape() const; |
---|
837 | const index* strides() const; |
---|
838 | const index* index_bases() const; |
---|
839 | const storage_order_type& storage_order() const; |
---|
840 | |
---|
841 | // comparators |
---|
842 | bool operator==(const multi_array_ref& rhs); |
---|
843 | bool operator!=(const multi_array_ref& rhs); |
---|
844 | bool operator<(const multi_array_ref& rhs); |
---|
845 | bool operator>(const multi_array_ref& rhs); |
---|
846 | bool operator>=(const multi_array_ref& rhs); |
---|
847 | bool operator<=(const multi_array_ref& rhs); |
---|
848 | |
---|
849 | // modifiers: |
---|
850 | template <typename InputIterator> |
---|
851 | void assign(InputIterator begin, InputIterator end); |
---|
852 | template <typename SizeList> |
---|
853 | void reshape(const SizeList& sizes) |
---|
854 | template <typename BaseList> void reindex(const BaseList& values); |
---|
855 | void reindex(index value); |
---|
856 | }; |
---|
857 | |
---|
858 | </pre><p><b>Constructors. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting">template <typename ExtentList> |
---|
859 | explicit multi_array_ref(element* data, |
---|
860 | const ExtentList& sizes, |
---|
861 | const storage_order& store = c_storage_order(), |
---|
862 | const Allocator& alloc = Allocator()); |
---|
863 | </pre></span></dt><dd><p> |
---|
864 | This constructs a <tt class="literal">multi_array_ref</tt> using the specified |
---|
865 | parameters. <tt class="literal">sizes</tt> specifies the shape of the |
---|
866 | constructed <tt class="literal">multi_array_ref</tt>. <tt class="literal">store</tt> |
---|
867 | specifies the storage order or layout in memory of the array |
---|
868 | dimensions. <tt class="literal">alloc</tt> is used to |
---|
869 | allocate the contained elements. |
---|
870 | </p><p><b><tt class="literal">ExtentList</tt> Requirements. </b> |
---|
871 | <tt class="literal">ExtentList</tt> must model <a href="../../utility/Collection.html" target="_top">Collection</a>. |
---|
872 | </p><p><b>Preconditions. </b><tt class="literal">sizes.size() == NumDims;</tt></p></dd><dt><span class="term"> |
---|
873 | <pre class="programlisting">explicit multi_array_ref(element* data, |
---|
874 | extent_gen::gen_type<NumDims>::type ranges, |
---|
875 | const storage_order& store = c_storage_order()); |
---|
876 | </pre></span></dt><dd><p> |
---|
877 | This constructs a <tt class="literal">multi_array_ref</tt> using the specified |
---|
878 | parameters. <tt class="literal">ranges</tt> specifies the shape and |
---|
879 | index bases of the constructed multi_array_ref. It is the result of |
---|
880 | <tt class="literal">NumDims</tt> chained calls to |
---|
881 | <tt class="literal">extent_gen::operator[]</tt>. <tt class="literal">store</tt> |
---|
882 | specifies the storage order or layout in memory of the array |
---|
883 | dimensions. |
---|
884 | </p></dd><dt><span class="term"><pre class="programlisting"> |
---|
885 | multi_array_ref(const multi_array_ref& x); |
---|
886 | </pre></span></dt><dd><p>This constructs a shallow copy of <tt class="literal">x</tt>. |
---|
887 | </p><p><b>Complexity. </b> Constant time (for contrast, compare this to |
---|
888 | the <tt class="literal">multi_array</tt> class copy constructor. |
---|
889 | </p></dd></dl></div><p><b>Modifiers. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting"> |
---|
890 | multi_array_ref& operator=(const multi_array_ref& x); |
---|
891 | template <class Array> multi_array_ref& operator=(const Array& x); |
---|
892 | </pre> |
---|
893 | </span></dt><dd><p>This performs an element-wise copy of <tt class="literal">x</tt> |
---|
894 | into the current <tt class="literal">multi_array_ref</tt>.</p><p><b><tt class="literal">Array</tt> Requirements. </b><tt class="literal">Array</tt> must model MultiArray. |
---|
895 | </p><p><b>Preconditions. </b> |
---|
896 | </p><pre class="programlisting">std::equal(this->shape(),this->shape()+this->num_dimensions(), |
---|
897 | x.shape());</pre><p><b>Postconditions. </b> |
---|
898 | </p><pre class="programlisting">(*.this) == x;</pre><p> |
---|
899 | </p><p><b>Complexity. </b>The assignment operators perform |
---|
900 | O(<tt class="literal">x.num_elements()</tt>) calls to <tt class="literal">element</tt>'s |
---|
901 | copy constructor.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="const_multi_array_ref"></a><tt class="literal">const_multi_array_ref</tt></h3></div></div><div></div></div><p> |
---|
902 | <tt class="literal">const_multi_array_ref</tt> is a multi-dimensional container |
---|
903 | adaptor. It provides the MultiArray interface over any contiguous |
---|
904 | block of elements. <tt class="literal">const_multi_array_ref</tt> exports the |
---|
905 | same interface as <tt class="literal">multi_array</tt>, with the exception |
---|
906 | of the constructors. |
---|
907 | </p><p><b>Model Of. </b> |
---|
908 | <tt class="literal">const_multi_array_ref</tt> models |
---|
909 | <a href="#MultiArray" title="MultiArray Concept">MultiArray</a>, |
---|
910 | <a href="../../../libs/utility/CopyConstructible.html" target="_top">CopyConstructible</a>. |
---|
911 | and depending on the element type, it may also model |
---|
912 | <a href="http://www.sgi.com/tech/stl/EqualityComparable.html" target="_top">EqualityComparable</a> and <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top">LessThanComparable</a>. |
---|
913 | |
---|
914 | Detailed descriptions are provided here only for operations that are |
---|
915 | not described in the <tt class="literal">multi_array</tt> reference. |
---|
916 | </p><p><b>Synopsis. </b></p><pre class="programlisting"> |
---|
917 | |
---|
918 | namespace boost { |
---|
919 | |
---|
920 | template <typename ValueType, |
---|
921 | std::size_t NumDims, |
---|
922 | typename Allocator = std::allocator<ValueType> > |
---|
923 | class const_multi_array_ref { |
---|
924 | public: |
---|
925 | // types: |
---|
926 | typedef ValueType element; |
---|
927 | typedef *implementation-defined* value_type; |
---|
928 | typedef *implementation-defined* reference; |
---|
929 | typedef *implementation-defined* const_reference; |
---|
930 | typedef *implementation-defined* difference_type; |
---|
931 | typedef *implementation-defined* iterator; |
---|
932 | typedef *implementation-defined* const_iterator; |
---|
933 | typedef *implementation-defined* reverse_iterator; |
---|
934 | typedef *implementation-defined* const_reverse_iterator; |
---|
935 | typedef multi_array_types::size_type size_type; |
---|
936 | typedef multi_array_types::index index; |
---|
937 | typedef multi_array_types::index_gen index_gen; |
---|
938 | typedef multi_array_types::index_range index_range; |
---|
939 | typedef multi_array_types::extent_gen extent_gen; |
---|
940 | typedef multi_array_types::extent_range extent_range; |
---|
941 | typedef *implementation-defined* storage_order_type; |
---|
942 | |
---|
943 | // template typedefs |
---|
944 | template <std::size_t Dims> struct subarray; |
---|
945 | template <std::size_t Dims> struct const_subarray; |
---|
946 | template <std::size_t Dims> struct array_view; |
---|
947 | template <std::size_t Dims> struct const_array_view; |
---|
948 | |
---|
949 | |
---|
950 | // structors |
---|
951 | |
---|
952 | template <typename ExtentList> |
---|
953 | explicit const_multi_array_ref(const element* data, const ExtentList& sizes, |
---|
954 | const storage_order_type& store = c_storage_order()); |
---|
955 | explicit const_multi_array_ref(const element* data, const extents_tuple& ranges, |
---|
956 | const storage_order_type& store = c_storage_order()); |
---|
957 | const_multi_array_ref(const const_multi_array_ref& x); |
---|
958 | ~const_multi_array_ref(); |
---|
959 | |
---|
960 | |
---|
961 | |
---|
962 | // iterators: |
---|
963 | const_iterator begin() const; |
---|
964 | const_iterator end() const; |
---|
965 | const_reverse_iterator rbegin() const; |
---|
966 | const_reverse_iterator rend() const; |
---|
967 | |
---|
968 | // capacity: |
---|
969 | size_type size() const; |
---|
970 | size_type num_elements() const; |
---|
971 | size_type num_dimensions() const; |
---|
972 | |
---|
973 | // element access: |
---|
974 | template <typename IndexList> |
---|
975 | const element& operator()(const IndexList& indices) const; |
---|
976 | const_reference operator[](index i) const; |
---|
977 | const_array_view<Dims>::type operator[](const indices_tuple& r) const; |
---|
978 | |
---|
979 | // queries |
---|
980 | const element* data() const; |
---|
981 | const element* origin() const; |
---|
982 | const size_type* shape() const; |
---|
983 | const index* strides() const; |
---|
984 | const index* index_bases() const; |
---|
985 | const storage_order_type& storage_order() const; |
---|
986 | |
---|
987 | // comparators |
---|
988 | bool operator==(const const_multi_array_ref& rhs); |
---|
989 | bool operator!=(const const_multi_array_ref& rhs); |
---|
990 | bool operator<(const const_multi_array_ref& rhs); |
---|
991 | bool operator>(const const_multi_array_ref& rhs); |
---|
992 | bool operator>=(const const_multi_array_ref& rhs); |
---|
993 | bool operator<=(const const_multi_array_ref& rhs); |
---|
994 | |
---|
995 | // modifiers: |
---|
996 | template <typename SizeList> |
---|
997 | void reshape(const SizeList& sizes) |
---|
998 | template <typename BaseList> void reindex(const BaseList& values); |
---|
999 | void reindex(index value); |
---|
1000 | }; |
---|
1001 | |
---|
1002 | </pre><p><b>Constructors. </b></p><div class="variablelist"><dl><dt><span class="term"><pre class="programlisting">template <typename ExtentList> |
---|
1003 | explicit const_multi_array_ref(const element* data, |
---|
1004 | const ExtentList& sizes, |
---|
1005 | const storage_order& store = c_storage_order()); |
---|
1006 | </pre></span></dt><dd><p> |
---|
1007 | This constructs a <tt class="literal">const_multi_array_ref</tt> using the specified |
---|
1008 | parameters. <tt class="literal">sizes</tt> specifies the shape of the |
---|
1009 | constructed <tt class="literal">const_multi_array_ref</tt>. <tt class="literal">store</tt> |
---|
1010 | specifies the storage order or layout in memory of the array |
---|
1011 | dimensions. |
---|
1012 | </p><p><b><tt class="literal">ExtentList</tt> Requirements. </b> |
---|
1013 | <tt class="literal">ExtentList</tt> must model <a href="../../utility/Collection.html" target="_top">Collection</a>. |
---|
1014 | </p><p><b>Preconditions. </b><tt class="literal">sizes.size() == NumDims;</tt></p></dd><dt><span class="term"> |
---|
1015 | <pre class="programlisting">explicit const_multi_array_ref(const element* data, |
---|
1016 | extent_gen::gen_type<NumDims>::type ranges, |
---|
1017 | const storage_order& store = c_storage_order()); |
---|
1018 | </pre></span></dt><dd><p><b>Effects. </b> |
---|
1019 | This constructs a <tt class="literal">const_multi_array_ref</tt> using the specified |
---|
1020 | parameters. <tt class="literal">ranges</tt> specifies the shape and |
---|
1021 | index bases of the constructed const_multi_array_ref. It is the result of |
---|
1022 | <tt class="literal">NumDims</tt> chained calls to |
---|
1023 | <tt class="literal">extent_gen::operator[]</tt>. <tt class="literal">store</tt> |
---|
1024 | specifies the storage order or layout in memory of the array |
---|
1025 | dimensions. |
---|
1026 | </p></dd><dt><span class="term"><pre class="programlisting"> |
---|
1027 | const_multi_array_ref(const const_multi_array_ref& x); |
---|
1028 | </pre></span></dt><dd><p><b>Effects. </b>This constructs a shallow copy of <tt class="literal">x</tt>. |
---|
1029 | </p></dd></dl></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="auxiliary"></a>Auxiliary Components</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="multi_array_types"></a><tt class="literal">multi_array_types</tt></h3></div></div><div></div></div><pre class="programlisting"> |
---|
1030 | namespace multi_array_types { |
---|
1031 | typedef *implementation-defined* index; |
---|
1032 | typedef *implementation-defined* size_type; |
---|
1033 | typedef *implementation-defined* difference_type; |
---|
1034 | typedef *implementation-defined* index_range; |
---|
1035 | typedef *implementation-defined* extent_range; |
---|
1036 | typedef *implementation-defined* index_gen; |
---|
1037 | typedef *implementation-defined* extent_gen; |
---|
1038 | } |
---|
1039 | </pre><p>Namespace <tt class="literal">multi_array_types</tt> defines types |
---|
1040 | associated with <tt class="literal">multi_array</tt>, |
---|
1041 | <tt class="literal">multi_array_ref</tt>, and |
---|
1042 | <tt class="literal">const_multi_array_ref</tt> that are not |
---|
1043 | dependent upon template parameters. These types find common use with |
---|
1044 | all Boost.Multiarray components. They are defined |
---|
1045 | in a namespace from which they can be accessed conveniently. |
---|
1046 | With the exception of <tt class="literal">extent_gen</tt> and |
---|
1047 | <tt class="literal">extent_range</tt>, these types fulfill the roles of the |
---|
1048 | same name required by MultiArray and are described in its |
---|
1049 | concept definition. <tt class="literal">extent_gen</tt> and |
---|
1050 | <tt class="literal">extent_range</tt> are described below. |
---|
1051 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="extent_range"></a><tt class="classname">extent_range</tt></h3></div></div><div></div></div><p><tt class="classname">extent_range</tt> objects define half open |
---|
1052 | intervals. They provide shape and index base information to |
---|
1053 | <tt class="literal">multi_array</tt>, <tt class="literal">multi_array_ref</tt>, |
---|
1054 | and <tt class="literal">const_multi_array_ref</tt> constructors. |
---|
1055 | <tt class="classname">extent_range</tt>s are passed in |
---|
1056 | aggregate to an array constructor (see |
---|
1057 | <tt class="classname">extent_gen</tt> for more details). |
---|
1058 | </p><p><b>Synopsis. </b></p><pre class="programlisting"> |
---|
1059 | class extent_range { |
---|
1060 | public: |
---|
1061 | typedef multi_array_types::index index; |
---|
1062 | typedef multi_array_types::size_type size_type; |
---|
1063 | |
---|
1064 | // Structors |
---|
1065 | extent_range(index start, index finish); |
---|
1066 | extent_range(index finish); |
---|
1067 | ~extent_range(); |
---|
1068 | |
---|
1069 | // Queries |
---|
1070 | index start(); |
---|
1071 | index finish(); |
---|
1072 | size_type size(); |
---|
1073 | };</pre><p><b>Model Of. </b>DefaultConstructible,CopyConstructible</p><p><b>Methods and Types. </b></p><div class="variablelist"><dl><dt><span class="term"><tt class="function">extent_range(index start, index finish)</tt></span></dt><dd><p> This constructor defines the half open interval |
---|
1074 | <tt class="literal">[start,finish)</tt>. The expression |
---|
1075 | <tt class="literal">finish</tt> must be greater than <tt class="literal">start</tt>. |
---|
1076 | </p></dd><dt><span class="term"><tt class="function">extent_range(index finish)</tt></span></dt><dd><p>This constructor defines the half open interval |
---|
1077 | <tt class="literal">[0,finish)</tt>. The value of <tt class="literal">finish</tt> |
---|
1078 | must be positive.</p></dd><dt><span class="term"><tt class="function">index start()</tt></span></dt><dd><p>This function returns the first index represented by the range</p></dd><dt><span class="term"><tt class="function">index finish()</tt></span></dt><dd><p>This function returns the upper boundary value of the half-open |
---|
1079 | interval. Note that the range does not include this value.</p></dd><dt><span class="term"><tt class="function">size_type size()</tt></span></dt><dd><p>This function returns the size of the specified range. It is |
---|
1080 | equivalent to <tt class="literal">finish()-start()</tt>.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="extent_gen"></a><tt class="classname">extent_gen</tt></h3></div></div><div></div></div><p>The <tt class="classname">extent_gen</tt> class defines an |
---|
1081 | interface for aggregating array shape and indexing information to be |
---|
1082 | passed to a <tt class="literal">multi_array</tt>, |
---|
1083 | <tt class="literal">multi_array_ref</tt>, or <tt class="literal">const_multi_array_ref</tt> |
---|
1084 | constructor. Its interface mimics |
---|
1085 | the syntax used to declare built-in array types |
---|
1086 | in C++. For example, while a 3-dimensional array of |
---|
1087 | <tt class="classname">int</tt> values in C++ would be |
---|
1088 | declared as: |
---|
1089 | </p><pre class="programlisting">int A[3][4][5],</pre><p> |
---|
1090 | a similar <tt class="classname">multi_array</tt> would be declared: |
---|
1091 | </p><pre class="programlisting">multi_array<int,3> A(extents[3][4][5]).</pre><p> |
---|
1092 | </p><p><b>Synopsis. </b></p><pre class="programlisting"> |
---|
1093 | template <std::size_t NumRanges> |
---|
1094 | class *implementation_defined* { |
---|
1095 | public: |
---|
1096 | typedef multi_array_types::index index; |
---|
1097 | typedef multi_array_types::size_type size_type; |
---|
1098 | |
---|
1099 | template <std::size_t NumRanges> class gen_type; |
---|
1100 | |
---|
1101 | gen_type<NumRanges+1>::type operator[](const range& a_range) const; |
---|
1102 | gen_type<NumRanges+1>::type operator[](index idx) const; |
---|
1103 | }; |
---|
1104 | |
---|
1105 | typedef *implementation_defined*<0> extent_gen; |
---|
1106 | </pre><p><b>Methods and Types. </b></p><div class="variablelist"><dl><dt><span class="term"><tt class="function">template gen_type::<Ranges>::type</tt></span></dt><dd><p>This type generator is used to specify the result of |
---|
1107 | <tt class="literal">Ranges</tt> chained calls to |
---|
1108 | <tt class="literal">extent_gen::operator[].</tt> The types |
---|
1109 | <tt class="classname">extent_gen</tt> and |
---|
1110 | <tt class="classname">gen_type<0>::type</tt> are the same.</p></dd><dt><span class="term"><tt class="function">gen_type<NumRanges+1>::type |
---|
1111 | operator[](const extent_range& a_range) const;</tt></span></dt><dd><p>This function returns a new object containing all previous |
---|
1112 | <tt class="classname">extent_range</tt> objects in addition to |
---|
1113 | <tt class="literal">a_range.</tt> <tt class="classname">extent_range</tt> |
---|
1114 | objects are aggregated by chained calls to |
---|
1115 | <tt class="function">operator[]</tt>.</p></dd><dt><span class="term"><tt class="function">gen_type<NumRanges+1>::type |
---|
1116 | operator[](index idx) const;</tt></span></dt><dd><p>This function returns a new object containing all previous |
---|
1117 | <tt class="classname">extent_range</tt> objects in addition to |
---|
1118 | <tt class="literal">extent_range(0,idx).</tt> This function gives the array |
---|
1119 | constructors a similar syntax to traditional C multidimensional array |
---|
1120 | declaration.</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id860298"></a>Global Objects</h3></div></div><div></div></div><p>For syntactic convenience, Boost.MultiArray defines two |
---|
1121 | global objects as part of its |
---|
1122 | interface. These objects play the role of object generators; |
---|
1123 | expressions involving them create other objects of interest. |
---|
1124 | </p><p> Under some circumstances, the two global objects may be |
---|
1125 | considered excessive overhead. Their construction can be prevented by |
---|
1126 | defining the preprocessor symbol |
---|
1127 | <tt class="literal">BOOST_MULTI_ARRAY_NO_GENERATORS</tt> before including |
---|
1128 | <tt class="filename">boost/multi_array.hpp.</tt></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="extents"></a><tt class="literal">extents</tt></h4></div></div><div></div></div><pre class="programlisting"> |
---|
1129 | namespace boost { |
---|
1130 | multi_array_base::extent_gen extents; |
---|
1131 | } |
---|
1132 | </pre><p>Boost.MultiArray's array classes use the |
---|
1133 | <tt class="literal">extents</tt> global object to specify |
---|
1134 | array shape during their construction. |
---|
1135 | For example, |
---|
1136 | a 3 by 3 by 3 <tt class="classname">multi_array</tt> is constructed as follows: |
---|
1137 | </p><pre class="programlisting">multi_array<int,3> A(extents[3][3][3]);</pre><p> |
---|
1138 | The same array could also be created by explicitly declaring an <tt class="literal">extent_gen</tt> |
---|
1139 | object locally,, but the global object makes this declaration unnecessary. |
---|
1140 | </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="indices"></a><tt class="literal">indices</tt></h4></div></div><div></div></div><pre class="programlisting"> |
---|
1141 | namespace boost { |
---|
1142 | multi_array_base::index_gen indices; |
---|
1143 | } |
---|
1144 | </pre><p>The MultiArray concept specifies an |
---|
1145 | <tt class="literal">index_gen</tt> associated type that is used to |
---|
1146 | create views. |
---|
1147 | <tt class="literal">indices</tt> is a global object that serves the role of |
---|
1148 | <tt class="literal">index_gen</tt> for all array components provided by this |
---|
1149 | library and their associated subarrays and views. |
---|
1150 | </p><p>For example, using the <tt class="literal">indices</tt> object, |
---|
1151 | a view of an array <tt class="literal">A</tt> is constructed as follows: |
---|
1152 | </p><pre class="programlisting"> |
---|
1153 | A[indices[index_range(0,5)][2][index_range(2,4)]]; |
---|
1154 | </pre><p> |
---|
1155 | </p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="generators"></a>View and SubArray Generators</h3></div></div><div></div></div><p> |
---|
1156 | Boost.MultiArray provides traits classes, <tt class="literal">subarray_gen</tt>, |
---|
1157 | <tt class="literal">const_subarray_gen</tt>, |
---|
1158 | <tt class="literal">array_view_gen</tt>, |
---|
1159 | and <tt class="literal">const_array_view_gen</tt>, for naming of |
---|
1160 | array associated types within function templates. |
---|
1161 | In general this is no more convenient to use than the nested |
---|
1162 | type generators, but the library author found that some C++ compilers do not |
---|
1163 | properly handle templates nested within function template parameter types. |
---|
1164 | These generators constitute a workaround for this deficit. |
---|
1165 | The following code snippet illustrates |
---|
1166 | the correspondence between the <tt class="literal">array_view_gen</tt> |
---|
1167 | traits class and the <tt class="literal">array_view</tt> type associated to |
---|
1168 | an array: |
---|
1169 | |
---|
1170 | </p><pre class="programlisting"> |
---|
1171 | template <typename Array> |
---|
1172 | void my_function() { |
---|
1173 | typedef typename Array::template array_view<3>::type view1_t; |
---|
1174 | typedef typename boost::array_view_gen<Array,3>::type view2_t; |
---|
1175 | // ... |
---|
1176 | } |
---|
1177 | </pre><p> |
---|
1178 | |
---|
1179 | In the above example, <tt class="literal">view1_t</tt> and |
---|
1180 | <tt class="literal">view2_t</tt> have the same type. |
---|
1181 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="memory_layout"></a>Memory Layout Specifiers</h3></div></div><div></div></div><p> |
---|
1182 | While a multidimensional array represents a hierarchy of containers of |
---|
1183 | elements, at some point the elements must be laid out in |
---|
1184 | memory. As a result, a single multidimensional array |
---|
1185 | can be represented in memory more than one way. |
---|
1186 | </p><p>For example, consider the two dimensional array shown below in |
---|
1187 | matrix notation: |
---|
1188 | |
---|
1189 | </p><div><img src="matrix.gif"></div><p> |
---|
1190 | |
---|
1191 | Here is how the above array is expressed in C++: |
---|
1192 | </p><pre class="programlisting"> |
---|
1193 | int a[3][4] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; |
---|
1194 | </pre><p> |
---|
1195 | This is an example of row-major storage, where elements of each row |
---|
1196 | are stored contiguously. |
---|
1197 | |
---|
1198 | While C++ transparently handles accessing elements of an array, you |
---|
1199 | can also manage the array and its indexing manually. One way that |
---|
1200 | this may be expressed in memory is as follows: |
---|
1201 | </p><pre class="programlisting"> |
---|
1202 | int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; |
---|
1203 | int s[] = { 4, 1 }; |
---|
1204 | </pre><p> |
---|
1205 | |
---|
1206 | With the latter declaration of <tt class="literal">a</tt> and |
---|
1207 | strides <tt class="literal">s</tt>, element <tt class="literal">a(i,j)</tt> |
---|
1208 | of the array can be |
---|
1209 | accessed using the expression |
---|
1210 | </p><pre class="programlisting">*a+i*s[0]+j*s[1]</pre><p>. |
---|
1211 | </p><p>The same two dimensional array could be laid out by column as follows: |
---|
1212 | |
---|
1213 | </p><pre class="programlisting"> |
---|
1214 | int a[] = { 0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11 }; |
---|
1215 | int s[] = { 3, 1 }; |
---|
1216 | </pre><p> |
---|
1217 | Notice that the strides here are different. As a result, |
---|
1218 | The expression given above to access values will work with this pair |
---|
1219 | of data and strides as well. |
---|
1220 | </p><p>In addition to dimension order, it is also possible to |
---|
1221 | store any dimension in descending order. For example, returning to the |
---|
1222 | first example, the first dimension of the example array, the |
---|
1223 | rows, could be stored in |
---|
1224 | reverse, resulting in the following: |
---|
1225 | |
---|
1226 | </p><pre class="programlisting"> |
---|
1227 | int data[] = { 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 }; |
---|
1228 | int *a = data + 8; |
---|
1229 | int s[] = { -4, 1 }; |
---|
1230 | </pre><p> |
---|
1231 | |
---|
1232 | Note that in this example <tt class="literal">a</tt> must be explicitly set |
---|
1233 | to the origin. In the previous examples, the |
---|
1234 | first element stored in memory was the origin; here this is no longer |
---|
1235 | the case. |
---|
1236 | </p><p> |
---|
1237 | Alternatively, the second dimension, or the columns, could be reversed |
---|
1238 | and the rows stored in ascending order: |
---|
1239 | |
---|
1240 | </p><pre class="programlisting"> |
---|
1241 | int data[] = { 3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8 }; |
---|
1242 | int *a = data + 3; |
---|
1243 | int s[] = { 4, -1 }; |
---|
1244 | </pre><p> |
---|
1245 | </p><p> |
---|
1246 | Finally, both dimensions could be stored in descending order: |
---|
1247 | |
---|
1248 | </p><pre class="programlisting"> |
---|
1249 | int data[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; |
---|
1250 | int *a = data + 11; |
---|
1251 | int s[] = { -4, -1 }; |
---|
1252 | </pre><p> |
---|
1253 | <tt class="literal"> |
---|
1254 | </tt> |
---|
1255 | </p><p> |
---|
1256 | All of the above arrays are equivalent. The expression |
---|
1257 | given above for <tt class="literal">a(i,j)</tt> will yield the same value |
---|
1258 | regardless of the memory layout. |
---|
1259 | |
---|
1260 | Boost.MultiArray arrays can be created with customized storage |
---|
1261 | parameters as described above. Thus, existing data can be adapted |
---|
1262 | (with <tt class="literal">multi_array_ref</tt> or |
---|
1263 | <tt class="literal">const_multi_array_ref</tt>) as suited to the array |
---|
1264 | abstraction. A common usage of this feature would be to wrap arrays |
---|
1265 | that must interoperate with Fortran routines so they can be |
---|
1266 | manipulated naturally at both the C++ and Fortran levels. The |
---|
1267 | following sections describe the Boost.MultiArray components used to |
---|
1268 | specify memory layout. |
---|
1269 | </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="c_storage_order"></a><tt class="literal">c_storage_order</tt></h4></div></div><div></div></div><pre class="programlisting"> |
---|
1270 | class c_storage_order { |
---|
1271 | c_storage_order(); |
---|
1272 | }; |
---|
1273 | </pre><p><tt class="literal">c_storage_order</tt> is used to specify that an |
---|
1274 | array should store its elements using the same layout as that used by |
---|
1275 | primitive C++ multidimensional arrays, that is, from last dimension |
---|
1276 | to first. This is the default storage order for the arrays provided by |
---|
1277 | this library.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="fortran_storage_order"></a><tt class="literal">fortran_storage_order</tt></h4></div></div><div></div></div><pre class="programlisting"> |
---|
1278 | class fortran_storage_order { |
---|
1279 | fortran_storage_order(); |
---|
1280 | }; |
---|
1281 | </pre><p><tt class="literal">fortran_storage_order</tt> is used to specify that |
---|
1282 | an array should store its elements using the same memory layout as a |
---|
1283 | Fortran multidimensional array would, that is, from first dimension to |
---|
1284 | last.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="general_storage_order"></a><tt class="literal">general_storage_order</tt></h4></div></div><div></div></div><pre class="programlisting"> |
---|
1285 | template <std::size_t NumDims> |
---|
1286 | class general_storage_order { |
---|
1287 | |
---|
1288 | template <typename OrderingIter, typename AscendingIter> |
---|
1289 | general_storage_order(OrderingIter ordering, AscendingIter ascending); |
---|
1290 | }; |
---|
1291 | </pre><p><tt class="literal">general_storage_order</tt> allows the user to |
---|
1292 | specify an arbitrary memory layout for the contents of an array. The |
---|
1293 | constructed object is passed to the array constructor in order to |
---|
1294 | specify storage order.</p><p> |
---|
1295 | <tt class="literal">OrderingIter</tt> and <tt class="literal">AscendingIter</tt> |
---|
1296 | must model the <tt class="literal">InputIterator</tt> concept. Both |
---|
1297 | iterators must refer to a range of <tt class="literal">NumDims</tt> |
---|
1298 | elements. <tt class="literal">AscendingIter</tt> points to objects |
---|
1299 | convertible to <tt class="literal">bool</tt>. A value of |
---|
1300 | <tt class="literal">true</tt> means that a dimension is stored in ascending |
---|
1301 | order while <tt class="literal">false</tt> means that a dimension is stored |
---|
1302 | in descending order. <tt class="literal">OrderingIter</tt> specifies the |
---|
1303 | order in which dimensions are stored. |
---|
1304 | </p></div></div></div></div></body></html> |
---|