TVM
0.9.2
|
#include <tvm/VariableVector.h>
Public Member Functions | |
VariableVector () | |
template<typename... VarPtr> | |
VariableVector (VarPtr &&... variables) | |
VariableVector (const VariableVector &other) | |
VariableVector (VariableVector &&)=default | |
VariableVector & | operator= (const VariableVector &other) |
VariableVector & | operator= (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) | |
ObjWithId & | operator= (const ObjWithId &)=delete |
ObjWithId & | operator= (ObjWithId &&other) |
int | id () const |
Additional Inherited Members | |
Protected Member Functions inherited from tvm::internal::ObjWithId | |
ObjWithId () | |
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>> ?
tvm::VariableVector::VariableVector | ( | ) |
Construct an empty vector
tvm::VariableVector::VariableVector | ( | VarPtr &&... | variables | ) |
General construction
Can | be any list from the following type:
|
variables | A coma-separated list of instances of the above types. Variables will be added in the order they appear. |
tvm::VariableVector::VariableVector | ( | const VariableVector & | other | ) |
Copy constructor
|
default |
tvm::VariableVector::~VariableVector | ( | ) |
void tvm::VariableVector::add | ( | const std::vector< VariablePtr > & | variables | ) |
Same as add(VariablePtr), but for adding a vector of variables.
void tvm::VariableVector::add | ( | const VariableVector & | variables | ) |
Same as add(VariablePtr), but for adding a vector of variables.
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.
v | The variable to be added. |
bool tvm::VariableVector::add | ( | VariablePtr | v | ) |
Add a variable to the vector if not already present.
v | The variable to be added. |
\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.
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.
v | The variable to be added. |
containingIndex | Specify 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 . |
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
.
|
inline |
Iterator to the first variable. This enable to use VariableVector directly in range-based for loops
void tvm::VariableVector::clear | ( | ) |
Clear the vector
bool tvm::VariableVector::contains | ( | const Variable & | v | ) | const |
Check if this vector contains variable v
or not.
|
inline |
Iterator past the last variable. This enable to use VariableVector directly in range-based for loops
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.
int tvm::VariableVector::indexOf | ( | const Variable & | v | ) | const |
Find the index of variable v
in the vector. Returns -1 if v
is not present.
bool tvm::VariableVector::intersects | ( | const Variable & | v | ) | const |
Check if any variable of this vector intersects with v
int tvm::VariableVector::numberOfVariables | ( | ) | const |
Number of variables
VariableVector& tvm::VariableVector::operator= | ( | const VariableVector & | other | ) |
|
default |
const VariablePtr tvm::VariableVector::operator[] | ( | int | i | ) | const |
Element-wise access
bool tvm::VariableVector::remove | ( | const Variable & | v | ) |
Remove a variable from the vector, if present.
v | the variable to be removed. |
false
. void tvm::VariableVector::remove | ( | int | i | ) |
Remove the variable with the given index.
i | Index of the variable to be removed. |
std::out_of_range | if i is smaller than 0 or greater than the number of variables. |
void tvm::VariableVector::set | ( | const VectorConstRef & | val | ) |
Set the value of all variables from a concatenated vector
val | The concatenated value of all the variables, in the order of the variables as given by variables(). |
void tvm::VariableVector::setZero | ( | ) |
Set the value of all variables to 0.
int tvm::VariableVector::stamp | ( | ) | const |
A timestamp, used internally to determine if a cached mapping needs to be recomputed or not.
int tvm::VariableVector::totalSize | ( | ) | const |
Sum of the sizes of all the variables.
const Eigen::VectorXd& tvm::VariableVector::value | ( | ) | const |
Get the concatenation of all variables' value, in the order of the variables as given by variables().
|
inline |
(DEPRECATED) Set the value of all variables from a concatenated vector
val | The concatenated value of all the variables, in the order of the variables as given by variables(). |
const std::vector<VariablePtr>& tvm::VariableVector::variables | ( | ) | const |
whole vector access