From a55e4744261f3aa411e000c9b66a9dbfc280c9f5 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 29 May 2021 21:47:13 -0400 Subject: [PATCH] update docstrings and format --- gtsam/nonlinear/NonlinearEquality.h | 53 ++++++++++++++++------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/gtsam/nonlinear/NonlinearEquality.h b/gtsam/nonlinear/NonlinearEquality.h index f4cf3cc88e..d7f8b0ef89 100644 --- a/gtsam/nonlinear/NonlinearEquality.h +++ b/gtsam/nonlinear/NonlinearEquality.h @@ -59,10 +59,10 @@ class NonlinearEquality: public NoiseModelFactor1 { double error_gain_; // typedef to this class - typedef NonlinearEquality This; + using This = NonlinearEquality; // typedef to base class - typedef NoiseModelFactor1 Base; + using Base = NoiseModelFactor1; public: @@ -73,7 +73,7 @@ class NonlinearEquality: public NoiseModelFactor1 { CompareFunction compare_; // bool (*compare_)(const T& a, const T& b); - /** default constructor - only for serialization */ + /// Default constructor - only for serialization NonlinearEquality() { } @@ -109,9 +109,11 @@ class NonlinearEquality: public NoiseModelFactor1 { void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override { - std::cout << s << "Constraint: on [" << keyFormatter(this->key()) << "]\n"; + std::cout << (s.empty() ? s : s + " ") << "Constraint: on [" + << keyFormatter(this->key()) << "]\n"; traits::Print(feasible_, "Feasible Point:\n"); - std::cout << "Variable Dimension: " << traits::GetDimension(feasible_) << std::endl; + std::cout << "Variable Dimension: " << traits::GetDimension(feasible_) + << std::endl; } /** Check if two factors are equal */ @@ -125,7 +127,7 @@ class NonlinearEquality: public NoiseModelFactor1 { /// @name Standard Interface /// @{ - /** actual error function calculation */ + /// Actual error function calculation double error(const Values& c) const override { const T& xj = c.at(this->key()); Vector e = this->unwhitenedError(c); @@ -136,7 +138,7 @@ class NonlinearEquality: public NoiseModelFactor1 { } } - /** error function */ + /// Error function Vector evaluateError(const T& xj, boost::optional H = boost::none) const override { const size_t nj = traits::GetDimension(feasible_); @@ -157,7 +159,7 @@ class NonlinearEquality: public NoiseModelFactor1 { } } - // Linearize is over-written, because base linearization tries to whiten + /// Linearize is over-written, because base linearization tries to whiten GaussianFactor::shared_ptr linearize(const Values& x) const override { const T& xj = x.at(this->key()); Matrix A; @@ -179,7 +181,7 @@ class NonlinearEquality: public NoiseModelFactor1 { private: - /** Serialization function */ + /// Serialization function friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int /*version*/) { @@ -212,7 +214,7 @@ class NonlinearEquality1: public NoiseModelFactor1 { typedef NoiseModelFactor1 Base; typedef NonlinearEquality1 This; - /** default constructor to allow for serialization */ + /// Default constructor to allow for serialization NonlinearEquality1() { } @@ -231,12 +233,12 @@ class NonlinearEquality1: public NoiseModelFactor1 { * @param value feasible value that values(key) shouild be equal to * @param key the key for the unknown variable to be constrained * @param mu a parameter which really turns this into a strong prior - * */ - NonlinearEquality1(const X& value, Key key, double mu = 1000.0) : - Base( noiseModel::Constrained::All(traits::GetDimension(value), - std::abs(mu)), key), value_(value) { - } + NonlinearEquality1(const X& value, Key key, double mu = 1000.0) + : Base(noiseModel::Constrained::All(traits::GetDimension(value), + std::abs(mu)), + key), + value_(value) {} ~NonlinearEquality1() override { } @@ -247,7 +249,7 @@ class NonlinearEquality1: public NoiseModelFactor1 { gtsam::NonlinearFactor::shared_ptr(new This(*this))); } - /** g(x) with optional derivative */ + /// g(x) with optional derivative Vector evaluateError(const X& x1, boost::optional H = boost::none) const override { if (H) @@ -256,7 +258,7 @@ class NonlinearEquality1: public NoiseModelFactor1 { return traits::Local(value_,x1); } - /** Print */ + /// Print void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override { std::cout << s << ": NonlinearEquality1(" << keyFormatter(this->key()) @@ -269,7 +271,7 @@ class NonlinearEquality1: public NoiseModelFactor1 { private: - /** Serialization function */ + /// Serialization function friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int /*version*/) { @@ -287,7 +289,7 @@ struct traits > : Testable > /* ************************************************************************* */ /** - * Simple binary equality constraint - this constraint forces two factors to + * Simple binary equality constraint - this constraint forces two variables to * be the same. */ template @@ -301,7 +303,7 @@ class NonlinearEquality2: public NoiseModelFactor2 { GTSAM_CONCEPT_MANIFOLD_TYPE(X) - /** default constructor to allow for serialization */ + /// Default constructor to allow for serialization NonlinearEquality2() { } @@ -309,7 +311,12 @@ class NonlinearEquality2: public NoiseModelFactor2 { typedef boost::shared_ptr > shared_ptr; - ///TODO: comment + /** + * Constructor + * @param key1 the key for the first unknown variable to be constrained + * @param key2 the key for the second unknown variable to be constrained + * @param mu a parameter which really turns this into a strong prior + */ NonlinearEquality2(Key key1, Key key2, double mu = 1000.0) : Base(noiseModel::Constrained::All(traits::dimension, std::abs(mu)), key1, key2) { } @@ -322,7 +329,7 @@ class NonlinearEquality2: public NoiseModelFactor2 { gtsam::NonlinearFactor::shared_ptr(new This(*this))); } - /** g(x) with optional derivative2 */ + /// g(x) with optional derivative2 Vector evaluateError(const X& x1, const X& x2, boost::optional H1 = boost::none, boost::optional H2 = boost::none) const override { static const size_t p = traits::dimension; @@ -335,7 +342,7 @@ class NonlinearEquality2: public NoiseModelFactor2 { private: - /** Serialization function */ + /// Serialization function friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int /*version*/) {