multi_array_ref.xml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <sect2 id="multi_array_ref">
  2. <title><literal>multi_array_ref</literal></title>
  3. <para>
  4. <literal>multi_array_ref</literal> is a multi-dimensional container
  5. adaptor. It provides the MultiArray interface over any contiguous
  6. block of elements. <literal>multi_array_ref</literal> exports the
  7. same interface as <literal>multi_array</literal>, with the exception
  8. of the constructors.
  9. </para>
  10. <formalpara>
  11. <title>Model Of.</title>
  12. <para>
  13. <literal>multi_array_ref</literal> models
  14. <link linkend="MultiArray">MultiArray</link>,
  15. <ulink url="../../../libs/utility/CopyConstructible.html">CopyConstructible</ulink>.
  16. and depending on the element type, it may also model
  17. <ulink url="https://www.boost.org/sgi/stl/EqualityComparable.html">EqualityComparable</ulink> and <ulink url="https://www.boost.org/sgi/stl/LessThanComparable.html">LessThanComparable</ulink>.
  18. Detailed descriptions are provided here only for operations that are
  19. not described in the <literal>multi_array</literal> reference.
  20. </para>
  21. </formalpara>
  22. <formalpara>
  23. <title>Synopsis</title>
  24. <programlisting>
  25. <![CDATA[
  26. namespace boost {
  27. template <typename ValueType,
  28. std::size_t NumDims>
  29. class multi_array_ref {
  30. public:
  31. // types:
  32. typedef ValueType element;
  33. typedef *unspecified* value_type;
  34. typedef *unspecified* reference;
  35. typedef *unspecified* const_reference;
  36. typedef *unspecified* difference_type;
  37. typedef *unspecified* iterator;
  38. typedef *unspecified* const_iterator;
  39. typedef *unspecified* reverse_iterator;
  40. typedef *unspecified* const_reverse_iterator;
  41. typedef multi_array_types::size_type size_type;
  42. typedef multi_array_types::index index;
  43. typedef multi_array_types::index_gen index_gen;
  44. typedef multi_array_types::index_range index_range;
  45. typedef multi_array_types::extent_gen extent_gen;
  46. typedef multi_array_types::extent_range extent_range;
  47. typedef *unspecified* storage_order_type;
  48. // template typedefs
  49. template <std::size_t Dims> struct subarray;
  50. template <std::size_t Dims> struct const_subarray;
  51. template <std::size_t Dims> struct array_view;
  52. template <std::size_t Dims> struct const_array_view;
  53. static const std::size_t dimensionality = NumDims;
  54. // constructors and destructors
  55. template <typename ExtentList>
  56. explicit multi_array_ref(element* data, const ExtentList& sizes,
  57. const storage_order_type& store = c_storage_order());
  58. explicit multi_array_ref(element* data, const extents_tuple& ranges,
  59. const storage_order_type& store = c_storage_order());
  60. multi_array_ref(const multi_array_ref& x);
  61. ~multi_array_ref();
  62. // modifiers
  63. multi_array_ref& operator=(const multi_array_ref& x);
  64. template <class Array> multi_array_ref& operator=(const Array& x);
  65. // iterators:
  66. iterator begin();
  67. iterator end();
  68. const_iterator begin() const;
  69. const_iterator end() const;
  70. reverse_iterator rbegin();
  71. reverse_iterator rend();
  72. const_reverse_iterator rbegin() const;
  73. const_reverse_iterator rend() const;
  74. // capacity:
  75. size_type size() const;
  76. size_type num_elements() const;
  77. size_type num_dimensions() const;
  78. // element access:
  79. template <typename IndexList>
  80. element& operator()(const IndexList& indices);
  81. template <typename IndexList>
  82. const element& operator()(const IndexList& indices) const;
  83. reference operator[](index i);
  84. const_reference operator[](index i) const;
  85. array_view<Dims>::type operator[](const indices_tuple& r);
  86. const_array_view<Dims>::type operator[](const indices_tuple& r) const;
  87. // queries
  88. element* data();
  89. const element* data() const;
  90. element* origin();
  91. const element* origin() const;
  92. const size_type* shape() const;
  93. const index* strides() const;
  94. const index* index_bases() const;
  95. const storage_order_type& storage_order() const;
  96. // comparators
  97. bool operator==(const multi_array_ref& rhs);
  98. bool operator!=(const multi_array_ref& rhs);
  99. bool operator<(const multi_array_ref& rhs);
  100. bool operator>(const multi_array_ref& rhs);
  101. bool operator>=(const multi_array_ref& rhs);
  102. bool operator<=(const multi_array_ref& rhs);
  103. // modifiers:
  104. template <typename InputIterator>
  105. void assign(InputIterator begin, InputIterator end);
  106. template <typename SizeList>
  107. void reshape(const SizeList& sizes)
  108. template <typename BaseList> void reindex(const BaseList& values);
  109. void reindex(index value);
  110. };
  111. ]]>
  112. </programlisting>
  113. </formalpara>
  114. <formalpara>
  115. <title>Constructors</title>
  116. <variablelist>
  117. <varlistentry>
  118. <term><programlisting>template &lt;typename ExtentList&gt;
  119. explicit multi_array_ref(element* data,
  120. const ExtentList&amp; sizes,
  121. const storage_order&amp; store = c_storage_order(),
  122. const Allocator&amp; alloc = Allocator());
  123. </programlisting></term>
  124. <listitem>
  125. <para>
  126. This constructs a <literal>multi_array_ref</literal> using the specified
  127. parameters. <literal>sizes</literal> specifies the shape of the
  128. constructed <literal>multi_array_ref</literal>. <literal>store</literal>
  129. specifies the storage order or layout in memory of the array
  130. dimensions. <literal>alloc</literal> is used to
  131. allocate the contained elements.
  132. </para>
  133. <formalpara><title><literal>ExtentList</literal> Requirements</title>
  134. <para>
  135. <literal>ExtentList</literal> must model <ulink url="../../utility/Collection.html">Collection</ulink>.
  136. </para>
  137. </formalpara>
  138. <formalpara><title>Preconditions</title>
  139. <para><literal>sizes.size() == NumDims;</literal></para>
  140. </formalpara>
  141. </listitem>
  142. </varlistentry>
  143. <varlistentry>
  144. <term>
  145. <programlisting><![CDATA[explicit multi_array_ref(element* data,
  146. extent_gen::gen_type<NumDims>::type ranges,
  147. const storage_order& store = c_storage_order());]]>
  148. </programlisting></term>
  149. <listitem>
  150. <para>
  151. This constructs a <literal>multi_array_ref</literal> using the specified
  152. parameters. <literal>ranges</literal> specifies the shape and
  153. index bases of the constructed multi_array_ref. It is the result of
  154. <literal>NumDims</literal> chained calls to
  155. <literal>extent_gen::operator[]</literal>. <literal>store</literal>
  156. specifies the storage order or layout in memory of the array
  157. dimensions.
  158. </para>
  159. </listitem>
  160. </varlistentry>
  161. <varlistentry>
  162. <term><programlisting>
  163. <![CDATA[multi_array_ref(const multi_array_ref& x);]]>
  164. </programlisting></term>
  165. <listitem>
  166. <para>This constructs a shallow copy of <literal>x</literal>.
  167. </para>
  168. <formalpara>
  169. <title>Complexity</title>
  170. <para> Constant time (for contrast, compare this to
  171. the <literal>multi_array</literal> class copy constructor.
  172. </para></formalpara>
  173. </listitem>
  174. </varlistentry>
  175. </variablelist>
  176. </formalpara>
  177. <formalpara>
  178. <title>Modifiers</title>
  179. <variablelist>
  180. <varlistentry>
  181. <term><programlisting>
  182. <![CDATA[multi_array_ref& operator=(const multi_array_ref& x);
  183. template <class Array> multi_array_ref& operator=(const Array& x);]]>
  184. </programlisting>
  185. </term>
  186. <listitem>
  187. <para>This performs an element-wise copy of <literal>x</literal>
  188. into the current <literal>multi_array_ref</literal>.</para>
  189. <formalpara>
  190. <title><literal>Array</literal> Requirements</title>
  191. <para><literal>Array</literal> must model MultiArray.
  192. </para></formalpara>
  193. <formalpara>
  194. <title>Preconditions</title>
  195. <para>
  196. <programlisting>std::equal(this->shape(),this->shape()+this->num_dimensions(),
  197. x.shape());</programlisting></para>
  198. </formalpara>
  199. <formalpara>
  200. <title>Postconditions</title>
  201. <para>
  202. <programlisting>(*.this) == x;</programlisting>
  203. </para>
  204. </formalpara>
  205. <formalpara>
  206. <title>Complexity</title>
  207. <para>The assignment operators perform
  208. O(<literal>x.num_elements()</literal>) calls to <literal>element</literal>'s
  209. copy constructor.</para></formalpara>
  210. </listitem>
  211. </varlistentry>
  212. </variablelist>
  213. </formalpara>
  214. </sect2>