reference.html 89 KB

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