combine replaced

release/4.3a0
kartik arcot 2023-01-19 10:47:45 -08:00
parent d1d5336ed0
commit ccc5e3881b
1 changed files with 19 additions and 17 deletions

View File

@ -19,7 +19,6 @@
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <boost/bind/bind.hpp> #include <boost/bind/bind.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/numeric.hpp> #include <boost/range/numeric.hpp>
#include <boost/range/adaptor/transformed.hpp> #include <boost/range/adaptor/transformed.hpp>
#include <boost/range/adaptor/map.hpp> #include <boost/range/adaptor/map.hpp>
@ -28,7 +27,6 @@ using namespace std;
namespace gtsam { namespace gtsam {
using boost::combine;
using boost::adaptors::transformed; using boost::adaptors::transformed;
using boost::adaptors::map_values; using boost::adaptors::map_values;
using boost::accumulate; using boost::accumulate;
@ -166,9 +164,11 @@ namespace gtsam {
bool VectorValues::equals(const VectorValues& x, double tol) const { bool VectorValues::equals(const VectorValues& x, double tol) const {
if(this->size() != x.size()) if(this->size() != x.size())
return false; return false;
for(const auto values: boost::combine(*this, x)) { auto this_it = this->begin();
if(values.get<0>().first != values.get<1>().first || auto x_it = x.begin();
!equal_with_abs_tol(values.get<0>().second, values.get<1>().second, tol)) for(; this_it != this->end(); ++this_it, ++x_it) {
if(this_it->first != x_it->first ||
!equal_with_abs_tol(this_it->second, x_it->second, tol))
return false; return false;
} }
return true; return true;
@ -215,19 +215,19 @@ namespace gtsam {
/* ************************************************************************ */ /* ************************************************************************ */
namespace internal namespace internal
{ {
bool structureCompareOp(const std::tuple<VectorValues::value_type, bool structureCompareOp(const VectorValues::value_type& a, const VectorValues::value_type& b)
VectorValues::value_type>& vv)
{ {
return std::get<0>(vv).first == std::get<1>(vv).first return a.first == b.first && a.second.size() == b.second.size();
&& std::get<0>(vv).second.size() == std::get<1>(vv).second.size();
} }
} }
/* ************************************************************************ */ /* ************************************************************************ */
bool VectorValues::hasSameStructure(const VectorValues other) const bool VectorValues::hasSameStructure(const VectorValues other) const
{ {
return accumulate(combine(*this, other) // compare the "other" container with this one, using the structureCompareOp
| transformed(internal::structureCompareOp), true, logical_and<bool>()); // and then return true if all elements are compared as equal
return std::equal(this->begin(), this->end(), other.begin(), other.end(),
internal::structureCompareOp);
} }
/* ************************************************************************ */ /* ************************************************************************ */
@ -238,12 +238,14 @@ namespace gtsam {
double result = 0.0; double result = 0.0;
typedef std::tuple<value_type, value_type> ValuePair; typedef std::tuple<value_type, value_type> ValuePair;
using boost::adaptors::map_values; using boost::adaptors::map_values;
for(const ValuePair values: boost::combine(*this, v)) { auto this_it = this->begin();
assert_throw(values.get<0>().first == values.get<1>().first, auto v_it = v.begin();
invalid_argument("VectorValues::dot called with a VectorValues of different structure")); for(; this_it != this->end(); ++this_it, ++v_it) {
assert_throw(values.get<0>().second.size() == values.get<1>().second.size(), assert_throw(this_it->first == v_it->first,
invalid_argument("VectorValues::dot called with a VectorValues of different structure")); invalid_argument("VectorValues::dot called with a VectorValues of different structure"));
result += values.get<0>().second.dot(values.get<1>().second); assert_throw(this_it->second.size() == v_it->second.size(),
invalid_argument("VectorValues::dot called with a VectorValues of different structure"));
result += this_it->second.dot(v_it->second);
} }
return result; return result;
} }