From 8acf67d4c86838fbe1401bea98ab7db013bb2d80 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sat, 22 Jan 2022 12:58:12 -0500 Subject: [PATCH] linting --- gtsam/discrete/AlgebraicDecisionTree.h | 87 ++++++++++++-------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/gtsam/discrete/AlgebraicDecisionTree.h b/gtsam/discrete/AlgebraicDecisionTree.h index 566357a485..6ce36a688a 100644 --- a/gtsam/discrete/AlgebraicDecisionTree.h +++ b/gtsam/discrete/AlgebraicDecisionTree.h @@ -20,6 +20,10 @@ #include +#include +#include +#include +#include namespace gtsam { /** @@ -27,13 +31,14 @@ namespace gtsam { * Just has some nice constructors and some syntactic sugar * TODO: consider eliminating this class altogether? */ - template - class GTSAM_EXPORT AlgebraicDecisionTree: public DecisionTree { + template + class GTSAM_EXPORT AlgebraicDecisionTree : public DecisionTree { /** - * @brief Default method used by `labelFormatter` or `valueFormatter` when printing. - * + * @brief Default method used by `labelFormatter` or `valueFormatter` when + * printing. + * * @param x The value passed to format. - * @return std::string + * @return std::string */ static std::string DefaultFormatter(const L& x) { std::stringstream ss; @@ -42,17 +47,12 @@ namespace gtsam { } public: - using Base = DecisionTree; /** The Real ring with addition and multiplication */ struct Ring { - static inline double zero() { - return 0.0; - } - static inline double one() { - return 1.0; - } + static inline double zero() { return 0.0; } + static inline double one() { return 1.0; } static inline double add(const double& a, const double& b) { return a + b; } @@ -65,54 +65,49 @@ namespace gtsam { static inline double div(const double& a, const double& b) { return a / b; } - static inline double id(const double& x) { - return x; - } + static inline double id(const double& x) { return x; } }; - AlgebraicDecisionTree() : - Base(1.0) { - } + AlgebraicDecisionTree() : Base(1.0) {} - AlgebraicDecisionTree(const Base& add) : - Base(add) { - } + explicit AlgebraicDecisionTree(const Base& add) : Base(add) {} /** Create a new leaf function splitting on a variable */ - AlgebraicDecisionTree(const L& label, double y1, double y2) : - Base(label, y1, y2) { - } + AlgebraicDecisionTree(const L& label, double y1, double y2) + : Base(label, y1, y2) {} /** Create a new leaf function splitting on a variable */ - AlgebraicDecisionTree(const typename Base::LabelC& labelC, double y1, double y2) : - Base(labelC, y1, y2) { - } + AlgebraicDecisionTree(const typename Base::LabelC& labelC, double y1, + double y2) + : Base(labelC, y1, y2) {} /** Create from keys and vector table */ - AlgebraicDecisionTree // - (const std::vector& labelCs, const std::vector& ys) { - this->root_ = Base::create(labelCs.begin(), labelCs.end(), ys.begin(), - ys.end()); + AlgebraicDecisionTree // + (const std::vector& labelCs, + const std::vector& ys) { + this->root_ = + Base::create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); } /** Create from keys and string table */ - AlgebraicDecisionTree // - (const std::vector& labelCs, const std::string& table) { + AlgebraicDecisionTree // + (const std::vector& labelCs, + const std::string& table) { // Convert string to doubles std::vector ys; std::istringstream iss(table); std::copy(std::istream_iterator(iss), - std::istream_iterator(), std::back_inserter(ys)); + std::istream_iterator(), std::back_inserter(ys)); // now call recursive Create - this->root_ = Base::create(labelCs.begin(), labelCs.end(), ys.begin(), - ys.end()); + this->root_ = + Base::create(labelCs.begin(), labelCs.end(), ys.begin(), ys.end()); } /** Create a new function splitting on a variable */ - template - AlgebraicDecisionTree(Iterator begin, Iterator end, const L& label) : - Base(nullptr) { + template + AlgebraicDecisionTree(Iterator begin, Iterator end, const L& label) + : Base(nullptr) { this->root_ = compose(begin, end, label); } @@ -122,7 +117,7 @@ namespace gtsam { * @param other: The AlgebraicDecisionTree with label type M to convert. * @param map: Map from label type M to label type L. */ - template + template AlgebraicDecisionTree(const AlgebraicDecisionTree& other, const std::map& map) { // Functor for label conversion so we can use `convertFrom`. @@ -160,8 +155,8 @@ namespace gtsam { /// print method customized to value type `double`. void print(const std::string& s, - const typename Base::LabelFormatter& labelFormatter = - &DefaultFormatter) const { + const typename Base::LabelFormatter& labelFormatter = + &DefaultFormatter) const { auto valueFormatter = [](const double& v) { return (boost::format("%4.4g") % v).str(); }; @@ -177,8 +172,8 @@ namespace gtsam { return Base::equals(other, compare); } }; -// AlgebraicDecisionTree -template struct traits> : public Testable> {}; -} -// namespace gtsam +template +struct traits> + : public Testable> {}; +} // namespace gtsam