Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/multi_array/doc/xml/MultiArray.xml @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 31.2 KB
Line 
1<sect1 id="MultiArray"><title>MultiArray Concept</title>
2
3
4<para>The MultiArray
5concept defines an interface to hierarchically nested
6containers.  It specifies operations for accessing elements,
7traversing containers, and creating views
8of array data.
9MultiArray defines
10a flexible memory model that accomodates
11a variety of data layouts.
12</para>
13
14<para>
15At each level (or dimension) of a MultiArray's
16container hierarchy lie a set of ordered containers, each of which
17contains the same number and type of values. The depth of this
18container hierarchy is the MultiArray's <emphasis>dimensionality</emphasis>.
19MultiArray is recursively defined; the
20containers at each level of the container hierarchy model
21MultiArray as well. While each dimension of a MultiArray
22has its own size, the list of sizes for all dimensions
23defines the <emphasis>shape</emphasis> of the entire MultiArray.
24At the base of this hierarchy lie 1-dimensional
25MultiArrays.  Their values are the contained
26objects of interest and not part of the container hierarchy. These are
27the MultiArray's elements.
28</para>
29
30
31<para>
32Like other container concepts, MultiArray exports
33iterators to traverse its values. In addition, values can be
34addressed directly using the familiar bracket notation.
35</para>
36
37<para>
38MultiArray also specifies
39routines for creating
40specialized views. A <emphasis>view</emphasis> lets you treat a
41subset of the underlying
42elements in a MultiArray as though it were a separate
43MultiArray. Since a view refers to the same underlying elements,
44changes made to a view's elements will be reflected in the original
45MultiArray. For
46example, given a 3-dimensional "cube" of elements, a 2-dimensional
47slice can be viewed as if it were an independent
48MultiArray.
49
50Views are created using <literal>index_gen</literal> and
51<literal>index_range</literal> objects.
52<literal>index_range</literal>s denote elements from a certain
53dimension that are to be included in a
54view. <literal>index_gen</literal> aggregates range data and performs
55bookkeeping to determine the view type to be returned.
56
57MultiArray's <literal>operator[]</literal>
58 must be passed the result
59of <literal>N</literal> chained calls to
60<literal>index_gen::operator[]</literal>, i.e.
61
62<programlisting>indices[a0][a1]...[aN];
63</programlisting>
64
65where <literal>N</literal> is the
66MultiArray's dimensionality and
67<literal>indices</literal> an object of type <literal>index_gen</literal>.
68
69The view type is dependent upon the number of degenerate dimensions
70specified to <literal>index_gen</literal>.  A degenerate dimension
71occurs when a single-index is specified to
72<literal>index_gen</literal> for a certain dimension.  For example, if
73<literal>indices</literal> is an object of type
74<literal>index_gen</literal>, then the following example:
75
76<programlisting>indices[index_range(0,5)][2][index_range(0,4)];
77</programlisting>
78
79has a degenerate second dimension.  The view generated from the above
80specification will have 2 dimensions with shape <literal>5 x 4</literal>.
81If the "<literal>2</literal>" above were replaced with
82another <literal>index_range</literal> object, for example:
83
84<programlisting>indices[index_range(0,5)][index_range(0,2)][index_range(0,4)];
85</programlisting>
86
87then the view would have 3 dimensions.</para>
88
89<para>
90MultiArray exports
91information regarding the memory
92layout of its contained elements. Its memory model for elements is
93completely defined by 4 properties: the origin, shape, index bases,
94and strides.  The origin is the address in memory of the element
95accessed as <literal>a[0][0]...[0]</literal>, where
96<literal>a</literal> is a MultiArray. The shape is a list of numbers
97specifying the size of containers at each dimension.  For example, the
98first extent is the size of the outermost container, the second extent
99is the size of its subcontainers, and so on. The index bases are a
100list of signed values specifying the index of the first value in a
101container. All containers at the same dimension share the same index
102base.  Note that since positive index bases are
103possible, the origin need not exist in order to determine the location
104in memory of the MultiArray's elements.
105  The strides determine how index values are mapped to memory offsets.
106They accomodate a
107number of possible element layouts.  For example, the elements of a 2
108dimensional array can be stored by row (i.e., the elements of each row
109are stored contiguously) or by column (i.e., the elements of each
110column are stored contiguously).
111</para>
112
113
114<sect2><title>Notation</title>
115<para>What follows are the descriptions of symbols that will be used
116to describe the MultiArray interface.</para>
117    <table>
118      <title>Notation</title>
119      <tgroup cols="2">
120        <tbody>
121          <row>
122              <entry><literal>A</literal></entry>
123              <entry>A type that is a model of MultiArray
124</entry>
125            </row>
126            <row>
127              <entry><literal>a,b</literal></entry>
128              <entry>Objects of type <literal>A</literal></entry>
129            </row>
130            <row>
131              <entry><literal>NumDims</literal></entry>
132              <entry>The numeric dimension parameter associated with
133<literal>A</literal>.</entry>
134            </row>
135            <row>
136              <entry><literal>Dims</literal></entry>
137              <entry>Some numeric dimension parameter such that
138<literal>0&lt;Dims&lt;NumDims</literal>.
139</entry>
140          </row>
141          <row>
142              <entry><literal>indices</literal></entry>
143              <entry>An object created by some number of chained calls
144to <literal>index_gen::operator[](index_range)</literal>.</entry>
145            </row>
146            <row>
147              <entry><literal>index_list</literal></entry>
148              <entry>An object whose type models
149<ulink url="../../utility/Collection.html">Collection</ulink>
150</entry>
151            </row>
152            <row>
153              <entry><literal>idx</literal></entry>
154              <entry>A signed integral value.</entry>
155            </row>
156            <row>
157              <entry><literal>tmp</literal></entry> 
158              <entry>An object of type
159              <literal>boost::array&lt;index,NumDims&gt;</literal></entry>
160            </row>
161        </tbody>
162      </tgroup>
163    </table>
164</sect2>
165
166<sect2><title>Associated Types</title>
167<para>
168</para>
169<table><title>Associated Types</title>
170<tgroup cols="2">
171
172<thead>
173<row>
174<entry>Type</entry>
175<entry>Description</entry>
176</row>
177</thead>
178
179<tbody>
180
181<row>
182<entry><literal>value_type</literal></entry>
183
184<entry>This is the value type of the container.
185  If <literal>NumDims == 1</literal>, then this is
186<literal>element</literal>. Otherwise, this is the value type of the
187immediately nested containers.
188</entry>
189</row>
190
191<row>
192<entry>
193<literal>reference</literal>
194</entry>
195
196<entry>
197This is the reference type of the contained value.
198If <literal>NumDims == 1</literal>, then this is
199<literal>element&amp;</literal>. Otherwise, this is the same type as
200<literal>template subarray&lt;NumDims-1&gt;::type</literal>.
201</entry>
202</row>
203
204<row>
205<entry>
206<literal>const_reference</literal>
207</entry>
208<entry>
209This is the const reference type of the contained value.
210If <literal>NumDims == 1</literal>, then this is 
211<literal>const element&amp;</literal>. Otherwise, this is the same
212type as
213<literal>template const_subarray&lt;NumDims-1&gt;::type</literal>.
214</entry>
215</row>
216
217<row>
218<entry>
219<literal>size_type</literal>
220</entry>
221<entry>
222This is an unsigned integral type.  It is primarily used to specify array shape.
223</entry>
224</row>
225
226
227<row>
228<entry>
229<literal>difference_type</literal>
230</entry>
231<entry>
232This is a signed integral type used to represent the distance between two
233iterators. It is the same type as
234<literal>std::iterator_traits&lt;iterator&gt;::difference_type</literal>.
235</entry>
236</row>
237
238<row>
239<entry><literal>iterator</literal></entry>
240<entry>
241This is an iterator over the values of <literal>A</literal>.
242If <literal>NumDims == 1</literal>, then it models
243<ulink url="http://www.sgi.com/tech/stl/RandomAccessIterator.html">
244<literal>Random Access Iterator</literal></ulink>.
245Otherwise it models
246<ulink url="./iterator_categories.html#concept_RandomAccessTraversalIterator">
247Random Access Traversal Iterator</ulink>,
248<ulink url="./iterator_categories.html#concept_ReadableIterator">
249Readable Iterator</ulink>, and
250<ulink url="./iterator_categories.html#concept_WritableIterator">
251Writable Iterator</ulink>.
252</entry>
253</row>
254
255<row>
256<entry>
257<literal>const_iterator</literal>
258</entry>
259<entry>
260This is the const iterator over the values of <literal>A</literal>.
261</entry>
262</row>
263<row>
264
265<entry>
266<literal>reverse_iterator</literal>
267</entry>
268<entry>
269This is the reversed iterator, used to iterate backwards over the values of
270<literal>A</literal>.
271</entry>
272</row>
273
274<row>
275<entry>
276<literal>const_reverse_iterator</literal>
277</entry>
278<entry>
279This is the reversed const iterator.
280<literal>A</literal>.
281</entry>
282</row>
283<row>
284
285<entry>
286<literal>element</literal>
287</entry>
288<entry>
289This is the type of objects stored at the base of the
290hierarchy of MultiArrays. It is the same as
291<literal>template subarray&lt;1&gt;::value_type</literal>
292</entry>
293</row>
294
295<row>
296<entry>
297<literal>index</literal>
298</entry>
299<entry>
300This is a signed integral type used for indexing into <literal>A</literal>. It
301is also used to represent strides and index bases.
302</entry>
303</row>
304
305<row>
306<entry>
307<literal>index_gen</literal>
308</entry>
309<entry>
310This type is used to create a tuple of <literal>index_range</literal>s
311passed to <literal>operator[]</literal> to create
312an <literal>array_view&lt;Dims&gt;::type</literal> object.
313</entry>
314</row>
315
316<row>
317<entry>
318<literal>index_range</literal>
319</entry>
320<entry>
321This type specifies a range of indices over some dimension of a
322MultiArray.  This range will be visible through an
323<literal>array_view&lt;Dims&gt;::type</literal> object.
324</entry>
325</row>
326
327<row>
328<entry>
329<literal>template subarray&lt;Dims&gt;::type</literal>
330</entry>
331<entry>
332This is subarray type with <literal>Dims</literal> dimensions.
333It is the reference type of the <literal>(NumDims - Dims)</literal>
334dimension of <literal>A</literal> and also models
335MultiArray.
336</entry>
337</row>
338
339<row>
340<entry>
341<literal>template const_subarray&lt;Dims&gt;::type</literal>
342</entry>
343<entry>
344This is the const subarray type.
345</entry>
346</row>
347
348<row>
349<entry>
350<literal>template array_view&lt;Dims&gt;::type</literal>
351</entry>
352<entry>
353This is the view type with <literal>Dims</literal> dimensions.  It is
354returned by calling <literal>operator[](<literal>indices</literal>)</literal>.
355It models MultiArray.
356</entry>
357</row>
358
359<row>
360<entry>
361<literal>template
362const_array_view&lt;Dims&gt;::type</literal>
363</entry>
364<entry>
365This is the const view type with <literal>Dims</literal> dimensions.
366</entry>
367</row>
368
369</tbody>
370</tgroup>
371</table>
372
373</sect2>
374
375
376  <sect2><title>Valid expressions</title>
377   
378    <table><title>Valid Expressions</title>
379      <tgroup cols="3">
380        <thead>
381          <row>
382            <entry>Expression</entry>
383            <entry>Return type</entry>
384            <entry>Semantics</entry>
385          </row>
386        </thead>
387        <tbody>
388          <row>
389            <entry><literal>a.shape()</literal></entry>
390            <entry><literal>const size_type*</literal></entry>
391            <entry>
392This returns a list of <literal>NumDims</literal> elements specifying the
393extent of each array dimension.
394</entry>
395          </row>
396
397          <row>
398            <entry><literal>a.strides()</literal></entry>
399            <entry><literal>const index*</literal></entry>
400            <entry>
401This returns a list of <literal>NumDims</literal> elements specifying the
402stride associated with each array dimension. When accessing values,
403strides is used to calculate an element's location in memory.
404</entry>
405          </row>
406
407          <row>
408            <entry><literal>a.index_bases()</literal></entry>
409            <entry><literal>const index*</literal></entry>
410            <entry>
411This returns a list of <literal>NumDims</literal> elements specifying the
412numeric index of the first element for each array dimension.
413</entry>
414          </row>
415          <row>
416            <entry><literal>a.origin()</literal></entry>
417            <entry>
418<literal>element*</literal> if <literal>a</literal> is mutable,
419<literal>const element*</literal> otherwise.
420</entry>
421<entry>
422This returns the address of the element accessed by the expression
423<literal>a[0][0]...[0].</literal>. If the index bases are positive,
424this element won't exist, but the address can still be used to locate
425a valid element given its indices.
426</entry>
427          </row>
428          <row>
429            <entry><literal>a.num_dimensions()</literal></entry>
430            <entry><literal>size_type</literal></entry>
431            <entry>This returns the number of dimensions of the array
432(note that <literal>a.num_dimensions() == NumDims</literal>).</entry>
433          </row>
434
435            <row>
436              <entry><literal>a.num_elements()</literal></entry>
437              <entry><literal>size_type</literal></entry>
438              <entry>This returns the number of elements contained
439in the array. It is equivalent to the following code:
440<programlisting>
441std::accumulate(a.shape(),a.shape+a.num_dimensions(),
442    size_type(1),std::multiplies&lt;size_type&gt;());
443</programlisting>
444</entry>
445          </row>
446
447          <row>
448            <entry><literal>a.size()</literal></entry>
449            <entry><literal>size_type</literal></entry>
450            <entry>
451This returns the number of values contained in
452<literal>a</literal>. It is equivalent to <literal>a.shape()[0];</literal>
453</entry>
454          </row>
455          <row>
456            <entry><literal>a(index_list)</literal></entry>
457            <entry>
458<literal>element&amp;</literal>;  if <literal>a</literal> is mutable,
459<literal>const element&amp;</literal> otherwise.
460            </entry>
461            <entry>
462This expression accesses a specific element of
463<literal>a</literal>.<literal>index_list</literal> is the unique set
464of indices that address the element returned.  It is
465equivalent to the following code (disregarding intermediate temporaries):
466<programlisting>
467    // multiply indices by strides
468    std::transform(index_list.begin(), index_list.end(),
469      a.strides(), tmp.begin(), std::multiplies&lt;index&gt;()),
470
471    // add the sum of the products to the origin
472    *std::accumulate(tmp.begin(), tmp.end(), a.origin());
473</programlisting>
474</entry>
475          </row>
476
477          <row>
478            <entry><literal>a.begin()</literal></entry>
479            <entry>
480<literal>iterator</literal> if <literal>a</literal> is mutable,
481<literal>const_iterator</literal> otherwise.
482            </entry>
483            <entry>This returns an iterator pointing to the beginning of
484<literal>a</literal>.</entry>
485          </row>
486
487          <row>
488            <entry><literal>a.end()</literal></entry>
489            <entry>
490<literal>iterator</literal> if <literal>a</literal> is mutable,
491<literal>const_iterator</literal> otherwise.
492            </entry>
493              <entry>This returns an iterator pointing to the end of
494<literal>a</literal>.</entry>
495          </row>
496
497          <row>
498            <entry><literal>a.rbegin()</literal></entry>
499            <entry>
500<literal>reverse_iterator</literal> if <literal>a</literal> is mutable,
501<literal>const_reverse_iterator</literal> otherwise.
502            </entry>
503            <entry>This returns a reverse iterator pointing to the
504beginning of <literal>a</literal> reversed.
505</entry>
506          </row>
507
508          <row>
509            <entry><literal>a.rend()</literal></entry>
510            <entry>
511<literal>reverse_iterator</literal> if <literal>a</literal> is mutable,
512<literal>const_reverse_iterator</literal> otherwise.
513</entry>
514            <entry>
515This returns a reverse iterator pointing to the end of <literal>a</literal>
516reversed.
517</entry>
518</row>
519          <row>
520            <entry><literal>a[idx]</literal></entry>
521            <entry>
522<literal>reference</literal> if <literal>a</literal> is mutable,
523<literal>const_reference</literal> otherwise.
524            </entry>
525            <entry>
526This returns a reference type that is bound to the index
527<literal>idx</literal> value of <literal>a</literal>.  Note that if
528<literal>i</literal> is the index base for this dimension, the above
529expression returns the <literal>(idx-i)</literal>th element (counting
530from zero).  The expression is equivalent to
531<literal>*(a.begin()+idx-a.index_bases()[0]);</literal>.
532</entry>
533          </row>
534
535          <row>
536            <entry><literal>a[indices]</literal></entry>
537            <entry>
538<literal>array_view&lt;Dims&gt;::type</literal> if
539<literal>a</literal> is mutable,
540<literal>const_array_view&lt;Dims&gt;::type</literal> otherwise.
541            </entry>
542        <entry>
543This expression generates a view of the array determined by the
544<literal>index_range</literal> and <literal>index</literal> values
545 used to construct <literal>indices</literal>.
546</entry>
547      </row>
548            <row>
549              <entry><literal>a == b</literal></entry>
550              <entry>bool</entry>
551              <entry>This performs a lexicographical comparison of the
552values of <literal>a</literal> and <literal>b</literal>.  The element
553type must model <ulink url="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</ulink> for this
554expression to be valid.</entry>
555            </row>
556            <row>
557              <entry><literal>a &lt; b</literal></entry>
558              <entry>bool</entry>
559              <entry>This performs a lexicographical comparison of the
560values of <literal>a</literal> and <literal>b</literal>.  The element
561type must model <ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink> for this
562expression to be valid.</entry>
563            </row>
564            <row>
565              <entry><literal>a &lt;= b</literal></entry>
566              <entry>bool</entry>
567              <entry>This performs a lexicographical comparison of the
568values of <literal>a</literal> and <literal>b</literal>.  The element
569type must model <ulink url="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</ulink> and
570<ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink> for this
571expression to be valid.</entry>
572            </row>
573            <row>
574              <entry><literal>a &gt; b</literal></entry>
575              <entry>bool</entry>
576              <entry>This performs a lexicographical comparison of the
577values of <literal>a</literal> and <literal>b</literal>.  The element
578type must model <ulink url="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</ulink> and
579<ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink> for this
580expression to be valid.</entry>
581            </row>
582            <row>
583              <entry><literal>a &gt;= b</literal></entry>
584              <entry>bool</entry>
585              <entry>This performs a lexicographical comparison of the
586values of <literal>a</literal> and <literal>b</literal>.  The element
587type must model <ulink url="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</ulink> for this
588expression to be valid.</entry>
589            </row>
590    </tbody>
591    </tgroup>
592    </table>
593    </sect2>
594
595
596<sect2><title>Complexity guarantees</title>
597
598<literal>begin()</literal> and <literal>end()</literal> execute in amortized
599constant time.
600<literal>size()</literal> executes in at most linear time in the
601MultiArray's size.
602</sect2>
603
604<sect2>
605<title>Invariants</title>
606<table><title>Invariants</title>
607      <tgroup cols="2">
608        <tbody>
609          <row>
610            <entry>Valid range</entry>
611            <entry><literal>[a.begin(),a.end())</literal> is a valid range.
612            </entry>
613          </row>
614
615          <row>
616            <entry>Range size</entry>
617            <entry>
618<literal>a.size() == std::distance(a.begin(),a.end());</literal>.
619</entry>
620          </row>
621
622          <row>
623            <entry>Completeness</entry>
624            <entry>
625Iteration through the range
626<literal>[a.begin(),a.end())</literal> will traverse across every
627<literal>value_type</literal> of <literal>a</literal>.
628</entry>
629            </row>
630            <row>
631              <entry>Accessor Equivalence</entry>
632              <entry>
633Calling <literal>a[a1][a2]...[aN]</literal> where <literal>N==NumDims</literal>
634yields the same result as calling
635<literal>a(index_list)</literal>, where <literal>index_list</literal>
636is a <ulink url="../../utility/Collection.html">Collection</ulink> containing the values <literal>a1...aN</literal>.
637</entry>
638              </row>
639        </tbody>
640      </tgroup>
641    </table>
642  </sect2>
643
644<sect2 id="view_types">
645      <title>Associated Types for Views</title>
646      <para>The following MultiArray  associated
647types define the interface for creating views of existing
648MultiArrays. Their interfaces and roles in the
649concept are described below.</para>
650 
651  <sect3 id="index_range">
652    <title><literal>index_range</literal></title>
653
654    <para><literal>index_range</literal> objects represent half-open
655strided intervals.  They are aggregated (using an
656<literal>index_gen</literal> object) and passed to
657a MultiArray's <literal>operator[]</literal>
658to create an array view. When creating a view,
659each <literal>index_range</literal> denotes a range of
660valid indices along one dimension of a MultiArray.
661Elements that are accessed through the set of ranges specified will be
662included in the constructed view. In some cases, an
663<literal>index_range</literal> is created without specifying start
664or finish values.  In those cases, the object is interpreted to
665start at the beginning of a MultiArray dimension
666and end at its end.</para>
667
668<para>
669<literal>index_range</literal> objects can be constructed and modified
670several ways in order to allow convenient and clear expression of a
671range of indices.  To specify ranges, <literal>index_range</literal>
672supports a set of constructors, mutating member functions, and a novel
673specification involving inequality operators.  Using inequality
674operators,  a half open range [5,10) can be specified as follows:
675<programlisting>5 &lt;= index_range() &lt; 10;</programlisting> or
676<programlisting>4 &lt; index_range() &lt;= 9;</programlisting> and so on.
677
678The following describes the
679<literal>index_range</literal> interface.
680</para>
681
682    <table>
683      <title>Notation</title>
684      <tgroup cols="2">
685        <tbody>
686          <row>
687            <entry><literal>i</literal></entry>
688            <entry>An object of type <literal>index_range</literal>.</entry>
689          </row>
690          <row>
691            <entry><literal>idx,idx1,idx2,idx3</literal></entry>
692            <entry>Objects of type <literal>index</literal>.</entry>
693          </row>
694        </tbody>
695      </tgroup>
696    </table>
697
698    <table><title>Associated Types</title>
699      <tgroup cols="2">
700        <thead>
701          <row>
702            <entry>Type</entry>
703            <entry>Description</entry>
704          </row>
705        </thead>
706        <tbody>
707          <row>
708            <entry><literal>index</literal></entry>
709            <entry>This is a signed integral type. It is used to
710specify the start, finish, and stride values.</entry>
711          </row>
712          <row>
713            <entry><literal>size_type</literal></entry>
714            <entry>This is an unsigned integral type. It is used to
715report the size of the range an <literal>index_range</literal> 
716represents.</entry>
717          </row>
718        </tbody>
719      </tgroup>
720    </table>
721   
722
723    <table><title>Valid Expressions</title>
724      <tgroup cols="3">
725        <thead>
726          <row>
727            <entry>Expression</entry>
728            <entry>Return type</entry>
729            <entry>Semantics</entry>
730          </row>
731        </thead>
732        <tbody>
733          <row>
734            <entry><literal>index_range(idx1,idx2,idx3)</literal></entry>
735            <entry><literal>index_range</literal></entry>
736            <entry>This constructs an <literal>index_range</literal>
737            representing the interval <literal>[idx1,idx2)</literal>
738 with stride <literal>idx3</literal>.</entry>
739          </row>
740          <row>
741            <entry><literal>index_range(idx1,idx2)</literal></entry>
742            <entry><literal>index_range</literal></entry>
743            <entry>This constructs an <literal>index_range</literal>
744            representing the interval <literal>[idx1,idx2)</literal>
745 with unit stride. It is equivalent to
746            <literal>index_range(idx1,idx2,1)</literal>.</entry>
747          </row>
748          <row>
749            <entry><literal>index_range()</literal></entry>
750            <entry><literal>index_range</literal></entry>
751            <entry>This construct an <literal>index_range</literal>
752with unspecified start and finish values.</entry>
753          </row>
754          <row>
755            <entry><literal>i.start(idx1)</literal></entry> 
756            <entry><literal>index&amp;</literal></entry>
757            <entry>This sets the start index of <literal>i</literal> to
758            <literal>idx</literal>.</entry>
759          </row>
760          <row>
761            <entry><literal>i.finish(idx)</literal></entry>
762            <entry><literal>index&amp;</literal></entry>
763            <entry>This sets the finish index of <literal>i</literal> to
764            <literal>idx</literal>.</entry>
765          </row>
766          <row>
767            <entry><literal>i.stride(idx)</literal></entry>
768            <entry><literal>index&amp;</literal></entry>
769            <entry>This sets the stride length of <literal>i</literal> to
770            <literal>idx</literal>.</entry>
771          </row>
772          <row>
773            <entry><literal>i.start()</literal></entry>
774            <entry><literal>index</literal></entry>
775            <entry>This returns the start index of <literal>i</literal>.</entry>
776          </row>
777          <row>
778            <entry><literal>i.finish()</literal></entry>
779            <entry><literal>index</literal></entry>
780            <entry>This returns the finish index of <literal>i</literal>.</entry>
781          </row>
782          <row>
783            <entry><literal>i.stride()</literal></entry>
784            <entry><literal>index</literal></entry>
785            <entry>This returns the stride length of <literal>i</literal>.</entry>
786          </row>
787          <row>
788            <entry><literal>i.get_start(idx)</literal></entry> 
789            <entry><literal>index</literal></entry>
790            <entry>If <literal>i</literal> specifies a start
791value, this is equivalent to <literal>i.start()</literal>. Otherwise it
792returns <literal>idx</literal>.</entry>
793          </row>
794          <row>
795            <entry><literal>i.get_finish(idx)</literal></entry>
796            <entry><literal>index</literal></entry>
797            <entry>If <literal>i</literal> specifies a finish
798value, this is equivalent to <literal>i.finish()</literal>. Otherwise it
799returns <literal>idx</literal>.</entry>
800          </row>
801          <row>
802            <entry><literal>i.size(idx)</literal></entry>
803            <entry><literal>size_type</literal></entry>
804            <entry>If <literal>i</literal> specifies a both finish and
805start values, this is equivalent to
806<literal>(i.finish()-i.start())/i.stride()</literal>. Otherwise it
807returns <literal>idx</literal>.</entry>
808          </row>
809          <row>
810            <entry><literal>i &lt; idx</literal></entry>
811            <entry><literal>index</literal></entry>
812            <entry>This is another syntax for specifying the finish
813value. This notation does not include
814<literal>idx</literal> in the range of valid indices. It is equivalent to
815<literal>index_range(r.start(), idx, r.stride())</literal></entry>
816          </row>
817          <row>
818            <entry><literal>i &lt;= idx</literal></entry>
819            <entry><literal>index</literal></entry>
820            <entry>This is another syntax for specifying the finish
821value. This notation includes
822<literal>idx</literal> in the range of valid indices. It is equivalent to
823<literal>index_range(r.start(), idx + 1, r.stride())</literal></entry>
824          </row>
825          <row>
826            <entry><literal>idx &lt; i</literal></entry>
827            <entry><literal>index</literal></entry>
828            <entry>This is another syntax for specifying the start
829value. This notation does not include
830<literal>idx</literal> in the range of valid indices. It is equivalent to
831<literal>index_range(idx + 1, i.finish(), i.stride())</literal>.</entry>
832          </row>
833          <row>
834            <entry><literal>idx &lt;= i</literal></entry>
835            <entry><literal>index</literal></entry>
836            <entry>This is another syntax for specifying the start
837value. This notation includes
838<literal>idx1</literal> in the range of valid indices. It is equivalent to
839<literal>index_range(idx, i.finish(), i.stride())</literal>.</entry>
840          </row>
841          <row>
842            <entry><literal>i + idx</literal></entry>
843            <entry><literal>index</literal></entry>
844            <entry>This expression shifts the start and finish values
845of <literal>i</literal> up by <literal>idx</literal>. It is equivalent to
846<literal>index_range(r.start()+idx1, r.finish()+idx, r.stride())</literal></entry>
847          </row>
848          <row>
849            <entry><literal>i - idx</literal></entry>
850            <entry><literal>index</literal></entry>
851            <entry>This expression shifts the start and finish values
852of <literal>i</literal> up by <literal>idx</literal>. It is equivalent to
853<literal>index_range(r.start()-idx1, r.finish()-idx, r.stride())</literal></entry>
854          </row>
855        </tbody>
856      </tgroup>
857    </table>
858  </sect3>
859
860      <sect3 id="index_gen">
861        <title><literal>index_gen</literal></title>
862        <para> <literal>index_gen</literal> aggregates
863<literal>index_range</literal> objects in order to specify view
864parameters.  Chained calls to <literal>operator[]</literal> store
865range and dimension information used to
866instantiate a new view into a MultiArray.
867</para>
868        <table>
869          <title>Notation</title>
870          <tgroup cols="2">
871            <tbody>
872              <row>
873                <entry><literal>Dims,Ranges</literal></entry>
874                <entry>Unsigned integral values.</entry>
875              </row>
876              <row>
877                <entry><literal>x</literal></entry>
878                <entry>An object of type
879<literal>template gen_type&lt;Dims,Ranges&gt;::type</literal>.</entry>
880              </row>
881              <row>
882                <entry><literal>i</literal></entry>
883                <entry>An object of type
884<literal>index_range</literal>.</entry>
885              </row>
886              <row>
887                <entry><literal>idx</literal></entry>
888                <entry>Objects of type <literal>index</literal>.</entry>
889              </row>
890            </tbody>
891          </tgroup>
892        </table>
893       
894    <table><title>Associated Types</title>
895      <tgroup cols="2">
896        <thead>
897          <row>
898            <entry>Type</entry>
899            <entry>Description</entry>
900          </row>
901        </thead>
902        <tbody>
903          <row>
904            <entry><literal>index</literal></entry>
905            <entry>This is a signed integral type. It is used to
906specify degenerate dimensions.</entry>
907          </row>
908          <row>
909            <entry><literal>size_type</literal></entry>
910            <entry>This is an unsigned integral type. It is used to
911report the size of the range an <literal>index_range</literal> 
912represents.</entry>
913          </row>
914              <row>
915                <entry>
916<literal>template gen_type::&lt;Dims,Ranges&gt;::type</literal></entry>
917        <entry>This type generator names the result of
918<literal>Dims</literal> chained calls to
919<literal>index_gen::operator[]</literal>.  The
920<literal>Ranges</literal> parameter is determined by the number of
921degenerate ranges specified (i.e. calls to
922<literal>operator[](index)</literal>). Note that 
923<classname>index_gen</classname> and
924<classname>gen_type&lt;0,0&gt;::type</classname> are the same type.</entry>
925              </row>
926        </tbody>
927      </tgroup>
928    </table>
929   
930     
931
932
933    <table><title>Valid Expressions</title>
934      <tgroup cols="3">
935        <thead>
936          <row>
937            <entry>Expression</entry>
938            <entry>Return type</entry>
939            <entry>Semantics</entry>
940          </row>
941        </thead>
942        <tbody>
943          <row>
944            <entry><literal>index_gen()</literal></entry>
945            <entry><literal>gen_type&lt;0,0&gt;::type</literal></entry>
946            <entry>This constructs an <literal>index_gen</literal>
947object. This object can then be used to generate tuples of
948<literal>index_range</literal> values.</entry>
949          </row>
950
951              <row>
952                <entry><literal>x[i]</literal></entry>
953                <entry><literal>gen_type&lt;Dims+1,Ranges+1&gt;::type</literal>
954</entry>
955                <entry>Returns a new object containing all previous
956<classname>index_range</classname> objects in addition to
957<literal>i.</literal> Chained calls to
958<function>operator[]</function> are the means by which
959<classname>index_range</classname> objects are aggregated.</entry>
960              </row>
961              <row>
962                <entry><literal>x[idx]</literal></entry>
963                <entry><literal>gen_type&lt;Dims,Ranges&gt;::type</literal>
964</entry>
965        <entry>Returns a new object containing all previous
966<classname>index_range</classname> objects in addition to a degenerate
967range, <literal>index_range(idx,idx).</literal> Note that this is NOT
968equivalent to <literal>x[index_range(idx,idx)].</literal>, which will
969return an object of type
970<literal>gen_type&lt;Dims+1,Ranges+1&gt;::type</literal>.
971</entry>
972              </row>
973            </tbody>
974          </tgroup>
975        </table>
976      </sect3>
977     
978    </sect2>
979
980<sect2>
981<title>Models</title>
982
983    <itemizedlist>
984      <listitem> <literal>multi_array</literal> </listitem>
985      <listitem> <literal>multi_array_ref</literal> </listitem>
986      <listitem> <literal>const_multi_array_ref</literal> </listitem>
987      <listitem> 
988        <literal>template array_view&lt;Dims&gt;::type</literal> 
989      </listitem>
990      <listitem> 
991        <literal>template const_array_view&lt;Dims&gt;::type</literal> 
992      </listitem>
993      <listitem>
994        <literal>template subarray&lt;Dims&gt;::type</literal>
995      </listitem>
996      <listitem>
997        <literal>template const_subarray&lt;Dims&gt;::type</literal>
998      </listitem>
999    </itemizedlist>
1000</sect2>
1001
1002</sect1>
Note: See TracBrowser for help on using the repository browser.