Man Page gslice.3

                       Standard C++ Library
             Copyright 1998, Rogue Wave Software, Inc.



      - A numeric array class used  to  represent  a  generalized
     slice from an array.


     #include <valarray>
     class gslice ;


     gslice_represents a generalized slice from an array. A  gen-
     eralized  slice  contains a starting index, a set of lengths
     and a set of strides. The number of lengths and strides must
     be  equal.  Together  the  lengths and strides allow a slice
     from a multiple dimension array (with the dimension equal to
     the  number  of  strides)  to be represented on a one dimen-
     sional valarray. The gslice maps a set of  n  indices  (ij),
     where n is equal to the number of strides, to a single index

     When applied to a valarray using the gslice subscript opera-
     tor  (see  valarray)  a  gslice produces a gslice_array. The
     gslice_array class creates a view into the original valarray
     that is tailored to match parameters of the gslice. The ele-
     ments in a gslice_array are references to  the  elements  in
     the original array.


     class gslice {
       // constructors
      gslice(size_t, const valarray<size_t>&,
             const valarray<size_t>&);
      gslice (const gslice&);

       // Accessors
      size_t start() const;
      valarray<size_t> size() const;
      valarray<size_t> stride() const;



        Default constructor creates a gslice specifying  no  ele-

     gslice(size_t start, const valarray<size_t>& length,
           const valarray<size_t>& stride);

        Creates a slice with starting index, length and stride as
        indicated by the arguments.

     gslice(const gslice&)

        Creates a slice with starting index, length and stride as
        indicated by the slice argument.


     size_t start();

        Returns the starting index of the gslice.

     valarraysize_t> size();

        Returns a valarray<size_t> containing the lengths of  the

     Valarray<size_t> stride();
        Returns a valarray<size_t> containing the strides of  the


     // gslice.cpp
     #include "valarray.h" // Contains a valarray stream inserter
     using namespace std;

     int main(void)
      int ibuf[27] =
      size_t len_buf[3] = {3,3,3};
      size_t stride_buf[3] = {9,3,1};

       // create a valarray of ints
      valarray<int>  vi(ibuf,27);

       // create length and stride valarrays
      valarray<size_t> len(len_buf,3);
      valarray<size_t> stride(stride_buf,3);

       // print out the valarray
      cout << vi << endl;

       // Print out all three dimensions (the entire valarray)
      cout << valarray<int>(vi[gslice(0,len,stride)]) << endl;

       // Print a two dimensional slice out of the middle
      valarray<size_t> len2(2);
      len2[0] = 3;
      len2[1] = 3;
      valarray<size_t> stride2(2);
      stride2[0] = 3;
      stride2[1] = 1;
      cout << valarray<int>(vi[gslice(9,len2,stride2)]) << endl;

       // Print another two dimensional slice out of the middle
       // but orthogonal to one we just did
      stride2[0] = 9;
      stride2[1] = 1;
      cout << valarray<int>(vi[gslice(3,len2,stride2)]) << endl;

       // Print out the last plane in the middle,
       // (orthogonal to both of the previous ones)
      stride2[0] = 3;
      stride2[1] = 9;
      cout << valarray<int>(vi[gslice(1,len2,stride2)]) << endl;

       // Now how about a diagonal slice?
       // upper left front to lower right back
      stride2[0] = 3;
      stride2[1] = 10;
      cout << valarray<int>(vi[gslice(0,len2,stride2)]) << endl;

      return 0;

     Program Output



     If your compiler does not support namespaces,  then  you  do
     not need the using declaration for std.


     valarray,  slice_array,  slice,  gslice_array,   mask_array,