Added dims() and swap() functions to VectorValues

release/4.3a0
Richard Roberts 2012-06-30 19:18:02 +00:00
parent abd6795f5b
commit ad53c20b0d
2 changed files with 22 additions and 0 deletions

View File

@ -45,6 +45,14 @@ VectorValues VectorValues::Zero(const VectorValues& x) {
return cloned;
}
/* ************************************************************************* */
vector<size_t> VectorValues::dims() const {
std::vector<size_t> result(this->size());
for(Index j = 0; j < this->size(); ++j)
result[j] = this->dim(j);
return result;
}
/* ************************************************************************* */
void VectorValues::insert(Index j, const Vector& value) {
// Make sure j does not already exist
@ -188,4 +196,10 @@ VectorValues VectorValues::permute(const Permutation& permutation) const {
return lhs;
}
/* ************************************************************************* */
void VectorValues::swap(VectorValues& other) {
this->values_.swap(other.values_);
this->maps_.swap(other.maps_);
}
}

View File

@ -134,6 +134,9 @@ namespace gtsam {
/** Return the summed dimensionality of all variables. */
size_t dim() const { return values_.rows(); }
/** Return the dimension of each vector in this container */
std::vector<size_t> dims() const;
/** Check whether a variable with index \c j exists. */
bool exists(Index j) const { return j < size() && maps_[j].rows() > 0; }
@ -296,6 +299,11 @@ namespace gtsam {
*/
VectorValues permute(const Permutation& permutation) const;
/**
* Swap the data in this VectorValues with another.
*/
void swap(VectorValues& other);
/// @}
private: