Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Math Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

3.13 High Dimension Arrays

In previous sections, we saw how easy it is to create and manipulate one-dimensional arrays (vectors), two-dimensional arrays (matrices), three-dimensional arrays, and four-dimensional arrays. In this section, we describe some of the features for working with arrays of five, six, and even higher dimensions. These techniques can also be used to write code that can deal with arrays of arbitrary dimension. Combined with automatic type conversion from vectors and matrices to arrays, this allows you to write subroutines which can be used with vectors, matrices, and arrays.

First, here is a quick reminder of the most basic method for constructing a three-dimensional array:

Similarly, you can construct a four-dimensional array like this:

Beyond four dimensions, things become a little trickier. Rather than providing an infinite number of constructors like the ones for three-dimensional and four-dimensional arrays, we provide a constructor that takes an RWIntVec, a vector of integers, as a parameter. This is used to provide the sizes of the array in each dimension:

It is often useful to construct arrays of less than three dimensions as well. These are created using type conversion from vectors and matrices. For example:

Here A and v now provide alternative views of the same data. This constructor is often used to pass vectors and matrices to subroutines written to work on an arbitrary dimension array.

Subscripting individual elements from arrays is done by using an integer vector as the subscript:

Subscripting groups of elements from high dimension arrays is done using the slice() member function described in the SourcePro C++ API Reference Guide.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.