Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
valarray
classes:
gslice
gslice_array
indirect_array
mask_array
slice
slice_array
valarray
global functions:
abs
acos
asin
atan
atan2
cos
cosh
exp
log
log10
pow
sin
sinh
sqrt
tan
tanh
gslice
gslice::gslice
member functions:
gslice::size
gslice::start
gslice::stride


gslice

class
<valarray>
 class gslice;

Valarray generalized slice selector

This class represents a valarray generalized slice (multidimensional slice) selector. It does not contain any element - it only describes a selection of elements in a valarray to be used as an index in valarray::operator[] .

A valarray generalized slice is specified by a starting index, a set of sizes, and a set of strides. It produces a multidimensional combination of slice selections, where:

The starting index (start) is the index of the first element in the selection.
The size (size) is the number of elements selected in each dimension.
The stride (stride) is the separation between the elements that are selected (the size of each dimension).

For example, a gslice with:
start = 1
size = {2, 3}
stride = {7, 2}
would select:


                    [0][1][2][3][4][5][6][7][8][9][10][11][12][13]
start=1:                *
                        |
size=2, stride=7:       *--------------------*
                        |                    |
size=3, stride=2:       *-----*-----*        *------*------*
                        |     |     |        |      |      |
gslice:                 *     *     *        *      *      *
                    [0][1][2][3][4][5][6][7][8][9][10][11][12][13]

Members


Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// gslice example
#include <iostream>
#include <valarray>
using namespace std;
int main ()
{
  valarray<int> foo (14);
  for (int i=0; i<14; ++i) foo[i]=i;
  size_t start=1;
  size_t lengths[]= {2,3};
  size_t strides[]= {7,2};
  gslice mygslice (start,valarray<size_t>(lengths,2),valarray<size_t>(strides,2));
  valarray<int> bar = foo[mygslice];
  cout << "gslice: ";
  for (size_t n=0; n<bar.size(); n++)
	  cout << bar[n] << ' ';
  cout << endl;
  return 0;
}


Output

gslice: 1 3 5 8 10 12

See also