| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file    Errors.cpp | 
					
						
							|  |  |  |  * @brief   Factor Graph Configuration | 
					
						
							|  |  |  |  * @brief   Errors | 
					
						
							|  |  |  |  * @author  Carlos Nieto | 
					
						
							|  |  |  |  * @author  Christian Potthast | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-31 18:27:16 +08:00
										 |  |  | #include <boost/bind.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | #include "Errors.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void Errors::print(const std::string& s) const { | 
					
						
							|  |  |  |   odprintf("%s:\n", s.c_str()); | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:36 +08:00
										 |  |  |   BOOST_FOREACH(const Vector& v, *this) | 
					
						
							|  |  |  |     gtsam::print(v); | 
					
						
							| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:36 +08:00
										 |  |  | 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_); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | bool Errors::equals(const Errors& expected, double tol) const { | 
					
						
							| 
									
										
										
										
											2009-12-31 18:27:16 +08:00
										 |  |  | 	if( size() != expected.size() ) return false; | 
					
						
							|  |  |  | 	return equal(begin(),end(),expected.begin(),equalsVector(tol)); | 
					
						
							|  |  |  | 	// TODO: use boost::bind(&equal_with_abs_tol,_1, _2,tol)
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | Errors Errors::operator-(const Errors& b) const { | 
					
						
							|  |  |  | 	size_t m = size(); | 
					
						
							|  |  |  |   if (b.size()!=m) | 
					
						
							|  |  |  |     throw(std::invalid_argument("Errors::operator-: incompatible sizes")); | 
					
						
							|  |  |  | 	Errors result; | 
					
						
							|  |  |  | 	Errors::const_iterator it = b.begin(); | 
					
						
							|  |  |  |   BOOST_FOREACH(const Vector& ai, *this) | 
					
						
							|  |  |  | 		result.push_back(ai - *(it++)); | 
					
						
							|  |  |  | 	return result; | 
					
						
							| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-28 16:15:09 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | double dot(const Errors& a, const Errors& b) { | 
					
						
							|  |  |  | 	size_t m = a.size(); | 
					
						
							|  |  |  |   if (b.size()!=m) | 
					
						
							|  |  |  |     throw(std::invalid_argument("Errors::dot: incompatible sizes")); | 
					
						
							|  |  |  | 	double result = 0.0; | 
					
						
							| 
									
										
										
										
											2009-12-31 01:13:36 +08:00
										 |  |  | 	Errors::const_iterator it = b.begin(); | 
					
						
							|  |  |  |   BOOST_FOREACH(const Vector& ai, a) | 
					
						
							|  |  |  | 		result += gtsam::dot(ai, *(it++)); | 
					
						
							| 
									
										
										
										
											2009-12-28 16:15:09 +08:00
										 |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 16:32:59 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void print(const Errors& a, const string& s) { | 
					
						
							|  |  |  | 	a.print(s); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-27 06:48:41 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // gtsam
 |