std::gslice (3) - Linux Manuals
std::gslice: std::gslice
NAME
Synopsis
Defined in header <valarray>
class gslice;
std::gslice is the selector class that identifies a subset of std::valarray indices defined by a multi-level set of strides and sizes. Objects of type std::gslice can be used as indices with valarray's operator[] to select, for example, columns of a multidimensional array represented as a valarray.
Given the starting value s, a list of strides i
j and a list of sizes d
j, a std::gslice constructed from these values selects the set of indices k
j=s+Σ
j(i
jd
j).
For example, a gslice with starting index 3, strides {19,4,1} and lengths {2,4,3} generates the following set of indices:
3 + 0*19 + 0*4 + 0*1 = 3,
3 + 0*19 + 0*4 + 1*1 = 4,
3 + 0*19 + 0*4 + 2*1 = 5,
3 + 0*19 + 1*4 + 0*1 = 7,
3 + 0*19 + 1*4 + 1*1 = 8,
...
3 + 1*19 + 3*4 + 2*1 = 36
It is possible to construct std::gslice objects that select some indices more than once: if the above example used the strides {1,1,1}, the indices would have been {3, 4, 5, 4, 5, 6, ...}. Such gslices may only be used as arguments to the const version of std::valarray::operator[], otherwise the behavior is undefined.
Member functions
constructor (public member function)
start returns the parameters of the slice
size (public member function)
stride
std::gslice::gslice
gslice()
gslice( std::size_t start, const std::valarray<std::size_t>& sizes,
const std::valarray<std::size_t>& strides );
gslice( const gslice& other );
Constructs a new generic slice.
1) Default constructor. Equivalent to gslice(0, std::valarray<std::size_t>(), std::valarray<std::size_t>()). This constructor exists only to allow construction of arrays of slices.
2) Constructs a new slice with parameters start, sizes, strides.
3) Constructs a copy of other.
Parameters
start - the position of the first element
sizes - an array that defines the number of elements in each dimension
strides - an array that defines the number of positions between successive elements in each dimension
other - another slice to copy
std::slice::start, size, stride
std::size_t start() const; (1)
std::valarray<std::size_t> size() const; (2)
std::valarray<std::size_t> stride() const; (3)
Returns the parameters passed to the slice on construction - start, sizes and strides respectively.
Parameters
(none)
Return value
The parameters of the slice -- start, sizes and strides respectively.
Complexity
Constant.
Example
demonstrates the use of gslices to address columns of a 3D array
// Run this code
Output:
See also
operator[] (public member function)