rename comparator to compare and capture tol in the function lambda.
# Conflicts: # gtsam/hybrid/DCMixtureFactor.hrelease/4.3a0
parent
26c48a8c1f
commit
731cff746b
|
|
@ -141,10 +141,10 @@ namespace gtsam {
|
||||||
/// Equality method customized to node type `double`.
|
/// Equality method customized to node type `double`.
|
||||||
bool equals(const AlgebraicDecisionTree& other, double tol = 1e-9) const {
|
bool equals(const AlgebraicDecisionTree& other, double tol = 1e-9) const {
|
||||||
// lambda for comparison of two doubles upto some tolerance.
|
// lambda for comparison of two doubles upto some tolerance.
|
||||||
auto comparator = [](double a, double b, double tol) {
|
auto compare = [tol](double a, double b) {
|
||||||
return std::abs(a - b) < tol;
|
return std::abs(a - b) < tol;
|
||||||
};
|
};
|
||||||
return this->root_->equals(*other.root_, tol, comparator);
|
return this->root_->equals(*other.root_, tol, compare);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// AlgebraicDecisionTree
|
// AlgebraicDecisionTree
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,10 @@ namespace gtsam {
|
||||||
|
|
||||||
/** equality up to tolerance */
|
/** equality up to tolerance */
|
||||||
bool equals(const Node& q, double tol,
|
bool equals(const Node& q, double tol,
|
||||||
const ComparatorFunc& comparator) const override {
|
const CompareFunc& compare) const override {
|
||||||
const Leaf* other = dynamic_cast<const Leaf*>(&q);
|
const Leaf* other = dynamic_cast<const Leaf*>(&q);
|
||||||
if (!other) return false;
|
if (!other) return false;
|
||||||
return comparator(this->constant_, other->constant_, tol);
|
return compare(this->constant_, other->constant_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** print */
|
/** print */
|
||||||
|
|
@ -282,14 +282,14 @@ namespace gtsam {
|
||||||
|
|
||||||
/** equality up to tolerance */
|
/** equality up to tolerance */
|
||||||
bool equals(const Node& q, double tol,
|
bool equals(const Node& q, double tol,
|
||||||
const ComparatorFunc& comparator) const override {
|
const CompareFunc& compare) const override {
|
||||||
const Choice* other = dynamic_cast<const Choice*>(&q);
|
const Choice* other = dynamic_cast<const Choice*>(&q);
|
||||||
if (!other) return false;
|
if (!other) return false;
|
||||||
if (this->label_ != other->label_) return false;
|
if (this->label_ != other->label_) return false;
|
||||||
if (branches_.size() != other->branches_.size()) return false;
|
if (branches_.size() != other->branches_.size()) return false;
|
||||||
// we don't care about shared pointers being equal here
|
// we don't care about shared pointers being equal here
|
||||||
for (size_t i = 0; i < branches_.size(); i++)
|
for (size_t i = 0; i < branches_.size(); i++)
|
||||||
if (!(branches_[i]->equals(*(other->branches_[i]), tol, comparator)))
|
if (!(branches_[i]->equals(*(other->branches_[i]), tol, compare)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -649,8 +649,8 @@ namespace gtsam {
|
||||||
/*********************************************************************************/
|
/*********************************************************************************/
|
||||||
template <typename L, typename Y>
|
template <typename L, typename Y>
|
||||||
bool DecisionTree<L, Y>::equals(const DecisionTree& other, double tol,
|
bool DecisionTree<L, Y>::equals(const DecisionTree& other, double tol,
|
||||||
const ComparatorFunc& comparator) const {
|
const CompareFunc& compare) const {
|
||||||
return root_->equals(*other.root_, tol, comparator);
|
return root_->equals(*other.root_, tol, compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename L, typename Y>
|
template <typename L, typename Y>
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,14 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default method for comparison of two objects of type Y.
|
/// Default method for comparison of two objects of type Y.
|
||||||
static bool DefaultComparator(const Y& a, const Y& b, double tol) {
|
static bool DefaultCompare(const Y& a, const Y& b) {
|
||||||
return a == b;
|
return a == b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using FormatterFunc = std::function<std::string(L)>;
|
using FormatterFunc = std::function<std::string(L)>;
|
||||||
using ComparatorFunc = std::function<bool(const Y&, const Y&, double)>;
|
using CompareFunc = std::function<bool(const Y&, const Y&)>;
|
||||||
|
|
||||||
/** Handy typedefs for unary and binary function types */
|
/** Handy typedefs for unary and binary function types */
|
||||||
typedef std::function<Y(const Y&)> Unary;
|
typedef std::function<Y(const Y&)> Unary;
|
||||||
|
|
@ -102,7 +102,7 @@ namespace gtsam {
|
||||||
virtual bool sameLeaf(const Node& q) const = 0;
|
virtual bool sameLeaf(const Node& q) const = 0;
|
||||||
virtual bool equals(
|
virtual bool equals(
|
||||||
const Node& other, double tol = 1e-9,
|
const Node& other, double tol = 1e-9,
|
||||||
const ComparatorFunc& comparator = &DefaultComparator) const = 0;
|
const CompareFunc& compare = &DefaultCompare) const = 0;
|
||||||
virtual const Y& operator()(const Assignment<L>& x) const = 0;
|
virtual const Y& operator()(const Assignment<L>& x) const = 0;
|
||||||
virtual Ptr apply(const Unary& op) const = 0;
|
virtual Ptr apply(const Unary& op) const = 0;
|
||||||
virtual Ptr apply_f_op_g(const Node&, const Binary&) const = 0;
|
virtual Ptr apply_f_op_g(const Node&, const Binary&) const = 0;
|
||||||
|
|
@ -188,7 +188,7 @@ namespace gtsam {
|
||||||
|
|
||||||
// Testable
|
// Testable
|
||||||
bool equals(const DecisionTree& other, double tol = 1e-9,
|
bool equals(const DecisionTree& other, double tol = 1e-9,
|
||||||
const ComparatorFunc& comparator = &DefaultComparator) const;
|
const CompareFunc& compare = &DefaultCompare) const;
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name Standard Interface
|
/// @name Standard Interface
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue