gslice man page on OpenIndiana

Man page or keyword search:  
man Server   20441 pages
apropos Keyword Search (all sections)
Output format
OpenIndiana logo
[printable version]

gslice(3C++)			       -			  gslice(3C++)

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

NAME
       gslice

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

SYNOPSIS
       #include <valarray>
       class gslice ;

DESCRIPTION
       gslice_represents a generalized slice  from  an	array.	A  generalized
       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
       dimensional  valarray. The gslice maps a set of n indices (ij), where n
       is equal to the number of strides, to a single index k.

       When applied to a valarray using the  gslice  subscript	operator  (see
       valarray) a gslice produces a gslice_array. The gslice_array class cre‐
       ates a view into the original valarray that is tailored to match param‐
       eters  of  the gslice. The elements in a gslice_array are references to
       the elements in the original array.

INTERFACE
       class gslice {
       public:
  // constructors
 gslice();
 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;
};

CONSTRUCTORS
       gslice();

   Default constructor creates a gslice specifying no elements.

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.

ACCESSORS
       size_t start();

   Returns the starting index of the gslice.

valarraysize_t> size();

   Returns a valarray<size_t> containing the lengths of the gslice.

Valarray<;size_t> stride();

   Returns a valarray<size_t> containing the strides of the gslice.

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

       int main(void)
       {
 int ibuf[27] =
   {0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10};
 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

[0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10]
[0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10]
[1,2,3,4,5,6,7,8,9]
[3,4,5,4,5,6,5,6,7]
[1,2,3,4,5,6,7,8,9]
[0,2,4,3,5,7,6,8,10]

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

SEE ALSO
       valarray, slice_array, slice, gslice_array, mask_array, indirect_array

Rogue Wave Software		  02 Apr 1998			  gslice(3C++)
[top]

List of man pages available for OpenIndiana

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net