Errors is now a list
parent
f80ac5d7d5
commit
793a9d58ae
|
@ -16,19 +16,22 @@ namespace gtsam {
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void Errors::print(const std::string& s) const {
|
void Errors::print(const std::string& s) const {
|
||||||
odprintf("%s:\n", s.c_str());
|
odprintf("%s:\n", s.c_str());
|
||||||
for (size_t i=0;i<size();i++) {
|
BOOST_FOREACH(const Vector& v, *this)
|
||||||
odprintf("%d:", i);
|
gtsam::print(v);
|
||||||
gtsam::print((*this)[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
struct equalsVector : public std::binary_function<const Vector&, const Vector&, bool> {
|
||||||
|
double tol_;
|
||||||
|
equalsVector(double tol = 1e-9) : tol_(tol) {}
|
||||||
|
bool operator()(const Vector& expected, const Vector& actual) {
|
||||||
|
return equal_with_abs_tol(expected, actual,tol_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
bool Errors::equals(const Errors& expected, double tol) const {
|
bool Errors::equals(const Errors& expected, double tol) const {
|
||||||
if( size() != expected.size() ) return false;
|
if( size() != expected.size() ) return false;
|
||||||
for (size_t i=0;i<size();i++)
|
return equal(begin(),end(),expected.begin(),equalsVector(tol));
|
||||||
if(!equal_with_abs_tol(expected[i],(*this)[i],tol))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -37,8 +40,9 @@ double dot(const Errors& a, const Errors& b) {
|
||||||
if (b.size()!=m)
|
if (b.size()!=m)
|
||||||
throw(std::invalid_argument("Errors::dot: incompatible sizes"));
|
throw(std::invalid_argument("Errors::dot: incompatible sizes"));
|
||||||
double result = 0.0;
|
double result = 0.0;
|
||||||
for (size_t i = 0; i < m; i++)
|
Errors::const_iterator it = b.begin();
|
||||||
result += gtsam::dot(a[i], b[i]);
|
BOOST_FOREACH(const Vector& ai, a)
|
||||||
|
result += gtsam::dot(ai, *(it++));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/** vector of errors */
|
/** vector of errors */
|
||||||
class Errors : public std::vector<Vector>, public Testable<Errors> {
|
class Errors : public std::list<Vector>, public Testable<Errors> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,9 @@ Errors GaussianFactorGraph::operator*(const VectorConfig& x) const {
|
||||||
VectorConfig GaussianFactorGraph::operator^(const Errors& e) const {
|
VectorConfig GaussianFactorGraph::operator^(const Errors& e) const {
|
||||||
VectorConfig x;
|
VectorConfig x;
|
||||||
// For each factor add the gradient contribution
|
// For each factor add the gradient contribution
|
||||||
size_t i=0;
|
Errors::const_iterator it = e.begin();
|
||||||
BOOST_FOREACH(sharedFactor Ai,factors_)
|
BOOST_FOREACH(sharedFactor Ai,factors_)
|
||||||
x += (*Ai)^e[i++];
|
x += (*Ai)^(*(it++));
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue