TVM  0.9.2
tvm::VariableVector Class Reference

#include <tvm/VariableVector.h>

Inheritance diagram for tvm::VariableVector:
Collaboration diagram for tvm::VariableVector:

Public Member Functions

 VariableVector ()
 
template<typename... VarPtr>
 VariableVector (VarPtr &&... variables)
 
 VariableVector (const VariableVector &other)
 
 VariableVector (VariableVector &&)=default
 
VariableVectoroperator= (const VariableVector &other)
 
VariableVectoroperator= (VariableVector &&)=default
 
 ~VariableVector ()
 
bool add (VariablePtr v)
 
bool add (std::unique_ptr< Variable > v)
 
void add (const std::vector< VariablePtr > &variables)
 
void add (const VariableVector &variables)
 
int addAndGetIndex (VariablePtr v, bool containingIndex=false)
 
bool remove (const Variable &v)
 
void remove (int i)
 
void clear ()
 
int totalSize () const
 
int numberOfVariables () const
 
const VariablePtr operator[] (int i) const
 
const std::vector< VariablePtr > & variables () const
 
const Eigen::VectorXd & value () const
 
TVM_DEPRECATED void value (const VectorConstRef &x)
 
void set (const VectorConstRef &val)
 
void setZero ()
 
bool contains (const Variable &v) const
 
bool intersects (const Variable &v) const
 
int indexOf (const Variable &v) const
 
Range getMappingOf (const Variable &v) const
 
int stamp () const
 
std::vector< VariablePtr >::const_iterator begin () const
 
std::vector< VariablePtr >::const_iterator end () const
 
- Public Member Functions inherited from tvm::internal::ObjWithId
 ObjWithId (const ObjWithId &)=delete
 
 ObjWithId (ObjWithId &&other)
 
ObjWithIdoperator= (const ObjWithId &)=delete
 
ObjWithIdoperator= (ObjWithId &&other)
 
int id () const
 

Additional Inherited Members

- Protected Member Functions inherited from tvm::internal::ObjWithId
 ObjWithId ()
 

Detailed Description

A vector of variables, with some useful manipulation/analysis functions.

One of the main use of this class is to determine variable mapping, i.e. given a vector aggregating all variables, which section of this vector would correspond to a given variable. There is two approaches for that: either build a map with computeMapping or use the method Variable::getMappingIn. The latter uses a cache in Variable in a way that if one invoke Variable::getMappingIn on any variable contained in a VariableVector, the mapping of all other contained variables will be computed and cached. For repeatedly querying the mapping of those variable w.r.t the same VariableVector, this is the fastest option. However it will be slow if querying alternatively mapping w.r.t different VariableVector on the same variable or set of variables.

A given variable can only appear once in a vector. Variables appear in the order they were added, ignoring duplicates.

FIXME would it make sense to derive from std::vector<std::shared_ptr<Variable>> ?

Constructor & Destructor Documentation

◆ VariableVector() [1/4]

tvm::VariableVector::VariableVector ( )

Construct an empty vector

◆ VariableVector() [2/4]

template<typename... VarPtr>
tvm::VariableVector::VariableVector ( VarPtr &&...  variables)

General construction

Template Parameters
Canbe any list from the following type:
  • VariablePtr
  • std::unique_ptr<Variable>
  • VariableVector
  • std::vector<VariablePtr>
Parameters
variablesA coma-separated list of instances of the above types. Variables will be added in the order they appear.

◆ VariableVector() [3/4]

tvm::VariableVector::VariableVector ( const VariableVector other)

Copy constructor

◆ VariableVector() [4/4]

tvm::VariableVector::VariableVector ( VariableVector &&  )
default

◆ ~VariableVector()

tvm::VariableVector::~VariableVector ( )

Member Function Documentation

◆ add() [1/4]

void tvm::VariableVector::add ( const std::vector< VariablePtr > &  variables)

Same as add(VariablePtr), but for adding a vector of variables.

◆ add() [2/4]

void tvm::VariableVector::add ( const VariableVector variables)

Same as add(VariablePtr), but for adding a vector of variables.

◆ add() [3/4]

bool tvm::VariableVector::add ( std::unique_ptr< Variable v)

Add a variable to the vector. This version is mostly to be used directly with the output of tvm::Space::createVariable.

Parameters
vThe variable to be added.
Returns
True if the variable was added, false otherwise

◆ add() [4/4]

bool tvm::VariableVector::add ( VariablePtr  v)

Add a variable to the vector if not already present.

Parameters
vThe variable to be added.
Returns
True if the variable was added, false otherwise.

\Note If the variable is only partially present (i.e. it intersects a a variable in the vector but is not contained by it), this function will throw. If you need to handle such a case, you should look at tvm::internal::VariableCountingVector.

◆ addAndGetIndex()

int tvm::VariableVector::addAndGetIndex ( VariablePtr  v,
bool  containingIndex = false 
)

Add a variable to the vector, if not already present, and return the index of the variable in the vector whether it was added or not.

Parameters
vThe variable to be added.
containingIndexSpecify what to return in case v is the subvariable of an already present variable. If false, return -1 in this case. If true, return the index of the variable containing v.
Returns
Index of variable v in the vector. If v is a subvariable of an already present variable, returns -1 or the index of the variable depending on containingIndex.

◆ begin()

std::vector< VariablePtr >::const_iterator tvm::VariableVector::begin ( ) const
inline

Iterator to the first variable. This enable to use VariableVector directly in range-based for loops

◆ clear()

void tvm::VariableVector::clear ( )

Clear the vector

◆ contains()

bool tvm::VariableVector::contains ( const Variable v) const

Check if this vector contains variable v or not.

◆ end()

std::vector< VariablePtr >::const_iterator tvm::VariableVector::end ( ) const
inline

Iterator past the last variable. This enable to use VariableVector directly in range-based for loops

◆ getMappingOf()

Range tvm::VariableVector::getMappingOf ( const Variable v) const

Return the mapping of v in this vector.

This is meant for when the mapping has not been cached, and will cache it. You should always prefer the use of Variable::getMappingIn.

◆ indexOf()

int tvm::VariableVector::indexOf ( const Variable v) const

Find the index of variable v in the vector. Returns -1 if v is not present.

◆ intersects()

bool tvm::VariableVector::intersects ( const Variable v) const

Check if any variable of this vector intersects with v

◆ numberOfVariables()

int tvm::VariableVector::numberOfVariables ( ) const

Number of variables

◆ operator=() [1/2]

VariableVector& tvm::VariableVector::operator= ( const VariableVector other)

◆ operator=() [2/2]

VariableVector& tvm::VariableVector::operator= ( VariableVector &&  )
default

◆ operator[]()

const VariablePtr tvm::VariableVector::operator[] ( int  i) const

Element-wise access

◆ remove() [1/2]

bool tvm::VariableVector::remove ( const Variable v)

Remove a variable from the vector, if present.

Parameters
vthe variable to be removed.
Returns
True if the variable was removed, false otherwise.
Warning
You can only remove a variable logically equal to one present in the vector. Trying to remove a subpart of a variable in the vector will not remove anything, and return false.

◆ remove() [2/2]

void tvm::VariableVector::remove ( int  i)

Remove the variable with the given index.

Parameters
iIndex of the variable to be removed.
Exceptions
std::out_of_rangeif i is smaller than 0 or greater than the number of variables.

◆ set()

void tvm::VariableVector::set ( const VectorConstRef val)

Set the value of all variables from a concatenated vector

Parameters
valThe concatenated value of all the variables, in the order of the variables as given by variables().

◆ setZero()

void tvm::VariableVector::setZero ( )

Set the value of all variables to 0.

◆ stamp()

int tvm::VariableVector::stamp ( ) const

A timestamp, used internally to determine if a cached mapping needs to be recomputed or not.

◆ totalSize()

int tvm::VariableVector::totalSize ( ) const

Sum of the sizes of all the variables.

◆ value() [1/2]

const Eigen::VectorXd& tvm::VariableVector::value ( ) const

Get the concatenation of all variables' value, in the order of the variables as given by variables().

◆ value() [2/2]

TVM_DEPRECATED void tvm::VariableVector::value ( const VectorConstRef x)
inline

(DEPRECATED) Set the value of all variables from a concatenated vector

Parameters
valThe concatenated value of all the variables, in the order of the variables as given by variables().

◆ variables()

const std::vector<VariablePtr>& tvm::VariableVector::variables ( ) const

whole vector access


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