MUQ  0.4.3
muq::Utilities::VectorSlice< VecType, ScalarType > Class Template Reference

Enables a subset of a vector to be easily accessed or reversed without copying memory. More...

#include <VectorSlice.h>

Detailed Description

template<typename VecType, typename ScalarType>
class muq::Utilities::VectorSlice< VecType, ScalarType >

Enables a subset of a vector to be easily accessed or reversed without copying memory.

Given a vector v, this class provides a way for defining slices of the vector of the form v[startInd:endInd:skip] (in python notation).

This class is designed for use with the std::vector and Eigen::VectorXd classes, but can work with any type that exposes the [] operator and has a size() function, which includes other VectorViews.

IMPORTANT: This class does not copy data, so segfaults could occur if the underlying vector goes out of scope before the view is destructed.

Definition at line 24 of file VectorSlice.h.

Public Member Functions

 VectorSlice (VectorSlice< VecType, ScalarType > const &vec)
 
VectorSlice< VecType, ScalarType > & operator= (VectorSlice< VecType, ScalarType > const &vec)
 
 VectorSlice (VecType &dataIn, int startIndIn, int endIndIn, int skipIn=1)
 
ScalarType & operator() (int i)
 
ScalarType operator() (int i) const
 
ScalarType & operator[] (int i)
 
ScalarType operator[] (int i) const
 
unsigned int size () const
 
void CheckBounds (int i) const
 

Public Attributes

VecType & data
 
int startInd
 
int endInd
 
int skip
 

Constructor & Destructor Documentation

◆ VectorSlice() [1/2]

template<typename VecType , typename ScalarType >
muq::Utilities::VectorSlice< VecType, ScalarType >::VectorSlice ( VectorSlice< VecType, ScalarType > const &  vec)
inline

Definition at line 28 of file VectorSlice.h.

◆ VectorSlice() [2/2]

template<typename VecType , typename ScalarType >
muq::Utilities::VectorSlice< VecType, ScalarType >::VectorSlice ( VecType &  dataIn,
int  startIndIn,
int  endIndIn,
int  skipIn = 1 
)
inline

Construct the view with a reference to vector of doubles. Note that endInd-startInd should have the same size as skip. Thus, reversing the order of std::vector would be accomplished with

std::vector v{1,2,3,4};
VectorSlice vRev(v, v.size()-1,-1, -1);
VectorSlice(VectorSlice< VecType, ScalarType > const &vec)
Definition: VectorSlice.h:28
int int diyfp diyfp v
Definition: json.h:15163

Note that the second argument, endInd, is negative because the end index is not inclusive. Thus, endInd must be -1 to capture v[0].

Parameters
[in]dataInThe base vector that we want to slice.
[in]startIndInnon-negative integer specifying the starting index in the data vector
[in]endIndInnon-negative integer specifying the ending index in the data vector. Numpy indexing rules are followed, so this index is not-inclusive. @parm[in] skip. The number of

Definition at line 53 of file VectorSlice.h.

References muq::Utilities::VectorSlice< VecType, ScalarType >::endInd, muq::Utilities::VectorSlice< VecType, ScalarType >::skip, and muq::Utilities::VectorSlice< VecType, ScalarType >::startInd.

Member Function Documentation

◆ CheckBounds()

◆ operator()() [1/2]

◆ operator()() [2/2]

◆ operator=()

template<typename VecType , typename ScalarType >
VectorSlice<VecType, ScalarType>& muq::Utilities::VectorSlice< VecType, ScalarType >::operator= ( VectorSlice< VecType, ScalarType > const &  vec)
inline

◆ operator[]() [1/2]

template<typename VecType , typename ScalarType >
ScalarType& muq::Utilities::VectorSlice< VecType, ScalarType >::operator[] ( int  i)
inline

◆ operator[]() [2/2]

template<typename VecType , typename ScalarType >
ScalarType muq::Utilities::VectorSlice< VecType, ScalarType >::operator[] ( int  i) const
inline

◆ size()

template<typename VecType , typename ScalarType >
unsigned int muq::Utilities::VectorSlice< VecType, ScalarType >::size ( ) const
inline

Member Data Documentation

◆ data

◆ endInd

◆ skip

◆ startInd


The documentation for this class was generated from the following file: