Brian Silverman | 6137817 | 2018-08-04 23:37:59 -0700 | [diff] [blame^] | 1 | <sect2 id="multi_array_ref"> |
| 2 | <title><literal>multi_array_ref</literal></title> |
| 3 | |
| 4 | <para> |
| 5 | <literal>multi_array_ref</literal> is a multi-dimensional container |
| 6 | adaptor. It provides the MultiArray interface over any contiguous |
| 7 | block of elements. <literal>multi_array_ref</literal> exports the |
| 8 | same interface as <literal>multi_array</literal>, with the exception |
| 9 | of the constructors. |
| 10 | </para> |
| 11 | |
| 12 | |
| 13 | <formalpara> |
| 14 | <title>Model Of.</title> |
| 15 | <para> |
| 16 | <literal>multi_array_ref</literal> models |
| 17 | <link linkend="MultiArray">MultiArray</link>, |
| 18 | <ulink url="../../../libs/utility/CopyConstructible.html">CopyConstructible</ulink>. |
| 19 | and depending on the element type, it may also model |
| 20 | <ulink url="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</ulink> and <ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink>. |
| 21 | Detailed descriptions are provided here only for operations that are |
| 22 | not described in the <literal>multi_array</literal> reference. |
| 23 | </para> |
| 24 | </formalpara> |
| 25 | |
| 26 | <formalpara> |
| 27 | <title>Synopsis</title> |
| 28 | |
| 29 | <programlisting> |
| 30 | <; |
| 101 | const_reference operator[](index i) const; |
| 102 | array_view<Dims>::type operator[](const indices_tuple& r); |
| 103 | const_array_view<Dims>::type operator[](const indices_tuple& r) const; |
| 104 | |
| 105 | // queries |
| 106 | element* data(); |
| 107 | const element* data() const; |
| 108 | element* origin(); |
| 109 | const element* origin() const; |
| 110 | const size_type* shape() const; |
| 111 | const index* strides() const; |
| 112 | const index* index_bases() const; |
| 113 | const storage_order_type& storage_order() const; |
| 114 | |
| 115 | // comparators |
| 116 | bool operator==(const multi_array_ref& rhs); |
| 117 | bool operator!=(const multi_array_ref& rhs); |
| 118 | bool operator<(const multi_array_ref& rhs); |
| 119 | bool operator>(const multi_array_ref& rhs); |
| 120 | bool operator>=(const multi_array_ref& rhs); |
| 121 | bool operator<=(const multi_array_ref& rhs); |
| 122 | |
| 123 | // modifiers: |
| 124 | template <typename InputIterator> |
| 125 | void assign(InputIterator begin, InputIterator end); |
| 126 | template <typename SizeList> |
| 127 | void reshape(const SizeList& sizes) |
| 128 | template <typename BaseList> void reindex(const BaseList& values); |
| 129 | void reindex(index value); |
| 130 | }; |
| 131 | ]]> |
| 132 | </programlisting> |
| 133 | </formalpara> |
| 134 | |
| 135 | <formalpara> |
| 136 | <title>Constructors</title> |
| 137 | |
| 138 | <variablelist> |
| 139 | <varlistentry> |
| 140 | <term><programlisting>template <typename ExtentList> |
| 141 | explicit multi_array_ref(element* data, |
| 142 | const ExtentList& sizes, |
| 143 | const storage_order& store = c_storage_order(), |
| 144 | const Allocator& alloc = Allocator()); |
| 145 | </programlisting></term> |
| 146 | <listitem> |
| 147 | |
| 148 | <para> |
| 149 | This constructs a <literal>multi_array_ref</literal> using the specified |
| 150 | parameters. <literal>sizes</literal> specifies the shape of the |
| 151 | constructed <literal>multi_array_ref</literal>. <literal>store</literal> |
| 152 | specifies the storage order or layout in memory of the array |
| 153 | dimensions. <literal>alloc</literal> is used to |
| 154 | allocate the contained elements. |
| 155 | </para> |
| 156 | |
| 157 | <formalpara><title><literal>ExtentList</literal> Requirements</title> |
| 158 | <para> |
| 159 | <literal>ExtentList</literal> must model <ulink url="../../utility/Collection.html">Collection</ulink>. |
| 160 | </para> |
| 161 | </formalpara> |
| 162 | |
| 163 | <formalpara><title>Preconditions</title> |
| 164 | <para><literal>sizes.size() == NumDims;</literal></para> |
| 165 | </formalpara> |
| 166 | |
| 167 | </listitem> |
| 168 | </varlistentry> |
| 169 | |
| 170 | <varlistentry> |
| 171 | <term> |
| 172 | <programlisting><![CDATA[explicit multi_array_ref(element* data, |
| 173 | extent_gen::gen_type<NumDims>::type ranges, |
| 174 | const storage_order& store = c_storage_order());]]> |
| 175 | </programlisting></term> |
| 176 | <listitem> |
| 177 | <para> |
| 178 | This constructs a <literal>multi_array_ref</literal> using the specified |
| 179 | parameters. <literal>ranges</literal> specifies the shape and |
| 180 | index bases of the constructed multi_array_ref. It is the result of |
| 181 | <literal>NumDims</literal> chained calls to |
| 182 | <literal>extent_gen::operator[]</literal>. <literal>store</literal> |
| 183 | specifies the storage order or layout in memory of the array |
| 184 | dimensions. |
| 185 | </para> |
| 186 | </listitem> |
| 187 | </varlistentry> |
| 188 | |
| 189 | |
| 190 | <varlistentry> |
| 191 | <term><programlisting> |
| 192 | <![CDATA[multi_array_ref(const multi_array_ref& x);]]> |
| 193 | </programlisting></term> |
| 194 | <listitem> |
| 195 | <para>This constructs a shallow copy of <literal>x</literal>. |
| 196 | </para> |
| 197 | |
| 198 | <formalpara> |
| 199 | <title>Complexity</title> |
| 200 | <para> Constant time (for contrast, compare this to |
| 201 | the <literal>multi_array</literal> class copy constructor. |
| 202 | </para></formalpara> |
| 203 | </listitem> |
| 204 | </varlistentry> |
| 205 | |
| 206 | </variablelist> |
| 207 | |
| 208 | </formalpara> |
| 209 | |
| 210 | |
| 211 | <formalpara> |
| 212 | <title>Modifiers</title> |
| 213 | |
| 214 | <variablelist> |
| 215 | <varlistentry> |
| 216 | |
| 217 | <term><programlisting> |
| 218 | <![CDATA[multi_array_ref& operator=(const multi_array_ref& x); |
| 219 | template <class Array> multi_array_ref& operator=(const Array& x);]]> |
| 220 | </programlisting> |
| 221 | </term> |
| 222 | |
| 223 | <listitem> |
| 224 | <para>This performs an element-wise copy of <literal>x</literal> |
| 225 | into the current <literal>multi_array_ref</literal>.</para> |
| 226 | |
| 227 | <formalpara> |
| 228 | <title><literal>Array</literal> Requirements</title> |
| 229 | <para><literal>Array</literal> must model MultiArray. |
| 230 | </para></formalpara> |
| 231 | |
| 232 | <formalpara> |
| 233 | <title>Preconditions</title> |
| 234 | <para> |
| 235 | <programlisting>std::equal(this->shape(),this->shape()+this->num_dimensions(), |
| 236 | x.shape());</programlisting></para> |
| 237 | </formalpara> |
| 238 | |
| 239 | |
| 240 | <formalpara> |
| 241 | <title>Postconditions</title> |
| 242 | <para> |
| 243 | <programlisting>(*.this) == x;</programlisting> |
| 244 | </para> |
| 245 | </formalpara> |
| 246 | |
| 247 | <formalpara> |
| 248 | <title>Complexity</title> |
| 249 | <para>The assignment operators perform |
| 250 | O(<literal>x.num_elements()</literal>) calls to <literal>element</literal>'s |
| 251 | copy constructor.</para></formalpara> |
| 252 | </listitem> |
| 253 | </varlistentry> |
| 254 | </variablelist> |
| 255 | |
| 256 | </formalpara> |
| 257 | </sect2> |