class
std::gslice
<valarray>
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
- (constructor)
- gslice constructor (public member function)
- gslice::start
- Return start of gslice (public member function)
- gslice::size
- Return sizes of gslice (public member function)
- gslice::stride
- Return strides of gslice (public member function)
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
See also
- slice
- Valarray slice selector (class)
- gslice_array
- Valarray gslice selection (class template)