(in branch) added VectorValues::setZero() function

release/4.3a0
Richard Roberts 2011-12-13 22:49:37 +00:00
parent a56fe9572e
commit 2ef911b7e9
2 changed files with 11 additions and 3 deletions

View File

@ -39,7 +39,7 @@ VectorValues& VectorValues::operator=(const VectorValues& rhs) {
/* ************************************************************************* */
VectorValues VectorValues::Zero(const VectorValues& x) {
VectorValues cloned(SameStructure(x));
cloned.vector() = Vector::Zero(x.dim());
cloned.setZero();
return cloned;
}
@ -124,10 +124,15 @@ VectorValues VectorValues::SameStructure(const VectorValues& other) {
/* ************************************************************************* */
VectorValues VectorValues::Zero(Index nVars, size_t varDim) {
VectorValues ret(nVars, varDim);
ret.vector() = Vector::Zero(ret.dim());
ret.setZero();
return ret;
}
/* ************************************************************************* */
void VectorValues::setZero() {
values_.setZero();
}
/* ************************************************************************* */
bool VectorValues::hasSameStructure(const VectorValues& other) const {
if(this->size() != other.size())

View File

@ -238,6 +238,9 @@ namespace gtsam {
template<class CONTAINER>
void append(const CONTAINER& dimensions);
/** Set all entries to zero, does not modify the size. */
void setZero();
/** Reference the entire solution vector (const version). */
const Vector& vector() const { chk(); return values_; }
@ -383,7 +386,7 @@ namespace gtsam {
template<class CONTAINER>
VectorValues VectorValues::Zero(const CONTAINER& dimensions) {
VectorValues ret(dimensions);
ret.vector() = Vector::Zero(ret.dim());
ret.setZero();
return ret;
}