From 93de9848e386447a6a7cade8875118852afdf139 Mon Sep 17 00:00:00 2001 From: Nithya Date: Wed, 9 Jun 2021 12:41:20 -0400 Subject: [PATCH 0001/1497] Added *.bib file --- README.md | 5 +++++ references.bib | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 references.bib diff --git a/README.md b/README.md index 60eff197ae..a83b013c99 100644 --- a/README.md +++ b/README.md @@ -95,3 +95,8 @@ GTSAM is open source under the BSD license, see the [`LICENSE`](LICENSE) and [`L Please see the [`examples/`](examples) directory and the [`USAGE`](USAGE.md) file for examples on how to use GTSAM. GTSAM was developed in the lab of [Frank Dellaert](http://www.cc.gatech.edu/~dellaert) at the [Georgia Institute of Technology](http://www.gatech.edu), with the help of many contributors over the years, see [THANKS](THANKS.md). + +## GTSAM Citation + +Use the following to cite GTSAM: + diff --git a/references.bib b/references.bib new file mode 100644 index 0000000000..52c00325e4 --- /dev/null +++ b/references.bib @@ -0,0 +1,9 @@ +@misc{gtsam, + author = {Borg Lab}, + title = {{GTSAM}}, + month = jul, + year = 2020, + doi = {}, + version = {4.0.3}, + url = {} + } \ No newline at end of file From 1c00d130f5a96616b9d8dc99ec27506e71a17cf3 Mon Sep 17 00:00:00 2001 From: Nithya Date: Fri, 11 Jun 2021 11:25:21 -0400 Subject: [PATCH 0002/1497] additional citations --- README.md | 3 --- references.bib | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a83b013c99..cb7b3d4640 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,4 @@ Please see the [`examples/`](examples) directory and the [`USAGE`](USAGE.md) fil GTSAM was developed in the lab of [Frank Dellaert](http://www.cc.gatech.edu/~dellaert) at the [Georgia Institute of Technology](http://www.gatech.edu), with the help of many contributors over the years, see [THANKS](THANKS.md). -## GTSAM Citation - -Use the following to cite GTSAM: diff --git a/references.bib b/references.bib index 52c00325e4..5468204cc9 100644 --- a/references.bib +++ b/references.bib @@ -1,9 +1,24 @@ @misc{gtsam, - author = {Borg Lab}, + author = {{Borg Lab}}, title = {{GTSAM}}, month = jul, year = 2020, - doi = {}, version = {4.0.3}, - url = {} - } \ No newline at end of file + url = {https://github.com/borglab/gtsam} + } + +@article{imu-preintegration, + author = {{Christian Forster and Luca Carlone and Frank Dellaert and Davide Scaramuzza}}, + title = {{IMU preintegration on Manifold for Efficient Visual-Inertial Maximum-a-Posteriori Estimation}}, + year = 2015 + +} + +@techreport{factorgraphs, + author = {Frank Dellaert}, + title = {{Factor Graphs and GTSAM: A Hands-On Introduction}}, + number = {GT-RIM-CP\&R-2012-002}, + month = jul, + year = 2012 + +} \ No newline at end of file From 81f1d9315840e0638da10c1397a73cec90b0744e Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Wed, 1 Dec 2021 16:04:49 -0500 Subject: [PATCH 0003/1497] NoiseModelFactorN - fixed-number of variables >6 --- gtsam/mainpage.dox | 2 +- gtsam/nonlinear/NonlinearFactor.h | 106 ++++++++++++++++++++++++++++++ tests/testNonlinearFactor.cpp | 44 +++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) diff --git a/gtsam/mainpage.dox b/gtsam/mainpage.dox index ee7bd9924c..e07f45f079 100644 --- a/gtsam/mainpage.dox +++ b/gtsam/mainpage.dox @@ -16,7 +16,7 @@ To use GTSAM to solve your own problems, you will often have to create new facto -# The number of variables your factor involves is unknown at compile time - derive from NoiseModelFactor and implement NoiseModelFactor::unwhitenedError() - This is a factor expressing the sum-of-squares error between a measurement \f$ z \f$ and a measurement prediction function \f$ h(x) \f$, on which the errors are expected to follow some distribution specified by a noise model (see noiseModel). --# The number of variables your factor involves is known at compile time and is between 1 and 6 - derive from NoiseModelFactor1, NoiseModelFactor2, NoiseModelFactor3, NoiseModelFactor4, NoiseModelFactor5, or NoiseModelFactor6, and implement \c evaluateError() +-# The number of variables your factor involves is known at compile time and is between 1 and 6 - derive from NoiseModelFactor1, NoiseModelFactor2, NoiseModelFactor3, NoiseModelFactor4, NoiseModelFactor5, or NoiseModelFactor6, and implement \c evaluateError(). If the number of variables is greater than 6, derive from NoiseModelFactorN. - This factor expresses the same sum-of-squares error with a noise model, but makes the implementation task slightly easier than with %NoiseModelFactor. -# Derive from NonlinearFactor - This is more advanced and allows creating factors without an explicit noise model, or that linearize to HessianFactor instead of JacobianFactor. diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 7fafd95dfa..503ae7d58f 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -28,6 +28,7 @@ #include #include +#include namespace gtsam { @@ -770,5 +771,110 @@ class NoiseModelFactor6: public NoiseModelFactor { }; // \class NoiseModelFactor6 /* ************************************************************************* */ +/** A convenient base class for creating your own NoiseModelFactor with N + * variables. To derive from this class, implement evaluateError(). */ +template +class NoiseModelFactorN: public NoiseModelFactor { + +protected: + + typedef NoiseModelFactor Base; + typedef NoiseModelFactorN This; + + /* "Dummy templated" alias is used to expand fixed-type parameter packs with + * same length as VALUES. This ignores the template parameter. */ + template + using optional_matrix_type = boost::optional; + + /* "Dummy templated" alias is used to expand fixed-type parameter packs with + * same length as VALUES. This ignores the template parameter. */ + template + using key_type = Key; + +public: + + /** + * Default Constructor for I/O + */ + NoiseModelFactorN() {} + + /** + * Constructor. + * Example usage: NoiseModelFactorN(noise, key1, key2, ..., keyN) + * @param noiseModel shared pointer to noise model + * @param keys... keys for the variables in this factor + */ + NoiseModelFactorN(const SharedNoiseModel& noiseModel, + key_type... keys) + : Base(noiseModel, std::array{keys...}) {} + + /** + * Constructor. + * @param noiseModel shared pointer to noise model + * @param keys a container of keys for the variables in this factor + */ + template + NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys) + : Base(noiseModel, keys) { + assert(std::size(keys) == sizeof...(VALUES)); + } + + ~NoiseModelFactorN() override {} + + /** Method to retrieve keys */ + template + inline Key key() const { return keys_[N]; } + + /** Calls the n-key specific version of evaluateError, which is pure virtual + * so must be implemented in the derived class. */ + Vector unwhitenedError( + const Values& x, + boost::optional&> H = boost::none) const override { + return unwhitenedError(boost::mp11::index_sequence_for{}, x, H); + } + + /** + * Override this method to finish implementing an n-way factor. + * If any of the optional Matrix reference arguments are specified, it should + * compute both the function evaluation and its derivative(s) in the requested + * variables. + */ + virtual Vector evaluateError( + const VALUES& ... x, + optional_matrix_type ... H) const = 0; + + /** No-jacobians requested function overload (since parameter packs can't have + * default args) */ + Vector evaluateError(const VALUES&... x) const { + return evaluateError(x..., optional_matrix_type()...); + } + + private: + + /** Pack expansion with index_sequence template pattern */ + template + Vector unwhitenedError( + boost::mp11::index_sequence, // + const Values& x, + boost::optional&> H = boost::none) const { + if (this->active(x)) { + if (H) { + return evaluateError(x.at(keys_[Inds])..., (*H)[Inds]...); + } else { + return evaluateError(x.at(keys_[Inds])...); + } + } else { + return Vector::Zero(this->dim()); + } + } + + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int /*version*/) { + ar & boost::serialization::make_nvp("NoiseModelFactor", + boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactorN } // \namespace gtsam diff --git a/tests/testNonlinearFactor.cpp b/tests/testNonlinearFactor.cpp index 84bba850b3..eb35bf55da 100644 --- a/tests/testNonlinearFactor.cpp +++ b/tests/testNonlinearFactor.cpp @@ -406,6 +406,50 @@ TEST(NonlinearFactor, NoiseModelFactor6) { } +/* ************************************************************************* */ +class TestFactorN : public NoiseModelFactorN { +public: + typedef NoiseModelFactorN Base; + TestFactorN() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X(1), X(2), X(3), X(4)) {} + + Vector + evaluateError(const double& x1, const double& x2, const double& x3, const double& x4, + boost::optional H1 = boost::none, + boost::optional H2 = boost::none, + boost::optional H3 = boost::none, + boost::optional H4 = boost::none) const override { + if (H1) { + *H1 = (Matrix(1, 1) << 1.0).finished(); + *H2 = (Matrix(1, 1) << 2.0).finished(); + *H3 = (Matrix(1, 1) << 3.0).finished(); + *H4 = (Matrix(1, 1) << 4.0).finished(); + } + return (Vector(1) << x1 + x2 + x3 + x4).finished(); + } +}; + +/* ************************************ */ +TEST(NonlinearFactor, NoiseModelFactorN) { + TestFactorN tf; + Values tv; + tv.insert(X(1), double((1.0))); + tv.insert(X(2), double((2.0))); + tv.insert(X(3), double((3.0))); + tv.insert(X(4), double((4.0))); + EXPECT(assert_equal((Vector(1) << 10.0).finished(), tf.unwhitenedError(tv))); + DOUBLES_EQUAL(25.0/2.0, tf.error(tv), 1e-9); + JacobianFactor jf(*boost::dynamic_pointer_cast(tf.linearize(tv))); + LONGS_EQUAL((long)X(1), (long)jf.keys()[0]); + LONGS_EQUAL((long)X(2), (long)jf.keys()[1]); + LONGS_EQUAL((long)X(3), (long)jf.keys()[2]); + LONGS_EQUAL((long)X(4), (long)jf.keys()[3]); + EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 0.5).finished(), jf.getA(jf.begin()))); + EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 1.0).finished(), jf.getA(jf.begin()+1))); + EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 1.5).finished(), jf.getA(jf.begin()+2))); + EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 2.0).finished(), jf.getA(jf.begin()+3))); + EXPECT(assert_equal((Vector)(Vector(1) << -5.0).finished(), jf.getb())); +} + /* ************************************************************************* */ TEST( NonlinearFactor, clone_rekey ) { From e037fa1bdbf49a7c07aeb226caaca11e43fa4be5 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Wed, 1 Dec 2021 16:20:51 -0500 Subject: [PATCH 0004/1497] c++11 doesn't support std::size so use obj.size() instead --- gtsam/nonlinear/NonlinearFactor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 503ae7d58f..b87d1bfaaa 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -816,7 +816,7 @@ class NoiseModelFactorN: public NoiseModelFactor { template NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys) : Base(noiseModel, keys) { - assert(std::size(keys) == sizeof...(VALUES)); + assert(keys.size() == sizeof...(VALUES)); } ~NoiseModelFactorN() override {} From d9c8ce2721c076805b541746d268e69a99e71bd9 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Thu, 2 Dec 2021 23:26:34 -0500 Subject: [PATCH 0005/1497] alternate make_index_sequence impl if no boost::mp11 --- gtsam/nonlinear/NonlinearFactor.h | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index b87d1bfaaa..2498913970 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -28,7 +28,41 @@ #include #include + +#if BOOST_VERSION >= 106600 #include +#else +namespace boost { +namespace mp11 { +// Adapted from https://stackoverflow.com/a/32223343/9151520 +template +struct index_sequence { + using type = index_sequence; + using value_type = size_t; + static constexpr std::size_t size() noexcept { return sizeof...(Ints); } +}; +namespace detail { +template +struct _merge_and_renumber; + +template +struct _merge_and_renumber, index_sequence > + : index_sequence {}; +} // namespace detail +template +struct make_index_sequence + : detail::_merge_and_renumber< + typename make_index_sequence::type, + typename make_index_sequence::type> {}; +template <> +struct make_index_sequence<0> : index_sequence<> {}; +template <> +struct make_index_sequence<1> : index_sequence<0> {}; +template +using index_sequence_for = make_index_sequence; +} // namespace mp11 +} // namespace boost +#endif namespace gtsam { From 2aecaf325805f14e690fcfb83a4a20b579527467 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 00:39:10 -0500 Subject: [PATCH 0006/1497] optional jacobian overloads backwards compatibility --- gtsam/nonlinear/NonlinearFactor.h | 17 ++++++++++++-- tests/testNonlinearFactor.cpp | 37 ++++++++++++++++++++++++++----- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 2498913970..542c4d5f1b 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -878,11 +878,24 @@ class NoiseModelFactorN: public NoiseModelFactor { optional_matrix_type ... H) const = 0; /** No-jacobians requested function overload (since parameter packs can't have - * default args) */ - Vector evaluateError(const VALUES&... x) const { + * default args). This specializes the version below to avoid recursive calls + * since this is commonly used. */ + inline Vector evaluateError(const VALUES&... x) const { return evaluateError(x..., optional_matrix_type()...); } + /** Some optional jacobians omitted function overload */ + template 0) && + (sizeof...(OptionalJacArgs) < + sizeof...(VALUES)), + bool>::type = true> + inline Vector evaluateError(const VALUES&... x, + OptionalJacArgs&&... H) const { + return evaluateError(x..., std::forward(H)..., + boost::none); + } + private: /** Pack expansion with index_sequence template pattern */ diff --git a/tests/testNonlinearFactor.cpp b/tests/testNonlinearFactor.cpp index eb35bf55da..8ecbbc397f 100644 --- a/tests/testNonlinearFactor.cpp +++ b/tests/testNonlinearFactor.cpp @@ -418,12 +418,10 @@ class TestFactorN : public NoiseModelFactorN { boost::optional H2 = boost::none, boost::optional H3 = boost::none, boost::optional H4 = boost::none) const override { - if (H1) { - *H1 = (Matrix(1, 1) << 1.0).finished(); - *H2 = (Matrix(1, 1) << 2.0).finished(); - *H3 = (Matrix(1, 1) << 3.0).finished(); - *H4 = (Matrix(1, 1) << 4.0).finished(); - } + if (H1) *H1 = (Matrix(1, 1) << 1.0).finished(); + if (H2) *H2 = (Matrix(1, 1) << 2.0).finished(); + if (H3) *H3 = (Matrix(1, 1) << 3.0).finished(); + if (H4) *H4 = (Matrix(1, 1) << 4.0).finished(); return (Vector(1) << x1 + x2 + x3 + x4).finished(); } }; @@ -448,6 +446,33 @@ TEST(NonlinearFactor, NoiseModelFactorN) { EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 1.5).finished(), jf.getA(jf.begin()+2))); EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 2.0).finished(), jf.getA(jf.begin()+3))); EXPECT(assert_equal((Vector)(Vector(1) << -5.0).finished(), jf.getb())); + + // Test all evaluateError argument overloads to ensure backward compatibility + Matrix H1_expected, H2_expected, H3_expected, H4_expected; + Vector e_expected = tf.evaluateError(9, 8, 7, 6, H1_expected, H2_expected, + H3_expected, H4_expected); + + std::unique_ptr> base_ptr( + new TestFactorN(tf)); + Matrix H1, H2, H3, H4; + EXPECT(assert_equal(e_expected, base_ptr->evaluateError(9, 8, 7, 6))); + EXPECT(assert_equal(e_expected, base_ptr->evaluateError(9, 8, 7, 6, H1))); + EXPECT(assert_equal(H1_expected, H1)); + EXPECT(assert_equal(e_expected, // + base_ptr->evaluateError(9, 8, 7, 6, H1, H2))); + EXPECT(assert_equal(H1_expected, H1)); + EXPECT(assert_equal(H2_expected, H2)); + EXPECT(assert_equal(e_expected, + base_ptr->evaluateError(9, 8, 7, 6, H1, H2, H3))); + EXPECT(assert_equal(H1_expected, H1)); + EXPECT(assert_equal(H2_expected, H2)); + EXPECT(assert_equal(H3_expected, H3)); + EXPECT(assert_equal(e_expected, + base_ptr->evaluateError(9, 8, 7, 6, H1, H2, H3, H4))); + EXPECT(assert_equal(H1_expected, H1)); + EXPECT(assert_equal(H2_expected, H2)); + EXPECT(assert_equal(H3_expected, H3)); + EXPECT(assert_equal(H4_expected, H4)); } /* ************************************************************************* */ From 8fe7e48258d69f4cb131c6af7e15504806ebbd4b Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 00:46:23 -0500 Subject: [PATCH 0007/1497] backward compatibility unit tests for NoiseModelFactor4 --- tests/testNonlinearFactor.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/testNonlinearFactor.cpp b/tests/testNonlinearFactor.cpp index 8ecbbc397f..fda65d56a3 100644 --- a/tests/testNonlinearFactor.cpp +++ b/tests/testNonlinearFactor.cpp @@ -255,7 +255,13 @@ TEST( NonlinearFactor, cloneWithNewNoiseModel ) /* ************************************************************************* */ class TestFactor4 : public NoiseModelFactor4 { -public: + static_assert(std::is_same::value, "Base type wrong"); + static_assert( + std::is_same>::value, + "This type wrong"); + + public: typedef NoiseModelFactor4 Base; TestFactor4() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X(1), X(2), X(3), X(4)) {} @@ -299,6 +305,22 @@ TEST(NonlinearFactor, NoiseModelFactor4) { EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 1.5).finished(), jf.getA(jf.begin()+2))); EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 2.0).finished(), jf.getA(jf.begin()+3))); EXPECT(assert_equal((Vector)(Vector(1) << -5.0).finished(), jf.getb())); + + // Test all functions/types for backwards compatibility + static_assert(std::is_same::value, + "X1 type incorrect"); + static_assert(std::is_same::value, + "X2 type incorrect"); + static_assert(std::is_same::value, + "X3 type incorrect"); + static_assert(std::is_same::value, + "X4 type incorrect"); + EXPECT(assert_equal(tf.key1(), X(1))); + EXPECT(assert_equal(tf.key2(), X(2))); + EXPECT(assert_equal(tf.key3(), X(3))); + EXPECT(assert_equal(tf.key4(), X(4))); + std::vector H = {Matrix(), Matrix(), Matrix(), Matrix()}; + EXPECT(assert_equal(Vector1(10.0), tf.unwhitenedError(tv, H))); } /* ************************************************************************* */ From bee4eeefdd358d07fb7ed02911a58dd5ec3eba33 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 02:25:11 -0500 Subject: [PATCH 0008/1497] NoiseModelFactor4 implemented as derived class of NoiseModelFactorN --- gtsam/nonlinear/NonlinearFactor.h | 345 +++++++++++++----------------- 1 file changed, 153 insertions(+), 192 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 542c4d5f1b..e024a41a09 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -309,13 +309,137 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { /* ************************************************************************* */ /** - * A convenient base class for creating your own NoiseModelFactor with 1 - * variable. To derive from this class, implement evaluateError(). + * A convenient base class for creating your own NoiseModelFactor with n + * variables. To derive from this class, implement evaluateError(). * * Templated on a values structure type. The values structures are typically * more general than just vectors, e.g., Rot3 or Pose3, * which are objects in non-linear manifolds (Lie groups). */ +template +class NoiseModelFactorN: public NoiseModelFactor { + public: + /** The type of the N'th template param can be obtained with VALUE */ + template + using VALUE = typename std::tuple_element>::type; + + protected: + typedef NoiseModelFactor Base; + typedef NoiseModelFactorN This; + + /* "Dummy templated" alias is used to expand fixed-type parameter packs with + * same length as VALUES. This ignores the template parameter. */ + template + using optional_matrix_type = boost::optional; + + /* "Dummy templated" alias is used to expand fixed-type parameter packs with + * same length as VALUES. This ignores the template parameter. */ + template + using key_type = Key; + + public: + /** + * Default Constructor for I/O + */ + NoiseModelFactorN() {} + + /** + * Constructor. + * Example usage: NoiseModelFactorN(noise, key1, key2, ..., keyN) + * @param noiseModel shared pointer to noise model + * @param keys... keys for the variables in this factor + */ + NoiseModelFactorN(const SharedNoiseModel& noiseModel, + key_type... keys) + : Base(noiseModel, std::array{keys...}) {} + + /** + * Constructor. + * @param noiseModel shared pointer to noise model + * @param keys a container of keys for the variables in this factor + */ + template + NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys) + : Base(noiseModel, keys) { + assert(keys.size() == sizeof...(VALUES)); + } + + ~NoiseModelFactorN() override {} + + // /** Method to retrieve keys */ + // template + // inline Key key() const { return keys_[N]; } + + /** Calls the n-key specific version of evaluateError, which is pure virtual + * so must be implemented in the derived class. */ + Vector unwhitenedError( + const Values& x, + boost::optional&> H = boost::none) const override { + return unwhitenedError(boost::mp11::index_sequence_for{}, x, H); + } + + /** + * Override this method to finish implementing an n-way factor. + * If any of the optional Matrix reference arguments are specified, it should + * compute both the function evaluation and its derivative(s) in the requested + * variables. + */ + virtual Vector evaluateError( + const VALUES& ... x, + optional_matrix_type ... H) const = 0; + + /** No-jacobians requested function overload (since parameter packs can't have + * default args). This specializes the version below to avoid recursive calls + * since this is commonly used. */ + inline Vector evaluateError(const VALUES&... x) const { + return evaluateError(x..., optional_matrix_type()...); + } + + /** Some optional jacobians omitted function overload */ + template 0) && + (sizeof...(OptionalJacArgs) < + sizeof...(VALUES)), + bool>::type = true> + inline Vector evaluateError(const VALUES&... x, + OptionalJacArgs&&... H) const { + return evaluateError(x..., std::forward(H)..., + boost::none); + } + + private: + + /** Pack expansion with index_sequence template pattern */ + template + Vector unwhitenedError( + boost::mp11::index_sequence, // + const Values& x, + boost::optional&> H = boost::none) const { + if (this->active(x)) { + if (H) { + return evaluateError(x.at(keys_[Inds])..., (*H)[Inds]...); + } else { + return evaluateError(x.at(keys_[Inds])...); + } + } else { + return Vector::Zero(this->dim()); + } + } + + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int /*version*/) { + ar & boost::serialization::make_nvp("NoiseModelFactor", + boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactorN + + + +/* ************************************************************************* */ +/** A convenient base class for creating your own NoiseModelFactor with 1 + * variable. To derive from this class, implement evaluateError(). */ template class NoiseModelFactor1: public NoiseModelFactor { @@ -552,83 +676,40 @@ class NoiseModelFactor3: public NoiseModelFactor { /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 4 * variables. To derive from this class, implement evaluateError(). */ -template -class NoiseModelFactor4: public NoiseModelFactor { - -public: - - // typedefs for value types pulled from keys - typedef VALUE1 X1; - typedef VALUE2 X2; - typedef VALUE3 X3; - typedef VALUE4 X4; - -protected: - - typedef NoiseModelFactor Base; - typedef NoiseModelFactor4 This; - -public: - - /** - * Default Constructor for I/O - */ - NoiseModelFactor4() {} - - /** - * Constructor - * @param noiseModel shared pointer to noise model - * @param j1 key of the first variable - * @param j2 key of the second variable - * @param j3 key of the third variable - * @param j4 key of the fourth variable - */ - NoiseModelFactor4(const SharedNoiseModel& noiseModel, Key j1, Key j2, Key j3, Key j4) : - Base(noiseModel, cref_list_of<4>(j1)(j2)(j3)(j4)) {} - +template +class NoiseModelFactor4 + : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; + using X4 = VALUE4; + + protected: + using Base = NoiseModelFactor; // grandparent, for backwards compatibility + using This = NoiseModelFactor4; + + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor4() override {} /** methods to retrieve keys */ - inline Key key1() const { return keys_[0]; } - inline Key key2() const { return keys_[1]; } - inline Key key3() const { return keys_[2]; } - inline Key key4() const { return keys_[3]; } - - /** Calls the 4-key specific version of evaluateError, which is pure virtual - * so must be implemented in the derived class. */ - Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const override { - if(this->active(x)) { - if(H) - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), (*H)[0], (*H)[1], (*H)[2], (*H)[3]); - else - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3])); - } else { - return Vector::Zero(this->dim()); - } - } - - /** - * Override this method to finish implementing a 4-way factor. - * If any of the optional Matrix reference arguments are specified, it should compute - * both the function evaluation and its derivative(s) in X1 (and/or X2, X3). - */ - virtual Vector - evaluateError(const X1&, const X2&, const X3&, const X4&, - boost::optional H1 = boost::none, - boost::optional H2 = boost::none, - boost::optional H3 = boost::none, - boost::optional H4 = boost::none) const = 0; - -private: + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + inline Key key4() const { return this->keys_[3]; } + private: /** Serialization function */ friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); } -}; // \class NoiseModelFactor4 +}; // \class NoiseModelFactor4 /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 5 @@ -804,124 +885,4 @@ class NoiseModelFactor6: public NoiseModelFactor { } }; // \class NoiseModelFactor6 -/* ************************************************************************* */ -/** A convenient base class for creating your own NoiseModelFactor with N - * variables. To derive from this class, implement evaluateError(). */ -template -class NoiseModelFactorN: public NoiseModelFactor { - -protected: - - typedef NoiseModelFactor Base; - typedef NoiseModelFactorN This; - - /* "Dummy templated" alias is used to expand fixed-type parameter packs with - * same length as VALUES. This ignores the template parameter. */ - template - using optional_matrix_type = boost::optional; - - /* "Dummy templated" alias is used to expand fixed-type parameter packs with - * same length as VALUES. This ignores the template parameter. */ - template - using key_type = Key; - -public: - - /** - * Default Constructor for I/O - */ - NoiseModelFactorN() {} - - /** - * Constructor. - * Example usage: NoiseModelFactorN(noise, key1, key2, ..., keyN) - * @param noiseModel shared pointer to noise model - * @param keys... keys for the variables in this factor - */ - NoiseModelFactorN(const SharedNoiseModel& noiseModel, - key_type... keys) - : Base(noiseModel, std::array{keys...}) {} - - /** - * Constructor. - * @param noiseModel shared pointer to noise model - * @param keys a container of keys for the variables in this factor - */ - template - NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys) - : Base(noiseModel, keys) { - assert(keys.size() == sizeof...(VALUES)); - } - - ~NoiseModelFactorN() override {} - - /** Method to retrieve keys */ - template - inline Key key() const { return keys_[N]; } - - /** Calls the n-key specific version of evaluateError, which is pure virtual - * so must be implemented in the derived class. */ - Vector unwhitenedError( - const Values& x, - boost::optional&> H = boost::none) const override { - return unwhitenedError(boost::mp11::index_sequence_for{}, x, H); - } - - /** - * Override this method to finish implementing an n-way factor. - * If any of the optional Matrix reference arguments are specified, it should - * compute both the function evaluation and its derivative(s) in the requested - * variables. - */ - virtual Vector evaluateError( - const VALUES& ... x, - optional_matrix_type ... H) const = 0; - - /** No-jacobians requested function overload (since parameter packs can't have - * default args). This specializes the version below to avoid recursive calls - * since this is commonly used. */ - inline Vector evaluateError(const VALUES&... x) const { - return evaluateError(x..., optional_matrix_type()...); - } - - /** Some optional jacobians omitted function overload */ - template 0) && - (sizeof...(OptionalJacArgs) < - sizeof...(VALUES)), - bool>::type = true> - inline Vector evaluateError(const VALUES&... x, - OptionalJacArgs&&... H) const { - return evaluateError(x..., std::forward(H)..., - boost::none); - } - - private: - - /** Pack expansion with index_sequence template pattern */ - template - Vector unwhitenedError( - boost::mp11::index_sequence, // - const Values& x, - boost::optional&> H = boost::none) const { - if (this->active(x)) { - if (H) { - return evaluateError(x.at(keys_[Inds])..., (*H)[Inds]...); - } else { - return evaluateError(x.at(keys_[Inds])...); - } - } else { - return Vector::Zero(this->dim()); - } - } - - /** Serialization function */ - friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); - } -}; // \class NoiseModelFactorN - } // \namespace gtsam From ed07edbfe4ab40fa1d583fe47bfd762818a97ae1 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 03:00:47 -0500 Subject: [PATCH 0009/1497] converted all NoiseModelFactorX to inherit from NoiseModelFactorN --- gtsam/nonlinear/NonlinearFactor.h | 502 ++++++++---------------------- 1 file changed, 137 insertions(+), 365 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index e024a41a09..64ef96b854 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -316,16 +316,16 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { * more general than just vectors, e.g., Rot3 or Pose3, * which are objects in non-linear manifolds (Lie groups). */ -template -class NoiseModelFactorN: public NoiseModelFactor { +template +class NoiseModelFactorN : public NoiseModelFactor { public: /** The type of the N'th template param can be obtained with VALUE */ template using VALUE = typename std::tuple_element>::type; protected: - typedef NoiseModelFactor Base; - typedef NoiseModelFactorN This; + using Base = NoiseModelFactor; + using This = NoiseModelFactorN; /* "Dummy templated" alias is used to expand fixed-type parameter packs with * same length as VALUES. This ignores the template parameter. */ @@ -366,9 +366,11 @@ class NoiseModelFactorN: public NoiseModelFactor { ~NoiseModelFactorN() override {} - // /** Method to retrieve keys */ - // template - // inline Key key() const { return keys_[N]; } + /** Method to retrieve keys */ + template + inline Key key() const { + return keys_[N]; + } /** Calls the n-key specific version of evaluateError, which is pure virtual * so must be implemented in the derived class. */ @@ -384,9 +386,8 @@ class NoiseModelFactorN: public NoiseModelFactor { * compute both the function evaluation and its derivative(s) in the requested * variables. */ - virtual Vector evaluateError( - const VALUES& ... x, - optional_matrix_type ... H) const = 0; + virtual Vector evaluateError(const VALUES&... x, + optional_matrix_type... H) const = 0; /** No-jacobians requested function overload (since parameter packs can't have * default args). This specializes the version below to avoid recursive calls @@ -408,7 +409,6 @@ class NoiseModelFactorN: public NoiseModelFactor { } private: - /** Pack expansion with index_sequence template pattern */ template Vector unwhitenedError( @@ -428,250 +428,110 @@ class NoiseModelFactorN: public NoiseModelFactor { /** Serialization function */ friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); } -}; // \class NoiseModelFactorN - - +}; // \class NoiseModelFactorN /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 1 * variable. To derive from this class, implement evaluateError(). */ -template -class NoiseModelFactor1: public NoiseModelFactor { - -public: - - // typedefs for value types pulled from keys - typedef VALUE X; - -protected: - - typedef NoiseModelFactor Base; - typedef NoiseModelFactor1 This; - -public: - /// @name Constructors - /// @{ +template +class NoiseModelFactor1 : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X = VALUE; - /** Default constructor for I/O only */ - NoiseModelFactor1() {} + protected: + using Base = NoiseModelFactor; // grandparent, for backwards compatibility + using This = NoiseModelFactor1; + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor1() override {} - inline Key key() const { return keys_[0]; } + inline Key key() const { return this->keys_[0]; } - /** - * Constructor - * @param noiseModel shared pointer to noise model - * @param key1 by which to look up X value in Values - */ - NoiseModelFactor1(const SharedNoiseModel &noiseModel, Key key1) - : Base(noiseModel, cref_list_of<1>(key1)) {} - - /// @} - /// @name NoiseModelFactor methods - /// @{ - - /** - * Calls the 1-key specific version of evaluateError below, which is pure - * virtual so must be implemented in the derived class. - */ - Vector unwhitenedError( - const Values &x, - boost::optional &> H = boost::none) const override { - if (this->active(x)) { - const X &x1 = x.at(keys_[0]); - if (H) { - return evaluateError(x1, (*H)[0]); - } else { - return evaluateError(x1); - } - } else { - return Vector::Zero(this->dim()); - } - } - - /// @} - /// @name Virtual methods - /// @{ - - /** - * Override this method to finish implementing a unary factor. - * If the optional Matrix reference argument is specified, it should compute - * both the function evaluation and its derivative in X. - */ - virtual Vector - evaluateError(const X &x, - boost::optional H = boost::none) const = 0; - - /// @} - -private: + private: /** Serialization function */ friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); } -};// \class NoiseModelFactor1 - +}; // \class NoiseModelFactor1 /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 2 * variables. To derive from this class, implement evaluateError(). */ -template -class NoiseModelFactor2: public NoiseModelFactor { - -public: - - // typedefs for value types pulled from keys - typedef VALUE1 X1; - typedef VALUE2 X2; - -protected: - - typedef NoiseModelFactor Base; - typedef NoiseModelFactor2 This; - -public: - - /** - * Default Constructor for I/O - */ - NoiseModelFactor2() {} +template +class NoiseModelFactor2 : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; - /** - * Constructor - * @param noiseModel shared pointer to noise model - * @param j1 key of the first variable - * @param j2 key of the second variable - */ - NoiseModelFactor2(const SharedNoiseModel& noiseModel, Key j1, Key j2) : - Base(noiseModel, cref_list_of<2>(j1)(j2)) {} + protected: + using Base = NoiseModelFactor; + using This = NoiseModelFactor2; + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor2() override {} /** methods to retrieve both keys */ - inline Key key1() const { return keys_[0]; } - inline Key key2() const { return keys_[1]; } - - /** Calls the 2-key specific version of evaluateError, which is pure virtual - * so must be implemented in the derived class. */ - Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const override { - if(this->active(x)) { - const X1& x1 = x.at(keys_[0]); - const X2& x2 = x.at(keys_[1]); - if(H) { - return evaluateError(x1, x2, (*H)[0], (*H)[1]); - } else { - return evaluateError(x1, x2); - } - } else { - return Vector::Zero(this->dim()); - } - } - - /** - * Override this method to finish implementing a binary factor. - * If any of the optional Matrix reference arguments are specified, it should compute - * both the function evaluation and its derivative(s) in X1 (and/or X2). - */ - virtual Vector - evaluateError(const X1&, const X2&, boost::optional H1 = - boost::none, boost::optional H2 = boost::none) const = 0; - -private: + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + private: /** Serialization function */ friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); } -}; // \class NoiseModelFactor2 +}; // \class NoiseModelFactor2 /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 3 * variables. To derive from this class, implement evaluateError(). */ -template -class NoiseModelFactor3: public NoiseModelFactor { - -public: - - // typedefs for value types pulled from keys - typedef VALUE1 X1; - typedef VALUE2 X2; - typedef VALUE3 X3; - -protected: - - typedef NoiseModelFactor Base; - typedef NoiseModelFactor3 This; - -public: - - /** - * Default Constructor for I/O - */ - NoiseModelFactor3() {} +template +class NoiseModelFactor3 : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; - /** - * Constructor - * @param noiseModel shared pointer to noise model - * @param j1 key of the first variable - * @param j2 key of the second variable - * @param j3 key of the third variable - */ - NoiseModelFactor3(const SharedNoiseModel& noiseModel, Key j1, Key j2, Key j3) : - Base(noiseModel, cref_list_of<3>(j1)(j2)(j3)) {} + protected: + using Base = NoiseModelFactor; + using This = NoiseModelFactor3; + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor3() override {} /** methods to retrieve keys */ - inline Key key1() const { return keys_[0]; } - inline Key key2() const { return keys_[1]; } - inline Key key3() const { return keys_[2]; } - - /** Calls the 3-key specific version of evaluateError, which is pure virtual - * so must be implemented in the derived class. */ - Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const override { - if(this->active(x)) { - if(H) - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), (*H)[0], (*H)[1], (*H)[2]); - else - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2])); - } else { - return Vector::Zero(this->dim()); - } - } - - /** - * Override this method to finish implementing a trinary factor. - * If any of the optional Matrix reference arguments are specified, it should compute - * both the function evaluation and its derivative(s) in X1 (and/or X2, X3). - */ - virtual Vector - evaluateError(const X1&, const X2&, const X3&, - boost::optional H1 = boost::none, - boost::optional H2 = boost::none, - boost::optional H3 = boost::none) const = 0; - -private: + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + private: /** Serialization function */ friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); } -}; // \class NoiseModelFactor3 +}; // \class NoiseModelFactor3 /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 4 @@ -687,7 +547,7 @@ class NoiseModelFactor4 using X4 = VALUE4; protected: - using Base = NoiseModelFactor; // grandparent, for backwards compatibility + using Base = NoiseModelFactor; using This = NoiseModelFactor4; public: @@ -714,175 +574,87 @@ class NoiseModelFactor4 /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 5 * variables. To derive from this class, implement evaluateError(). */ -template -class NoiseModelFactor5: public NoiseModelFactor { - -public: - - // typedefs for value types pulled from keys - typedef VALUE1 X1; - typedef VALUE2 X2; - typedef VALUE3 X3; - typedef VALUE4 X4; - typedef VALUE5 X5; - -protected: - - typedef NoiseModelFactor Base; - typedef NoiseModelFactor5 This; - -public: - - /** - * Default Constructor for I/O - */ - NoiseModelFactor5() {} +template +class NoiseModelFactor5 + : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; + using X4 = VALUE4; + using X5 = VALUE5; - /** - * Constructor - * @param noiseModel shared pointer to noise model - * @param j1 key of the first variable - * @param j2 key of the second variable - * @param j3 key of the third variable - * @param j4 key of the fourth variable - * @param j5 key of the fifth variable - */ - NoiseModelFactor5(const SharedNoiseModel& noiseModel, Key j1, Key j2, Key j3, Key j4, Key j5) : - Base(noiseModel, cref_list_of<5>(j1)(j2)(j3)(j4)(j5)) {} + protected: + using Base = NoiseModelFactor; + using This = NoiseModelFactor5; + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor5() override {} /** methods to retrieve keys */ - inline Key key1() const { return keys_[0]; } - inline Key key2() const { return keys_[1]; } - inline Key key3() const { return keys_[2]; } - inline Key key4() const { return keys_[3]; } - inline Key key5() const { return keys_[4]; } - - /** Calls the 5-key specific version of evaluateError, which is pure virtual - * so must be implemented in the derived class. */ - Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const override { - if(this->active(x)) { - if(H) - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), x.at(keys_[4]), (*H)[0], (*H)[1], (*H)[2], (*H)[3], (*H)[4]); - else - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), x.at(keys_[4])); - } else { - return Vector::Zero(this->dim()); - } - } - - /** - * Override this method to finish implementing a 5-way factor. - * If any of the optional Matrix reference arguments are specified, it should compute - * both the function evaluation and its derivative(s) in X1 (and/or X2, X3). - */ - virtual Vector - evaluateError(const X1&, const X2&, const X3&, const X4&, const X5&, - boost::optional H1 = boost::none, - boost::optional H2 = boost::none, - boost::optional H3 = boost::none, - boost::optional H4 = boost::none, - boost::optional H5 = boost::none) const = 0; - -private: + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + inline Key key4() const { return this->keys_[3]; } + inline Key key5() const { return this->keys_[4]; } + private: /** Serialization function */ friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); } -}; // \class NoiseModelFactor5 +}; // \class NoiseModelFactor5 /* ************************************************************************* */ /** A convenient base class for creating your own NoiseModelFactor with 6 * variables. To derive from this class, implement evaluateError(). */ -template -class NoiseModelFactor6: public NoiseModelFactor { - -public: - - // typedefs for value types pulled from keys - typedef VALUE1 X1; - typedef VALUE2 X2; - typedef VALUE3 X3; - typedef VALUE4 X4; - typedef VALUE5 X5; - typedef VALUE6 X6; - -protected: - - typedef NoiseModelFactor Base; - typedef NoiseModelFactor6 This; - -public: - - /** - * Default Constructor for I/O - */ - NoiseModelFactor6() {} +template +class NoiseModelFactor6 + : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; + using X4 = VALUE4; + using X5 = VALUE5; + using X6 = VALUE6; - /** - * Constructor - * @param noiseModel shared pointer to noise model - * @param j1 key of the first variable - * @param j2 key of the second variable - * @param j3 key of the third variable - * @param j4 key of the fourth variable - * @param j5 key of the fifth variable - * @param j6 key of the fifth variable - */ - NoiseModelFactor6(const SharedNoiseModel& noiseModel, Key j1, Key j2, Key j3, Key j4, Key j5, Key j6) : - Base(noiseModel, cref_list_of<6>(j1)(j2)(j3)(j4)(j5)(j6)) {} + protected: + using Base = NoiseModelFactor; + using This = + NoiseModelFactor6; + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor6() override {} /** methods to retrieve keys */ - inline Key key1() const { return keys_[0]; } - inline Key key2() const { return keys_[1]; } - inline Key key3() const { return keys_[2]; } - inline Key key4() const { return keys_[3]; } - inline Key key5() const { return keys_[4]; } - inline Key key6() const { return keys_[5]; } - - /** Calls the 6-key specific version of evaluateError, which is pure virtual - * so must be implemented in the derived class. */ - Vector unwhitenedError(const Values& x, boost::optional&> H = boost::none) const override { - if(this->active(x)) { - if(H) - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), x.at(keys_[4]), x.at(keys_[5]), (*H)[0], (*H)[1], (*H)[2], (*H)[3], (*H)[4], (*H)[5]); - else - return evaluateError(x.at(keys_[0]), x.at(keys_[1]), x.at(keys_[2]), x.at(keys_[3]), x.at(keys_[4]), x.at(keys_[5])); - } else { - return Vector::Zero(this->dim()); - } - } - - /** - * Override this method to finish implementing a 6-way factor. - * If any of the optional Matrix reference arguments are specified, it should compute - * both the function evaluation and its derivative(s) in X1 (and/or X2, X3). - */ - virtual Vector - evaluateError(const X1&, const X2&, const X3&, const X4&, const X5&, const X6&, - boost::optional H1 = boost::none, - boost::optional H2 = boost::none, - boost::optional H3 = boost::none, - boost::optional H4 = boost::none, - boost::optional H5 = boost::none, - boost::optional H6 = boost::none) const = 0; - -private: + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + inline Key key4() const { return this->keys_[3]; } + inline Key key5() const { return this->keys_[4]; } + inline Key key6() const { return this->keys_[5]; } + private: /** Serialization function */ friend class boost::serialization::access; - template - void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - ar & boost::serialization::make_nvp("NoiseModelFactor", - boost::serialization::base_object(*this)); + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); } -}; // \class NoiseModelFactor6 +}; // \class NoiseModelFactor6 } // \namespace gtsam From ea7d769476e897f786799c5f774846460e880e19 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 05:49:36 -0500 Subject: [PATCH 0010/1497] documentation --- gtsam/nonlinear/NonlinearFactor.h | 136 ++++++++++++++++++++++++------ 1 file changed, 109 insertions(+), 27 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 64ef96b854..34e891c643 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -307,19 +307,39 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { /* ************************************************************************* */ - /** - * A convenient base class for creating your own NoiseModelFactor with n - * variables. To derive from this class, implement evaluateError(). + * A convenient base class for creating your own NoiseModelFactor + * with n variables. To derive from this class, implement evaluateError(). + * + * For example, a 2-way factor could be implemented like so: + * + * ~~~~~~~~~~~~~~~~~~~~{.cpp} + * class MyFactor : public NoiseModelFactorN { + * public: + * using Base = NoiseModelFactorN; + * + * MyFactor(Key key1, Key key2, const SharedNoiseModel& noiseModel) + * : Base(noiseModel, key1, key2) {} * - * Templated on a values structure type. The values structures are typically - * more general than just vectors, e.g., Rot3 or Pose3, - * which are objects in non-linear manifolds (Lie groups). + * Vector evaluateError( + * const double& x1, const double& x2, + * boost::optional H1 = boost::none, + * boost::optional H2 = boost::none) const override { + * if (H1) *H1 = (Matrix(1, 1) << 1.0).finished(); + * if (H2) *H2 = (Matrix(1, 1) << 2.0).finished(); + * return (Vector(1) << x1 + 2 * x2).finished(); + * } + * }; + * ~~~~~~~~~~~~~~~~~~~~ + * + * These factors are templated on a values structure type. The values structures + * are typically more general than just vectors, e.g., Rot3 or Pose3, which are + * objects in non-linear manifolds (Lie groups). */ template class NoiseModelFactorN : public NoiseModelFactor { public: - /** The type of the N'th template param can be obtained with VALUE */ + /** The type of the N'th template param can be obtained as VALUE */ template using VALUE = typename std::tuple_element>::type; @@ -338,6 +358,9 @@ class NoiseModelFactorN : public NoiseModelFactor { using key_type = Key; public: + /// @name Constructors + /// @{ + /** * Default Constructor for I/O */ @@ -346,8 +369,9 @@ class NoiseModelFactorN : public NoiseModelFactor { /** * Constructor. * Example usage: NoiseModelFactorN(noise, key1, key2, ..., keyN) - * @param noiseModel shared pointer to noise model - * @param keys... keys for the variables in this factor + * @param noiseModel Shared pointer to noise model. + * @param keys Keys for the variables in this factor, passed in as separate + * arguments. */ NoiseModelFactorN(const SharedNoiseModel& noiseModel, key_type... keys) @@ -355,8 +379,8 @@ class NoiseModelFactorN : public NoiseModelFactor { /** * Constructor. - * @param noiseModel shared pointer to noise model - * @param keys a container of keys for the variables in this factor + * @param noiseModel Shared pointer to noise model. + * @param keys A container of keys for the variables in this factor. */ template NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys) @@ -364,6 +388,8 @@ class NoiseModelFactorN : public NoiseModelFactor { assert(keys.size() == sizeof...(VALUES)); } + /// @} + ~NoiseModelFactorN() override {} /** Method to retrieve keys */ @@ -372,26 +398,59 @@ class NoiseModelFactorN : public NoiseModelFactor { return keys_[N]; } + /// @name NoiseModelFactor methods + /// @{ + /** Calls the n-key specific version of evaluateError, which is pure virtual - * so must be implemented in the derived class. */ + * so must be implemented in the derived class. + * @param[in] x A Values object containing the values of all the variables + * used in this factor + * @param[out] H A vector of (dynamic) matrices whose size should be equal to + * n. The jacobians w.r.t. each variable will be output in this parameter. + */ Vector unwhitenedError( const Values& x, boost::optional&> H = boost::none) const override { return unwhitenedError(boost::mp11::index_sequence_for{}, x, H); } + /// @} + /// @name Virtual methods + /// @{ /** * Override this method to finish implementing an n-way factor. + * + * Both the `x` and `H` arguments are written here as parameter packs, but + * when overriding this method, you probably want to explicitly write them + * out. For example, for a 2-way factor with variable types Pose3 and double: + * ``` + * Vector evaluateError(const Pose3& x1, const double& x2, + * boost::optional H1 = boost::none, + * boost::optional H2 = boost::none) const + * override {...} + * ``` + * * If any of the optional Matrix reference arguments are specified, it should * compute both the function evaluation and its derivative(s) in the requested * variables. + * + * @param x The values of the variables to evaluate the error for. Passed in + * as separate arguments. + * @param[out] H The Jacobian with respect to each variable (optional). */ virtual Vector evaluateError(const VALUES&... x, optional_matrix_type... H) const = 0; + /// @} + /// @name Convenience method overloads + /// @{ + /** No-jacobians requested function overload (since parameter packs can't have * default args). This specializes the version below to avoid recursive calls - * since this is commonly used. */ + * since this is commonly used. + * + * e.g. `Vector error = factor.evaluateError(x1, x2, x3);` + */ inline Vector evaluateError(const VALUES&... x) const { return evaluateError(x..., optional_matrix_type()...); } @@ -408,10 +467,14 @@ class NoiseModelFactorN : public NoiseModelFactor { boost::none); } + /// @} + private: - /** Pack expansion with index_sequence template pattern */ + /** Pack expansion with index_sequence template pattern, used to index into + * `keys_` and `H` + */ template - Vector unwhitenedError( + inline Vector unwhitenedError( boost::mp11::index_sequence, // const Values& x, boost::optional&> H = boost::none) const { @@ -436,8 +499,11 @@ class NoiseModelFactorN : public NoiseModelFactor { }; // \class NoiseModelFactorN /* ************************************************************************* */ -/** A convenient base class for creating your own NoiseModelFactor with 1 - * variable. To derive from this class, implement evaluateError(). */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with VALUE<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 1 variable. To derive from this class, implement evaluateError(). + */ template class NoiseModelFactor1 : public NoiseModelFactorN { public: @@ -453,6 +519,7 @@ class NoiseModelFactor1 : public NoiseModelFactorN { using NoiseModelFactorN::NoiseModelFactorN; ~NoiseModelFactor1() override {} + /** method to retrieve key */ inline Key key() const { return this->keys_[0]; } private: @@ -466,8 +533,11 @@ class NoiseModelFactor1 : public NoiseModelFactorN { }; // \class NoiseModelFactor1 /* ************************************************************************* */ -/** A convenient base class for creating your own NoiseModelFactor with 2 - * variables. To derive from this class, implement evaluateError(). */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with VALUE<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 2 variables. To derive from this class, implement evaluateError(). + */ template class NoiseModelFactor2 : public NoiseModelFactorN { public: @@ -499,8 +569,11 @@ class NoiseModelFactor2 : public NoiseModelFactorN { }; // \class NoiseModelFactor2 /* ************************************************************************* */ -/** A convenient base class for creating your own NoiseModelFactor with 3 - * variables. To derive from this class, implement evaluateError(). */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with VALUE<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 3 variables. To derive from this class, implement evaluateError(). + */ template class NoiseModelFactor3 : public NoiseModelFactorN { public: @@ -534,8 +607,11 @@ class NoiseModelFactor3 : public NoiseModelFactorN { }; // \class NoiseModelFactor3 /* ************************************************************************* */ -/** A convenient base class for creating your own NoiseModelFactor with 4 - * variables. To derive from this class, implement evaluateError(). */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with VALUE<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 4 variables. To derive from this class, implement evaluateError(). + */ template class NoiseModelFactor4 : public NoiseModelFactorN { @@ -572,8 +648,11 @@ class NoiseModelFactor4 }; // \class NoiseModelFactor4 /* ************************************************************************* */ -/** A convenient base class for creating your own NoiseModelFactor with 5 - * variables. To derive from this class, implement evaluateError(). */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with VALUE<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 5 variables. To derive from this class, implement evaluateError(). + */ template class NoiseModelFactor5 : public NoiseModelFactorN { @@ -613,8 +692,11 @@ class NoiseModelFactor5 }; // \class NoiseModelFactor5 /* ************************************************************************* */ -/** A convenient base class for creating your own NoiseModelFactor with 6 - * variables. To derive from this class, implement evaluateError(). */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with VALUE<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 6 variables. To derive from this class, implement evaluateError(). + */ template class NoiseModelFactor6 From ba3cc85701aaee6277ae5446e98027f9a1267295 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 06:17:14 -0500 Subject: [PATCH 0011/1497] avoid inheritance by conditionally defining backwards compatibility types/funcs in NoiseModelFactorN --- gtsam/nonlinear/NonlinearFactor.h | 624 ++++++++++++++++++------------ tests/testNonlinearFactor.cpp | 44 +++ 2 files changed, 414 insertions(+), 254 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 34e891c643..764f1fdf98 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -306,6 +306,76 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { }; // \class NoiseModelFactor +/* ************************************************************************* */ +/* We need some helper structs to help us with NoiseModelFactorN - specifically + * we need to alias X1, X2, X3, ... in the templated NoiseModelFactorN class to + * maintain backwards compatibility with NoiseModelFactor1, NoiseModelFactor2, + * NoiseModelFactor3, ... + * + * The tricky part is that we want to _conditionally_ alias these only if the + * `sizeof...(VALUES)` is greater than the index we want to alias (e.g. a 3-way + * factor should only have up to X3). + * + * The approach we use is to create structs which use template specialization to + * conditionally typedef X1, X2, ... for us, then inherit from them to inherit + * the aliases. + * + * Usage: + * ``` + * template + * class MyClass : public AliasX3 { ... }; + * ``` + * This will only typedef X3 if VALUES has at least 3 template parameters. So + * then we can do something like: + * ``` + * int main { + * MyClass::X3 a; // variable a will have type double + * // MyClass::X3 b; // this won't compile + * MyClass::X3 c; // variable c will have type char + * } + * ``` + */ + +// convenience macro extracts the type for the i'th VALUE in a parameter pack +#define GET_VALUE_I(VALUES, I) \ + typename std::tuple_element>::type + +namespace detail { + +// First handle `typedef X`. By default, we do not alias X (empty struct). +template +struct AliasX_ {}; +// But if `1 == sizeof...(VALUES)` is true, then we do alias X by specializing +// for when the first template parameter is true. +template +struct AliasX_<(1 == sizeof...(VALUES)), VALUES...> { + using X = GET_VALUE_I(VALUES, 0); +}; +// We'll alias the "true" template version for convenience. +template +using AliasX = AliasX_; + +// Now do the same thing for X1, X2, ... using a macro. +#define ALIAS_HELPER_X(N) \ + template \ + struct AliasX##N##_ {}; \ + template \ + struct AliasX##N##_<(N <= sizeof...(VALUES)), VALUES...> { \ + using X##N = GET_VALUE_I(VALUES, N - 1); \ + }; \ + template \ + using AliasX##N = AliasX##N##_; +ALIAS_HELPER_X(1); +ALIAS_HELPER_X(2); +ALIAS_HELPER_X(3); +ALIAS_HELPER_X(4); +ALIAS_HELPER_X(5); +ALIAS_HELPER_X(6); +#undef ALIAS_HELPER_X +#undef GET_VALUE_I + +} // namespace detail + /* ************************************************************************* */ /** * A convenient base class for creating your own NoiseModelFactor @@ -337,11 +407,21 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { * objects in non-linear manifolds (Lie groups). */ template -class NoiseModelFactorN : public NoiseModelFactor { +class NoiseModelFactorN : public NoiseModelFactor, + public detail::AliasX, + public detail::AliasX1, + public detail::AliasX2, + public detail::AliasX3, + public detail::AliasX4, + public detail::AliasX5, + public detail::AliasX6 { public: - /** The type of the N'th template param can be obtained as VALUE */ - template - using VALUE = typename std::tuple_element>::type; + /// N is the number of variables (N-way factor) + enum { N = sizeof...(VALUES) }; + + /** The type of the i'th template param can be obtained as VALUE */ + template ::type = true> + using VALUE = typename std::tuple_element>::type; protected: using Base = NoiseModelFactor; @@ -375,28 +455,42 @@ class NoiseModelFactorN : public NoiseModelFactor { */ NoiseModelFactorN(const SharedNoiseModel& noiseModel, key_type... keys) - : Base(noiseModel, std::array{keys...}) {} + : Base(noiseModel, std::array{keys...}) {} /** - * Constructor. + * Constructor. Only enabled for n-ary factors where n > 1. * @param noiseModel Shared pointer to noise model. * @param keys A container of keys for the variables in this factor. */ - template + template 1), bool>::type = true> NoiseModelFactorN(const SharedNoiseModel& noiseModel, CONTAINER keys) : Base(noiseModel, keys) { - assert(keys.size() == sizeof...(VALUES)); + assert(keys.size() == N); } /// @} ~NoiseModelFactorN() override {} - /** Method to retrieve keys */ - template - inline Key key() const { - return keys_[N]; + /** Methods to retrieve keys */ +#define SUB(Old, New) template // to delay template deduction +#define KEY_IF_TRUE(Enable) typename std::enable_if<(Enable), Key>::type + // templated version of `key()` + template + inline KEY_IF_TRUE(I < N) key() const { + return keys_[I]; } + // backwards-compatibility functions + SUB(T, N) inline KEY_IF_TRUE(T == 1) key() const { return keys_[0]; } + SUB(T, N) inline KEY_IF_TRUE(T >= 1) key1() const { return keys_[0]; } + SUB(T, N) inline KEY_IF_TRUE(T >= 2) key2() const { return keys_[1]; } + SUB(T, N) inline KEY_IF_TRUE(T >= 3) key3() const { return keys_[2]; } + SUB(T, N) inline KEY_IF_TRUE(T >= 4) key4() const { return keys_[3]; } + SUB(T, N) inline KEY_IF_TRUE(T >= 5) key5() const { return keys_[4]; } + SUB(T, N) inline KEY_IF_TRUE(T >= 6) key6() const { return keys_[5]; } +#undef SUB +#undef KEY_IF_TRUE /// @name NoiseModelFactor methods /// @{ @@ -458,8 +552,7 @@ class NoiseModelFactorN : public NoiseModelFactor { /** Some optional jacobians omitted function overload */ template 0) && - (sizeof...(OptionalJacArgs) < - sizeof...(VALUES)), + (sizeof...(OptionalJacArgs) < N), bool>::type = true> inline Vector evaluateError(const VALUES&... x, OptionalJacArgs&&... H) const { @@ -498,245 +591,268 @@ class NoiseModelFactorN : public NoiseModelFactor { } }; // \class NoiseModelFactorN -/* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with VALUE<1>. - * A convenient base class for creating your own NoiseModelFactor - * with 1 variable. To derive from this class, implement evaluateError(). - */ -template -class NoiseModelFactor1 : public NoiseModelFactorN { - public: - // aliases for value types pulled from keys - using X = VALUE; - - protected: - using Base = NoiseModelFactor; // grandparent, for backwards compatibility - using This = NoiseModelFactor1; - - public: - // inherit NoiseModelFactorN's constructors - using NoiseModelFactorN::NoiseModelFactorN; - ~NoiseModelFactor1() override {} - - /** method to retrieve key */ - inline Key key() const { return this->keys_[0]; } - - private: - /** Serialization function */ - friend class boost::serialization::access; - template - void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - ar& boost::serialization::make_nvp( - "NoiseModelFactor", boost::serialization::base_object(*this)); - } -}; // \class NoiseModelFactor1 - -/* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with VALUE<1>. - * A convenient base class for creating your own NoiseModelFactor - * with 2 variables. To derive from this class, implement evaluateError(). - */ -template -class NoiseModelFactor2 : public NoiseModelFactorN { - public: - // aliases for value types pulled from keys - using X1 = VALUE1; - using X2 = VALUE2; - - protected: - using Base = NoiseModelFactor; - using This = NoiseModelFactor2; - - public: - // inherit NoiseModelFactorN's constructors - using NoiseModelFactorN::NoiseModelFactorN; - ~NoiseModelFactor2() override {} - - /** methods to retrieve both keys */ - inline Key key1() const { return this->keys_[0]; } - inline Key key2() const { return this->keys_[1]; } - - private: - /** Serialization function */ - friend class boost::serialization::access; - template - void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - ar& boost::serialization::make_nvp( - "NoiseModelFactor", boost::serialization::base_object(*this)); - } -}; // \class NoiseModelFactor2 - -/* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with VALUE<1>. - * A convenient base class for creating your own NoiseModelFactor - * with 3 variables. To derive from this class, implement evaluateError(). - */ -template -class NoiseModelFactor3 : public NoiseModelFactorN { - public: - // aliases for value types pulled from keys - using X1 = VALUE1; - using X2 = VALUE2; - using X3 = VALUE3; - - protected: - using Base = NoiseModelFactor; - using This = NoiseModelFactor3; - - public: - // inherit NoiseModelFactorN's constructors - using NoiseModelFactorN::NoiseModelFactorN; - ~NoiseModelFactor3() override {} - - /** methods to retrieve keys */ - inline Key key1() const { return this->keys_[0]; } - inline Key key2() const { return this->keys_[1]; } - inline Key key3() const { return this->keys_[2]; } - - private: - /** Serialization function */ - friend class boost::serialization::access; - template - void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - ar& boost::serialization::make_nvp( - "NoiseModelFactor", boost::serialization::base_object(*this)); - } -}; // \class NoiseModelFactor3 - -/* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with VALUE<1>. - * A convenient base class for creating your own NoiseModelFactor - * with 4 variables. To derive from this class, implement evaluateError(). - */ -template -class NoiseModelFactor4 - : public NoiseModelFactorN { - public: - // aliases for value types pulled from keys - using X1 = VALUE1; - using X2 = VALUE2; - using X3 = VALUE3; - using X4 = VALUE4; - - protected: - using Base = NoiseModelFactor; - using This = NoiseModelFactor4; - - public: - // inherit NoiseModelFactorN's constructors - using NoiseModelFactorN::NoiseModelFactorN; - ~NoiseModelFactor4() override {} - - /** methods to retrieve keys */ - inline Key key1() const { return this->keys_[0]; } - inline Key key2() const { return this->keys_[1]; } - inline Key key3() const { return this->keys_[2]; } - inline Key key4() const { return this->keys_[3]; } - - private: - /** Serialization function */ - friend class boost::serialization::access; - template - void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - ar& boost::serialization::make_nvp( - "NoiseModelFactor", boost::serialization::base_object(*this)); - } -}; // \class NoiseModelFactor4 - -/* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with VALUE<1>. - * A convenient base class for creating your own NoiseModelFactor - * with 5 variables. To derive from this class, implement evaluateError(). - */ -template -class NoiseModelFactor5 - : public NoiseModelFactorN { - public: - // aliases for value types pulled from keys - using X1 = VALUE1; - using X2 = VALUE2; - using X3 = VALUE3; - using X4 = VALUE4; - using X5 = VALUE5; - - protected: - using Base = NoiseModelFactor; - using This = NoiseModelFactor5; - - public: - // inherit NoiseModelFactorN's constructors - using NoiseModelFactorN::NoiseModelFactorN; - ~NoiseModelFactor5() override {} - - /** methods to retrieve keys */ - inline Key key1() const { return this->keys_[0]; } - inline Key key2() const { return this->keys_[1]; } - inline Key key3() const { return this->keys_[2]; } - inline Key key4() const { return this->keys_[3]; } - inline Key key5() const { return this->keys_[4]; } - - private: - /** Serialization function */ - friend class boost::serialization::access; - template - void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - ar& boost::serialization::make_nvp( - "NoiseModelFactor", boost::serialization::base_object(*this)); - } -}; // \class NoiseModelFactor5 - -/* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 - * with VALUE<1>. - * A convenient base class for creating your own NoiseModelFactor - * with 6 variables. To derive from this class, implement evaluateError(). - */ -template -class NoiseModelFactor6 - : public NoiseModelFactorN { - public: - // aliases for value types pulled from keys - using X1 = VALUE1; - using X2 = VALUE2; - using X3 = VALUE3; - using X4 = VALUE4; - using X5 = VALUE5; - using X6 = VALUE6; - - protected: - using Base = NoiseModelFactor; - using This = - NoiseModelFactor6; - - public: - // inherit NoiseModelFactorN's constructors - using NoiseModelFactorN::NoiseModelFactorN; - ~NoiseModelFactor6() override {} - - /** methods to retrieve keys */ - inline Key key1() const { return this->keys_[0]; } - inline Key key2() const { return this->keys_[1]; } - inline Key key3() const { return this->keys_[2]; } - inline Key key4() const { return this->keys_[3]; } - inline Key key5() const { return this->keys_[4]; } - inline Key key6() const { return this->keys_[5]; } - - private: - /** Serialization function */ - friend class boost::serialization::access; - template - void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - ar& boost::serialization::make_nvp( - "NoiseModelFactor", boost::serialization::base_object(*this)); - } -}; // \class NoiseModelFactor6 +// template +// using NoiseModelFactor1 = NoiseModelFactorN; +// template +// using NoiseModelFactor2 = NoiseModelFactorN; +// template +// using NoiseModelFactor3 = NoiseModelFactorN; +// template +// using NoiseModelFactor4 = NoiseModelFactorN; +// template +// using NoiseModelFactor5 = +// NoiseModelFactorN; +// template +// using NoiseModelFactor6 = +// NoiseModelFactorN; + +#define NoiseModelFactor1 NoiseModelFactorN +#define NoiseModelFactor2 NoiseModelFactorN +#define NoiseModelFactor3 NoiseModelFactorN +#define NoiseModelFactor4 NoiseModelFactorN +#define NoiseModelFactor5 NoiseModelFactorN +#define NoiseModelFactor6 NoiseModelFactorN + +// /* ************************************************************************* */ +// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 +// * with VALUE<1>. +// * A convenient base class for creating your own NoiseModelFactor +// * with 1 variable. To derive from this class, implement evaluateError(). +// */ +// template +// class NoiseModelFactor1 : public NoiseModelFactorN { +// public: +// // aliases for value types pulled from keys +// using X = VALUE; + +// protected: +// using Base = NoiseModelFactor; // grandparent, for backwards compatibility +// using This = NoiseModelFactor1; + +// public: +// // inherit NoiseModelFactorN's constructors +// using NoiseModelFactorN::NoiseModelFactorN; +// ~NoiseModelFactor1() override {} + +// /** method to retrieve key */ +// inline Key key() const { return this->keys_[0]; } + +// private: +// /** Serialization function */ +// friend class boost::serialization::access; +// template +// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { +// ar& boost::serialization::make_nvp( +// "NoiseModelFactor", boost::serialization::base_object(*this)); +// } +// }; // \class NoiseModelFactor1 + +// /* ************************************************************************* */ +// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 +// * with VALUE<1>. +// * A convenient base class for creating your own NoiseModelFactor +// * with 2 variables. To derive from this class, implement evaluateError(). +// */ +// template +// class NoiseModelFactor2 : public NoiseModelFactorN { +// public: +// // aliases for value types pulled from keys +// using X1 = VALUE1; +// using X2 = VALUE2; + +// protected: +// using Base = NoiseModelFactor; +// using This = NoiseModelFactor2; + +// public: +// // inherit NoiseModelFactorN's constructors +// using NoiseModelFactorN::NoiseModelFactorN; +// ~NoiseModelFactor2() override {} + +// /** methods to retrieve both keys */ +// inline Key key1() const { return this->keys_[0]; } +// inline Key key2() const { return this->keys_[1]; } + +// private: +// /** Serialization function */ +// friend class boost::serialization::access; +// template +// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { +// ar& boost::serialization::make_nvp( +// "NoiseModelFactor", boost::serialization::base_object(*this)); +// } +// }; // \class NoiseModelFactor2 + +// /* ************************************************************************* */ +// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 +// * with VALUE<1>. +// * A convenient base class for creating your own NoiseModelFactor +// * with 3 variables. To derive from this class, implement evaluateError(). +// */ +// template +// class NoiseModelFactor3 : public NoiseModelFactorN { +// public: +// // aliases for value types pulled from keys +// using X1 = VALUE1; +// using X2 = VALUE2; +// using X3 = VALUE3; + +// protected: +// using Base = NoiseModelFactor; +// using This = NoiseModelFactor3; + +// public: +// // inherit NoiseModelFactorN's constructors +// using NoiseModelFactorN::NoiseModelFactorN; +// ~NoiseModelFactor3() override {} + +// /** methods to retrieve keys */ +// inline Key key1() const { return this->keys_[0]; } +// inline Key key2() const { return this->keys_[1]; } +// inline Key key3() const { return this->keys_[2]; } + +// private: +// /** Serialization function */ +// friend class boost::serialization::access; +// template +// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { +// ar& boost::serialization::make_nvp( +// "NoiseModelFactor", boost::serialization::base_object(*this)); +// } +// }; // \class NoiseModelFactor3 + +// /* ************************************************************************* */ +// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 +// * with VALUE<1>. +// * A convenient base class for creating your own NoiseModelFactor +// * with 4 variables. To derive from this class, implement evaluateError(). +// */ +// template +// class NoiseModelFactor4 +// : public NoiseModelFactorN { +// public: +// // aliases for value types pulled from keys +// using X1 = VALUE1; +// using X2 = VALUE2; +// using X3 = VALUE3; +// using X4 = VALUE4; + +// protected: +// using Base = NoiseModelFactor; +// using This = NoiseModelFactor4; + +// public: +// // inherit NoiseModelFactorN's constructors +// using NoiseModelFactorN::NoiseModelFactorN; +// ~NoiseModelFactor4() override {} + +// /** methods to retrieve keys */ +// inline Key key1() const { return this->keys_[0]; } +// inline Key key2() const { return this->keys_[1]; } +// inline Key key3() const { return this->keys_[2]; } +// inline Key key4() const { return this->keys_[3]; } + +// private: +// /** Serialization function */ +// friend class boost::serialization::access; +// template +// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { +// ar& boost::serialization::make_nvp( +// "NoiseModelFactor", boost::serialization::base_object(*this)); +// } +// }; // \class NoiseModelFactor4 + +// /* ************************************************************************* */ +// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 +// * with VALUE<1>. +// * A convenient base class for creating your own NoiseModelFactor +// * with 5 variables. To derive from this class, implement evaluateError(). +// */ +// template +// class NoiseModelFactor5 +// : public NoiseModelFactorN { +// public: +// // aliases for value types pulled from keys +// using X1 = VALUE1; +// using X2 = VALUE2; +// using X3 = VALUE3; +// using X4 = VALUE4; +// using X5 = VALUE5; + +// protected: +// using Base = NoiseModelFactor; +// using This = NoiseModelFactor5; + +// public: +// // inherit NoiseModelFactorN's constructors +// using NoiseModelFactorN::NoiseModelFactorN; +// ~NoiseModelFactor5() override {} + +// /** methods to retrieve keys */ +// inline Key key1() const { return this->keys_[0]; } +// inline Key key2() const { return this->keys_[1]; } +// inline Key key3() const { return this->keys_[2]; } +// inline Key key4() const { return this->keys_[3]; } +// inline Key key5() const { return this->keys_[4]; } + +// private: +// /** Serialization function */ +// friend class boost::serialization::access; +// template +// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { +// ar& boost::serialization::make_nvp( +// "NoiseModelFactor", boost::serialization::base_object(*this)); +// } +// }; // \class NoiseModelFactor5 + +// /* ************************************************************************* */ +// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 +// * with VALUE<1>. +// * A convenient base class for creating your own NoiseModelFactor +// * with 6 variables. To derive from this class, implement evaluateError(). +// */ +// template +// class NoiseModelFactor6 +// : public NoiseModelFactorN { +// public: +// // aliases for value types pulled from keys +// using X1 = VALUE1; +// using X2 = VALUE2; +// using X3 = VALUE3; +// using X4 = VALUE4; +// using X5 = VALUE5; +// using X6 = VALUE6; + +// protected: +// using Base = NoiseModelFactor; +// using This = +// NoiseModelFactor6; + +// public: +// // inherit NoiseModelFactorN's constructors +// using NoiseModelFactorN::NoiseModelFactorN; +// ~NoiseModelFactor6() override {} + +// /** methods to retrieve keys */ +// inline Key key1() const { return this->keys_[0]; } +// inline Key key2() const { return this->keys_[1]; } +// inline Key key3() const { return this->keys_[2]; } +// inline Key key4() const { return this->keys_[3]; } +// inline Key key5() const { return this->keys_[4]; } +// inline Key key6() const { return this->keys_[5]; } + +// private: +// /** Serialization function */ +// friend class boost::serialization::access; +// template +// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { +// ar& boost::serialization::make_nvp( +// "NoiseModelFactor", boost::serialization::base_object(*this)); +// } +// }; // \class NoiseModelFactor6 } // \namespace gtsam diff --git a/tests/testNonlinearFactor.cpp b/tests/testNonlinearFactor.cpp index fda65d56a3..fba7949a12 100644 --- a/tests/testNonlinearFactor.cpp +++ b/tests/testNonlinearFactor.cpp @@ -253,6 +253,50 @@ TEST( NonlinearFactor, cloneWithNewNoiseModel ) CHECK(assert_equal(expected, actual)); } +/* ************************************************************************* */ +class TestFactor1 : public NoiseModelFactor1 { + static_assert(std::is_same::value, "Base type wrong"); + static_assert(std::is_same>::value, + "This type wrong"); + + public: + typedef NoiseModelFactor1 Base; + TestFactor1() : Base(noiseModel::Diagonal::Sigmas(Vector1(2.0)), L(1)) {} + + Vector evaluateError(const double& x1, boost::optional H1 = + boost::none) const override { + if (H1) *H1 = (Matrix(1, 1) << 1.0).finished(); + return (Vector(1) << x1).finished(); + } + + gtsam::NonlinearFactor::shared_ptr clone() const override { + return boost::static_pointer_cast( + gtsam::NonlinearFactor::shared_ptr(new TestFactor1(*this))); + } +}; + +/* ************************************ */ +TEST(NonlinearFactor, NoiseModelFactor1) { + TestFactor1 tf; + Values tv; + tv.insert(L(1), double((1.0))); + EXPECT(assert_equal((Vector(1) << 1.0).finished(), tf.unwhitenedError(tv))); + DOUBLES_EQUAL(0.25 / 2.0, tf.error(tv), 1e-9); + JacobianFactor jf( + *boost::dynamic_pointer_cast(tf.linearize(tv))); + LONGS_EQUAL((long)L(1), (long)jf.keys()[0]); + EXPECT(assert_equal((Matrix)(Matrix(1, 1) << 0.5).finished(), + jf.getA(jf.begin()))); + EXPECT(assert_equal((Vector)(Vector(1) << -0.5).finished(), jf.getb())); + + // Test all functions/types for backwards compatibility + static_assert(std::is_same::value, + "X type incorrect"); + EXPECT(assert_equal(tf.key(), L(1))); + std::vector H = {Matrix()}; + EXPECT(assert_equal(Vector1(1.0), tf.unwhitenedError(tv, H))); +} + /* ************************************************************************* */ class TestFactor4 : public NoiseModelFactor4 { static_assert(std::is_same::value, "Base type wrong"); From ddcca4cdae0220bcbfa299837bbbe68099062f15 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 06:46:26 -0500 Subject: [PATCH 0012/1497] switch template bool specialization order --- gtsam/nonlinear/NonlinearFactor.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 764f1fdf98..b925916bb2 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -314,7 +314,8 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { * * The tricky part is that we want to _conditionally_ alias these only if the * `sizeof...(VALUES)` is greater than the index we want to alias (e.g. a 3-way - * factor should only have up to X3). + * factor should only have up to X3). SFINAE doesn't work in this case with + * aliases so we have to come up with a different approach. * * The approach we use is to create structs which use template specialization to * conditionally typedef X1, X2, ... for us, then inherit from them to inherit @@ -345,26 +346,26 @@ namespace detail { // First handle `typedef X`. By default, we do not alias X (empty struct). template struct AliasX_ {}; -// But if `1 == sizeof...(VALUES)` is true, then we do alias X by specializing -// for when the first template parameter is true. +// But if the first template is true, then we do alias X by specializing. template -struct AliasX_<(1 == sizeof...(VALUES)), VALUES...> { +struct AliasX_ { using X = GET_VALUE_I(VALUES, 0); }; -// We'll alias the "true" template version for convenience. +// We'll alias (for convenience) the correct version based on whether or not +// `1 == sizeof...(VALUES)` is true template -using AliasX = AliasX_; +using AliasX = AliasX_<(1 == sizeof...(VALUES)), VALUES...>; // Now do the same thing for X1, X2, ... using a macro. -#define ALIAS_HELPER_X(N) \ - template \ - struct AliasX##N##_ {}; \ - template \ - struct AliasX##N##_<(N <= sizeof...(VALUES)), VALUES...> { \ - using X##N = GET_VALUE_I(VALUES, N - 1); \ - }; \ - template \ - using AliasX##N = AliasX##N##_; +#define ALIAS_HELPER_X(N) \ + template \ + struct AliasX##N##_ {}; \ + template \ + struct AliasX##N##_ { \ + using X##N = GET_VALUE_I(VALUES, N - 1); \ + }; \ + template \ + using AliasX##N = AliasX##N##_<(N <= sizeof...(VALUES)), VALUES...>; ALIAS_HELPER_X(1); ALIAS_HELPER_X(2); ALIAS_HELPER_X(3); From 280acde2fca26ff09df8acd40b10fae0a774cd1c Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Fri, 3 Dec 2021 07:43:42 -0500 Subject: [PATCH 0013/1497] can't get "using NoiseModelFactorX = NoiseModelFactorN" to work --- gtsam/nonlinear/NonlinearFactor.h | 298 +++++------------------------- 1 file changed, 51 insertions(+), 247 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index b925916bb2..b55ec78567 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -592,6 +592,7 @@ class NoiseModelFactorN : public NoiseModelFactor, } }; // \class NoiseModelFactorN +// // `using` does not work for some reason // template // using NoiseModelFactor1 = NoiseModelFactorN; // template @@ -608,252 +609,55 @@ class NoiseModelFactorN : public NoiseModelFactor, // using NoiseModelFactor6 = // NoiseModelFactorN; -#define NoiseModelFactor1 NoiseModelFactorN -#define NoiseModelFactor2 NoiseModelFactorN -#define NoiseModelFactor3 NoiseModelFactorN -#define NoiseModelFactor4 NoiseModelFactorN -#define NoiseModelFactor5 NoiseModelFactorN -#define NoiseModelFactor6 NoiseModelFactorN - -// /* ************************************************************************* */ -// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 -// * with VALUE<1>. -// * A convenient base class for creating your own NoiseModelFactor -// * with 1 variable. To derive from this class, implement evaluateError(). -// */ -// template -// class NoiseModelFactor1 : public NoiseModelFactorN { -// public: -// // aliases for value types pulled from keys -// using X = VALUE; - -// protected: -// using Base = NoiseModelFactor; // grandparent, for backwards compatibility -// using This = NoiseModelFactor1; - -// public: -// // inherit NoiseModelFactorN's constructors -// using NoiseModelFactorN::NoiseModelFactorN; -// ~NoiseModelFactor1() override {} - -// /** method to retrieve key */ -// inline Key key() const { return this->keys_[0]; } - -// private: -// /** Serialization function */ -// friend class boost::serialization::access; -// template -// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { -// ar& boost::serialization::make_nvp( -// "NoiseModelFactor", boost::serialization::base_object(*this)); -// } -// }; // \class NoiseModelFactor1 - -// /* ************************************************************************* */ -// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 -// * with VALUE<1>. -// * A convenient base class for creating your own NoiseModelFactor -// * with 2 variables. To derive from this class, implement evaluateError(). -// */ -// template -// class NoiseModelFactor2 : public NoiseModelFactorN { -// public: -// // aliases for value types pulled from keys -// using X1 = VALUE1; -// using X2 = VALUE2; - -// protected: -// using Base = NoiseModelFactor; -// using This = NoiseModelFactor2; - -// public: -// // inherit NoiseModelFactorN's constructors -// using NoiseModelFactorN::NoiseModelFactorN; -// ~NoiseModelFactor2() override {} - -// /** methods to retrieve both keys */ -// inline Key key1() const { return this->keys_[0]; } -// inline Key key2() const { return this->keys_[1]; } - -// private: -// /** Serialization function */ -// friend class boost::serialization::access; -// template -// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { -// ar& boost::serialization::make_nvp( -// "NoiseModelFactor", boost::serialization::base_object(*this)); -// } -// }; // \class NoiseModelFactor2 - -// /* ************************************************************************* */ -// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 -// * with VALUE<1>. -// * A convenient base class for creating your own NoiseModelFactor -// * with 3 variables. To derive from this class, implement evaluateError(). -// */ -// template -// class NoiseModelFactor3 : public NoiseModelFactorN { -// public: -// // aliases for value types pulled from keys -// using X1 = VALUE1; -// using X2 = VALUE2; -// using X3 = VALUE3; - -// protected: -// using Base = NoiseModelFactor; -// using This = NoiseModelFactor3; - -// public: -// // inherit NoiseModelFactorN's constructors -// using NoiseModelFactorN::NoiseModelFactorN; -// ~NoiseModelFactor3() override {} - -// /** methods to retrieve keys */ -// inline Key key1() const { return this->keys_[0]; } -// inline Key key2() const { return this->keys_[1]; } -// inline Key key3() const { return this->keys_[2]; } - -// private: -// /** Serialization function */ -// friend class boost::serialization::access; -// template -// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { -// ar& boost::serialization::make_nvp( -// "NoiseModelFactor", boost::serialization::base_object(*this)); -// } -// }; // \class NoiseModelFactor3 - -// /* ************************************************************************* */ -// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 -// * with VALUE<1>. -// * A convenient base class for creating your own NoiseModelFactor -// * with 4 variables. To derive from this class, implement evaluateError(). -// */ -// template -// class NoiseModelFactor4 -// : public NoiseModelFactorN { -// public: -// // aliases for value types pulled from keys -// using X1 = VALUE1; -// using X2 = VALUE2; -// using X3 = VALUE3; -// using X4 = VALUE4; - -// protected: -// using Base = NoiseModelFactor; -// using This = NoiseModelFactor4; - -// public: -// // inherit NoiseModelFactorN's constructors -// using NoiseModelFactorN::NoiseModelFactorN; -// ~NoiseModelFactor4() override {} - -// /** methods to retrieve keys */ -// inline Key key1() const { return this->keys_[0]; } -// inline Key key2() const { return this->keys_[1]; } -// inline Key key3() const { return this->keys_[2]; } -// inline Key key4() const { return this->keys_[3]; } - -// private: -// /** Serialization function */ -// friend class boost::serialization::access; -// template -// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { -// ar& boost::serialization::make_nvp( -// "NoiseModelFactor", boost::serialization::base_object(*this)); -// } -// }; // \class NoiseModelFactor4 - -// /* ************************************************************************* */ -// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 -// * with VALUE<1>. -// * A convenient base class for creating your own NoiseModelFactor -// * with 5 variables. To derive from this class, implement evaluateError(). -// */ -// template -// class NoiseModelFactor5 -// : public NoiseModelFactorN { -// public: -// // aliases for value types pulled from keys -// using X1 = VALUE1; -// using X2 = VALUE2; -// using X3 = VALUE3; -// using X4 = VALUE4; -// using X5 = VALUE5; - -// protected: -// using Base = NoiseModelFactor; -// using This = NoiseModelFactor5; - -// public: -// // inherit NoiseModelFactorN's constructors -// using NoiseModelFactorN::NoiseModelFactorN; -// ~NoiseModelFactor5() override {} - -// /** methods to retrieve keys */ -// inline Key key1() const { return this->keys_[0]; } -// inline Key key2() const { return this->keys_[1]; } -// inline Key key3() const { return this->keys_[2]; } -// inline Key key4() const { return this->keys_[3]; } -// inline Key key5() const { return this->keys_[4]; } - -// private: -// /** Serialization function */ -// friend class boost::serialization::access; -// template -// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { -// ar& boost::serialization::make_nvp( -// "NoiseModelFactor", boost::serialization::base_object(*this)); -// } -// }; // \class NoiseModelFactor5 - -// /* ************************************************************************* */ -// /** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 -// * with VALUE<1>. -// * A convenient base class for creating your own NoiseModelFactor -// * with 6 variables. To derive from this class, implement evaluateError(). -// */ -// template -// class NoiseModelFactor6 -// : public NoiseModelFactorN { -// public: -// // aliases for value types pulled from keys -// using X1 = VALUE1; -// using X2 = VALUE2; -// using X3 = VALUE3; -// using X4 = VALUE4; -// using X5 = VALUE5; -// using X6 = VALUE6; - -// protected: -// using Base = NoiseModelFactor; -// using This = -// NoiseModelFactor6; - -// public: -// // inherit NoiseModelFactorN's constructors -// using NoiseModelFactorN::NoiseModelFactorN; -// ~NoiseModelFactor6() override {} - -// /** methods to retrieve keys */ -// inline Key key1() const { return this->keys_[0]; } -// inline Key key2() const { return this->keys_[1]; } -// inline Key key3() const { return this->keys_[2]; } -// inline Key key4() const { return this->keys_[3]; } -// inline Key key5() const { return this->keys_[4]; } -// inline Key key6() const { return this->keys_[5]; } - -// private: -// /** Serialization function */ -// friend class boost::serialization::access; -// template -// void serialize(ARCHIVE& ar, const unsigned int /*version*/) { -// ar& boost::serialization::make_nvp( -// "NoiseModelFactor", boost::serialization::base_object(*this)); -// } -// }; // \class NoiseModelFactor6 +// this is visually ugly +template +struct NoiseModelFactor1 : NoiseModelFactorN { + using NoiseModelFactorN::NoiseModelFactorN; + using This = NoiseModelFactor1; +}; +template +struct NoiseModelFactor2 : NoiseModelFactorN { + using NoiseModelFactorN::NoiseModelFactorN; + using This = NoiseModelFactor2; +}; +template +struct NoiseModelFactor3 : NoiseModelFactorN { + using NoiseModelFactorN::NoiseModelFactorN; + using This = NoiseModelFactor3; +}; +template +struct NoiseModelFactor4 : NoiseModelFactorN { + using NoiseModelFactorN::NoiseModelFactorN; + using This = NoiseModelFactor4; +}; +template +struct NoiseModelFactor5 + : NoiseModelFactorN { + using NoiseModelFactorN::NoiseModelFactorN; + using This = NoiseModelFactor5; +}; +template +struct NoiseModelFactor6 + : NoiseModelFactorN { + using NoiseModelFactorN::NoiseModelFactorN; + using This = + NoiseModelFactor6; +}; + +/* ************************************************************************* */ +/** @deprecated: use NoiseModelFactorN + * Convenient base classes for creating your own NoiseModelFactors with 1-6 + * variables. To derive from these classes, implement evaluateError(). + */ +// // This has the side-effect that you could e.g. NoiseModelFactor6 +// #define NoiseModelFactor1 NoiseModelFactorN +// #define NoiseModelFactor2 NoiseModelFactorN +// #define NoiseModelFactor3 NoiseModelFactorN +// #define NoiseModelFactor4 NoiseModelFactorN +// #define NoiseModelFactor5 NoiseModelFactorN +// #define NoiseModelFactor6 NoiseModelFactorN } // \namespace gtsam From 89b4340530db96c6bfbfe750fbe129c9f9e998fb Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Wed, 8 Dec 2021 18:29:52 -0500 Subject: [PATCH 0014/1497] alternate option for typedef-ing X1, X2, ... --- gtsam/nonlinear/NonlinearFactor.h | 100 ++++++------------------------ 1 file changed, 20 insertions(+), 80 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index b55ec78567..53a3e664d4 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -305,78 +305,6 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { }; // \class NoiseModelFactor - -/* ************************************************************************* */ -/* We need some helper structs to help us with NoiseModelFactorN - specifically - * we need to alias X1, X2, X3, ... in the templated NoiseModelFactorN class to - * maintain backwards compatibility with NoiseModelFactor1, NoiseModelFactor2, - * NoiseModelFactor3, ... - * - * The tricky part is that we want to _conditionally_ alias these only if the - * `sizeof...(VALUES)` is greater than the index we want to alias (e.g. a 3-way - * factor should only have up to X3). SFINAE doesn't work in this case with - * aliases so we have to come up with a different approach. - * - * The approach we use is to create structs which use template specialization to - * conditionally typedef X1, X2, ... for us, then inherit from them to inherit - * the aliases. - * - * Usage: - * ``` - * template - * class MyClass : public AliasX3 { ... }; - * ``` - * This will only typedef X3 if VALUES has at least 3 template parameters. So - * then we can do something like: - * ``` - * int main { - * MyClass::X3 a; // variable a will have type double - * // MyClass::X3 b; // this won't compile - * MyClass::X3 c; // variable c will have type char - * } - * ``` - */ - -// convenience macro extracts the type for the i'th VALUE in a parameter pack -#define GET_VALUE_I(VALUES, I) \ - typename std::tuple_element>::type - -namespace detail { - -// First handle `typedef X`. By default, we do not alias X (empty struct). -template -struct AliasX_ {}; -// But if the first template is true, then we do alias X by specializing. -template -struct AliasX_ { - using X = GET_VALUE_I(VALUES, 0); -}; -// We'll alias (for convenience) the correct version based on whether or not -// `1 == sizeof...(VALUES)` is true -template -using AliasX = AliasX_<(1 == sizeof...(VALUES)), VALUES...>; - -// Now do the same thing for X1, X2, ... using a macro. -#define ALIAS_HELPER_X(N) \ - template \ - struct AliasX##N##_ {}; \ - template \ - struct AliasX##N##_ { \ - using X##N = GET_VALUE_I(VALUES, N - 1); \ - }; \ - template \ - using AliasX##N = AliasX##N##_<(N <= sizeof...(VALUES)), VALUES...>; -ALIAS_HELPER_X(1); -ALIAS_HELPER_X(2); -ALIAS_HELPER_X(3); -ALIAS_HELPER_X(4); -ALIAS_HELPER_X(5); -ALIAS_HELPER_X(6); -#undef ALIAS_HELPER_X -#undef GET_VALUE_I - -} // namespace detail - /* ************************************************************************* */ /** * A convenient base class for creating your own NoiseModelFactor @@ -408,14 +336,7 @@ ALIAS_HELPER_X(6); * objects in non-linear manifolds (Lie groups). */ template -class NoiseModelFactorN : public NoiseModelFactor, - public detail::AliasX, - public detail::AliasX1, - public detail::AliasX2, - public detail::AliasX3, - public detail::AliasX4, - public detail::AliasX5, - public detail::AliasX6 { +class NoiseModelFactorN : public NoiseModelFactor { public: /// N is the number of variables (N-way factor) enum { N = sizeof...(VALUES) }; @@ -424,6 +345,25 @@ class NoiseModelFactorN : public NoiseModelFactor, template ::type = true> using VALUE = typename std::tuple_element>::type; + private: + template + struct VALUE_OR_VOID { + using type = void; + }; + template + struct VALUE_OR_VOID::type> { + using type = VALUE; + }; + + public: + using X = typename VALUE_OR_VOID<0>::type; + using X1 = typename VALUE_OR_VOID<0>::type; + using X2 = typename VALUE_OR_VOID<1>::type; + using X3 = typename VALUE_OR_VOID<2>::type; + using X4 = typename VALUE_OR_VOID<3>::type; + using X5 = typename VALUE_OR_VOID<4>::type; + using X6 = typename VALUE_OR_VOID<5>::type; + protected: using Base = NoiseModelFactor; using This = NoiseModelFactorN; From 5004c47944f1e50234aa02c4c879771e272be7d2 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Wed, 8 Dec 2021 18:56:09 -0500 Subject: [PATCH 0015/1497] revert typedef X1, X2, ... to old version, and clean up a little --- gtsam/nonlinear/NonlinearFactor.h | 94 ++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 20 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 53a3e664d4..099f589792 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -305,6 +305,70 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { }; // \class NoiseModelFactor + +/* ************************************************************************* */ +/* We need some helper structs to help us with NoiseModelFactorN - specifically + * we need to alias X1, X2, X3, ... in the templated NoiseModelFactorN class to + * maintain backwards compatibility with NoiseModelFactor1, NoiseModelFactor2, + * NoiseModelFactor3, ... + * + * The tricky part is that we want to _conditionally_ alias these only if the + * `sizeof...(VALUES)` is greater than the index we want to alias (e.g. a 3-way + * factor should only have up to X3). SFINAE doesn't work in this case with + * aliases so we have to come up with a different approach. + * + * The approach we use is to inherit from structs that conditionally typedef + * these types for us (using template specialization). Note: std::conditional + * doesn't work because it requires that both types exist at compile time. + * + * Usage: + * ``` + * template + * class MyClass : public AliasX3 { ... }; + * ``` + * This will only typedef X3 if VALUES has at least 3 template parameters. So + * then we can do something like: + * ``` + * int main { + * MyClass::X3 a; // variable a will have type double + * // MyClass::X3 b; // this won't compile + * MyClass::X3 c; // variable c will have type char + * } + * ``` + */ + +namespace detail { + +// By default, we do not alias X (empty struct). +#define ALIAS_FALSE_X(NAME) \ + template \ + struct Alias##NAME##_ {}; +// But if the first template is true, then we do alias X by specializing. +#define ALIAS_TRUE_X(NAME, N) \ + template \ + struct Alias##NAME##_ { \ + using NAME = typename std::tuple_element>::type; \ + }; +// Finally, alias a convenience struct that chooses the right version. +#define ALIAS_X(NAME, N, CONDITION) \ + ALIAS_FALSE_X(NAME) \ + ALIAS_TRUE_X(NAME, N) \ + template \ + using Alias##NAME = Alias##NAME##_<(CONDITION), VALUES...>; + +ALIAS_X(X, 0, 0 == sizeof...(VALUES)); +ALIAS_X(X1, 0, 0 < sizeof...(VALUES)); +ALIAS_X(X2, 1, 1 < sizeof...(VALUES)); +ALIAS_X(X3, 2, 2 < sizeof...(VALUES)); +ALIAS_X(X4, 3, 3 < sizeof...(VALUES)); +ALIAS_X(X5, 4, 4 < sizeof...(VALUES)); +ALIAS_X(X6, 5, 5 < sizeof...(VALUES)); +#undef ALIAS_FALSE_X +#undef ALIAS_TRUE_X +#undef ALIAS_X + +} // namespace detail + /* ************************************************************************* */ /** * A convenient base class for creating your own NoiseModelFactor @@ -336,7 +400,16 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { * objects in non-linear manifolds (Lie groups). */ template -class NoiseModelFactorN : public NoiseModelFactor { +class NoiseModelFactorN + : public NoiseModelFactor, + public detail::AliasX, // using X = VALUE1 + public detail::AliasX1, // using X1 = VALUE1 + public detail::AliasX2, // using X2 = VALUE2 + public detail::AliasX3, // using X3 = VALUE3 + public detail::AliasX4, // using X4 = VALUE4 + public detail::AliasX5, // using X5 = VALUE5 + public detail::AliasX6 // using X6 = VALUE6 +{ public: /// N is the number of variables (N-way factor) enum { N = sizeof...(VALUES) }; @@ -345,25 +418,6 @@ class NoiseModelFactorN : public NoiseModelFactor { template ::type = true> using VALUE = typename std::tuple_element>::type; - private: - template - struct VALUE_OR_VOID { - using type = void; - }; - template - struct VALUE_OR_VOID::type> { - using type = VALUE; - }; - - public: - using X = typename VALUE_OR_VOID<0>::type; - using X1 = typename VALUE_OR_VOID<0>::type; - using X2 = typename VALUE_OR_VOID<1>::type; - using X3 = typename VALUE_OR_VOID<2>::type; - using X4 = typename VALUE_OR_VOID<3>::type; - using X5 = typename VALUE_OR_VOID<4>::type; - using X6 = typename VALUE_OR_VOID<5>::type; - protected: using Base = NoiseModelFactor; using This = NoiseModelFactorN; From 018213ec855db1dcbe0c7a7b754c178e49442379 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Wed, 8 Dec 2021 19:09:35 -0500 Subject: [PATCH 0016/1497] switch `using NoiseModelFactorX = ...` to `#define ...`. Reasoning is given as comments. --- gtsam/nonlinear/NonlinearFactor.h | 91 ++++++++----------------------- 1 file changed, 23 insertions(+), 68 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 099f589792..18822f0ef3 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -336,7 +336,6 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { * } * ``` */ - namespace detail { // By default, we do not alias X (empty struct). @@ -356,7 +355,7 @@ namespace detail { template \ using Alias##NAME = Alias##NAME##_<(CONDITION), VALUES...>; -ALIAS_X(X, 0, 0 == sizeof...(VALUES)); +ALIAS_X(X, 0, 1 == sizeof...(VALUES)); ALIAS_X(X1, 0, 0 < sizeof...(VALUES)); ALIAS_X(X2, 1, 1 < sizeof...(VALUES)); ALIAS_X(X3, 2, 2 < sizeof...(VALUES)); @@ -422,13 +421,13 @@ class NoiseModelFactorN using Base = NoiseModelFactor; using This = NoiseModelFactorN; - /* "Dummy templated" alias is used to expand fixed-type parameter packs with - * same length as VALUES. This ignores the template parameter. */ + /* Like std::void_t, except produces `boost::optional` instead. Used + * to expand fixed-type parameter-packs with same length as VALUES */ template using optional_matrix_type = boost::optional; - /* "Dummy templated" alias is used to expand fixed-type parameter packs with - * same length as VALUES. This ignores the template parameter. */ + /* Like std::void_t, except produces `Key` instead. Used to expand fixed-type + * parameter-packs with same length as VALUES */ template using key_type = Key; @@ -586,72 +585,28 @@ class NoiseModelFactorN } }; // \class NoiseModelFactorN -// // `using` does not work for some reason -// template -// using NoiseModelFactor1 = NoiseModelFactorN; -// template -// using NoiseModelFactor2 = NoiseModelFactorN; -// template -// using NoiseModelFactor3 = NoiseModelFactorN; -// template -// using NoiseModelFactor4 = NoiseModelFactorN; -// template -// using NoiseModelFactor5 = -// NoiseModelFactorN; -// template -// using NoiseModelFactor6 = -// NoiseModelFactorN; - -// this is visually ugly -template -struct NoiseModelFactor1 : NoiseModelFactorN { - using NoiseModelFactorN::NoiseModelFactorN; - using This = NoiseModelFactor1; -}; -template -struct NoiseModelFactor2 : NoiseModelFactorN { - using NoiseModelFactorN::NoiseModelFactorN; - using This = NoiseModelFactor2; -}; -template -struct NoiseModelFactor3 : NoiseModelFactorN { - using NoiseModelFactorN::NoiseModelFactorN; - using This = NoiseModelFactor3; -}; -template -struct NoiseModelFactor4 : NoiseModelFactorN { - using NoiseModelFactorN::NoiseModelFactorN; - using This = NoiseModelFactor4; -}; -template -struct NoiseModelFactor5 - : NoiseModelFactorN { - using NoiseModelFactorN::NoiseModelFactorN; - using This = NoiseModelFactor5; -}; -template -struct NoiseModelFactor6 - : NoiseModelFactorN { - using NoiseModelFactorN::NoiseModelFactorN; - using This = - NoiseModelFactor6; -}; - /* ************************************************************************* */ /** @deprecated: use NoiseModelFactorN * Convenient base classes for creating your own NoiseModelFactors with 1-6 * variables. To derive from these classes, implement evaluateError(). + * + * Note: we cannot use `using NoiseModelFactor1 = NoiseModelFactorN` due + * to class name injection making backwards compatibility difficult. + * + * Note: This has the side-effect that you could e.g. NoiseModelFactor6. + * That is, there is nothing stopping you from using any number of template + * arguments with any `NoiseModelFactorX`. */ -// // This has the side-effect that you could e.g. NoiseModelFactor6 -// #define NoiseModelFactor1 NoiseModelFactorN -// #define NoiseModelFactor2 NoiseModelFactorN -// #define NoiseModelFactor3 NoiseModelFactorN -// #define NoiseModelFactor4 NoiseModelFactorN -// #define NoiseModelFactor5 NoiseModelFactorN -// #define NoiseModelFactor6 NoiseModelFactorN +#define NoiseModelFactor1 NoiseModelFactorN +/** @deprecated */ +#define NoiseModelFactor2 NoiseModelFactorN +/** @deprecated */ +#define NoiseModelFactor3 NoiseModelFactorN +/** @deprecated */ +#define NoiseModelFactor4 NoiseModelFactorN +/** @deprecated */ +#define NoiseModelFactor5 NoiseModelFactorN +/** @deprecated */ +#define NoiseModelFactor6 NoiseModelFactorN } // \namespace gtsam From 84e873ebb0d14aaf0058d5a3e09d94aa38776847 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Thu, 9 Dec 2021 00:50:36 -0500 Subject: [PATCH 0017/1497] fix Windows CI issue: VALUE happens to have the same name in PriorFactor --- gtsam/nonlinear/NonlinearFactor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 18822f0ef3..ca13434a16 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -413,9 +413,9 @@ class NoiseModelFactorN /// N is the number of variables (N-way factor) enum { N = sizeof...(VALUES) }; - /** The type of the i'th template param can be obtained as VALUE */ + /** The type of the i'th template param can be obtained as X_ */ template ::type = true> - using VALUE = typename std::tuple_element>::type; + using X_ = typename std::tuple_element>::type; protected: using Base = NoiseModelFactor; From 40e585bb117eb24d3e591a97d06362b9acfa63a3 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Thu, 9 Dec 2021 02:26:57 -0500 Subject: [PATCH 0018/1497] review comments --- gtsam/nonlinear/NonlinearFactor.h | 46 +++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index ca13434a16..3a59a4db3e 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -29,6 +29,9 @@ #include #include +// boost::index_sequence was introduced in 1.66, so we'll manually define an +// implementation if user has 1.65. boost::index_sequence is used to get array +// indices that align with a parameter pack. #if BOOST_VERSION >= 106600 #include #else @@ -467,24 +470,11 @@ class NoiseModelFactorN ~NoiseModelFactorN() override {} - /** Methods to retrieve keys */ -#define SUB(Old, New) template // to delay template deduction -#define KEY_IF_TRUE(Enable) typename std::enable_if<(Enable), Key>::type - // templated version of `key()` + /** Returns a key. Usage: `key()` returns the I'th key. */ template - inline KEY_IF_TRUE(I < N) key() const { + inline typename std::enable_if<(I < N), Key>::type key() const { return keys_[I]; } - // backwards-compatibility functions - SUB(T, N) inline KEY_IF_TRUE(T == 1) key() const { return keys_[0]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 1) key1() const { return keys_[0]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 2) key2() const { return keys_[1]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 3) key3() const { return keys_[2]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 4) key4() const { return keys_[3]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 5) key5() const { return keys_[4]; } - SUB(T, N) inline KEY_IF_TRUE(T >= 6) key6() const { return keys_[5]; } -#undef SUB -#undef KEY_IF_TRUE /// @name NoiseModelFactor methods /// @{ @@ -583,6 +573,32 @@ class NoiseModelFactorN ar& boost::serialization::make_nvp( "NoiseModelFactor", boost::serialization::base_object(*this)); } + + public: + /** @defgroup deprecated key access + * Functions to retrieve keys (deprecated). Use the templated version: + * `key()` instead. + * @{ + */ +#define SUB(Old, New) template // to delay template deduction +#define KEY_IF_TRUE(Enable) typename std::enable_if<(Enable), Key>::type + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T == 1) key() const { return keys_[0]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 1) key1() const { return keys_[0]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 2) key2() const { return keys_[1]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 3) key3() const { return keys_[2]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 4) key4() const { return keys_[3]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 5) key5() const { return keys_[4]; } + /** @deprecated */ + SUB(T, N) inline KEY_IF_TRUE(T >= 6) key6() const { return keys_[5]; } +#undef SUB +#undef KEY_IF_TRUE + /** @} */ }; // \class NoiseModelFactorN /* ************************************************************************* */ From 11fd8612269690c9d95eba4a80ac5db705906aa1 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Thu, 9 Dec 2021 02:30:51 -0500 Subject: [PATCH 0019/1497] update doxygen (review comment) --- gtsam/mainpage.dox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/mainpage.dox b/gtsam/mainpage.dox index e07f45f079..e9c83da8a8 100644 --- a/gtsam/mainpage.dox +++ b/gtsam/mainpage.dox @@ -16,7 +16,7 @@ To use GTSAM to solve your own problems, you will often have to create new facto -# The number of variables your factor involves is unknown at compile time - derive from NoiseModelFactor and implement NoiseModelFactor::unwhitenedError() - This is a factor expressing the sum-of-squares error between a measurement \f$ z \f$ and a measurement prediction function \f$ h(x) \f$, on which the errors are expected to follow some distribution specified by a noise model (see noiseModel). --# The number of variables your factor involves is known at compile time and is between 1 and 6 - derive from NoiseModelFactor1, NoiseModelFactor2, NoiseModelFactor3, NoiseModelFactor4, NoiseModelFactor5, or NoiseModelFactor6, and implement \c evaluateError(). If the number of variables is greater than 6, derive from NoiseModelFactorN. +-# The number of variables your factor involves is known at compile time, derive from NoiseModelFactorN (where T1, T2, ... are the types of the variables, e.g. double, Vector, Pose3) and implement \c evaluateError(). - This factor expresses the same sum-of-squares error with a noise model, but makes the implementation task slightly easier than with %NoiseModelFactor. -# Derive from NonlinearFactor - This is more advanced and allows creating factors without an explicit noise model, or that linearize to HessianFactor instead of JacobianFactor. From c9dbb6e04085dad6dc7e48c99dbe6b5624a4575f Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Sun, 30 Jan 2022 17:23:02 -0500 Subject: [PATCH 0020/1497] create backwards compatibility unit test for NoiseModelFactor1 --- gtsam/nonlinear/tests/priorFactor.xml | 77 +++++++++++++++++++ .../tests/testSerializationNonlinear.cpp | 53 +++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 gtsam/nonlinear/tests/priorFactor.xml diff --git a/gtsam/nonlinear/tests/priorFactor.xml b/gtsam/nonlinear/tests/priorFactor.xml new file mode 100644 index 0000000000..46752262b9 --- /dev/null +++ b/gtsam/nonlinear/tests/priorFactor.xml @@ -0,0 +1,77 @@ + + + + + + + + + 1 + 0 + 12345 + + + + + + + + + 6 + + + 0 + + + + 6 + + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + + + + 6 + + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + + + + 1.00000000000000000e+00 + 1.00000000000000000e+00 + + + + + + + + 4.11982245665682978e-01 + -8.33737651774156818e-01 + -3.67630462924899259e-01 + -5.87266449276209815e-02 + -4.26917621276207360e-01 + 9.02381585483330806e-01 + -9.09297426825681709e-01 + -3.50175488374014632e-01 + -2.24845095366152908e-01 + + + + 4.00000000000000000e+00 + 5.00000000000000000e+00 + 6.00000000000000000e+00 + + + + + diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index 4a73cbb0b4..f7b524a5c7 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -107,6 +107,59 @@ TEST (Serialization, TemplatedValues) { EXPECT(equalsBinary(values)); } +bool str_assert_equal(const string& expected, const string& actual) { + if (actual == expected) return true; + printf("Not equal:\n"); + std::cout << "expected:\n" << expected << std::endl; + std::cout << "actual:\n" << actual << std::endl; + return false; +} +TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { + PriorFactor factor( + 12345, Pose3(Rot3::RzRyRx(Vector3(1., 2., 3.)), Point3(4., 5., 6.)), + noiseModel::Unit::Create(6)); + + // String + std::string actual_str = serialize(factor); + // Generated from hash 3ba65669113f41d0e56a03b4b314047776bab5c4 (>4.2a4) + std::string expected_str = + "22 serialization::archive 19 1 0\n" + "0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" + "1 1 0\n" + "2 1 0\n" + "3 0 0 0 0 6 0 1 0 0 0 6 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 6 1.00000000000000000e+00 " + "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 0 0 0 0 4.11982245665682978e-01 " + "-8.33737651774156818e-01 -3.67630462924899259e-01 " + "-5.87266449276209815e-02 -4.26917621276207360e-01 " + "9.02381585483330806e-01 -9.09297426825681709e-01 " + "-3.50175488374014632e-01 -2.24845095366152908e-01 0 0 " + "4.00000000000000000e+00 5.00000000000000000e+00 " + "6.00000000000000000e+00\n"; + EXPECT(str_assert_equal(expected_str, actual_str)); + PriorFactor factor_deserialized_str = PriorFactor(); + deserializeFromString(expected_str, factor_deserialized_str); + EXPECT(assert_equal(factor, factor_deserialized_str)); + + // XML + std::string actual_xml = serializeXML(factor); + std::string expected_xml; + { // read from file + // Generated from hash 3ba65669113f41d0e56a03b4b314047776bab5c4 (>4.2a4) + std::ifstream f("priorFactor.xml"); + std::stringstream buffer; + buffer << f.rdbuf(); + expected_xml = buffer.str(); + } + EXPECT(str_assert_equal(expected_xml, actual_xml)); + PriorFactor factor_deserialized_xml = PriorFactor(); + deserializeFromXMLFile("priorFactor.xml", factor_deserialized_xml); + EXPECT(assert_equal(factor, factor_deserialized_xml)); +} + TEST(Serialization, ISAM2) { gtsam::ISAM2Params parameters; From bb33be58b36ec4aa4f00d56064b6286901710e96 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Sun, 30 Jan 2022 17:25:20 -0500 Subject: [PATCH 0021/1497] revert some template stuff with inheritance for readability NoiseModelFactor123456 are now minimal classes that inherit from NoiseModelFactorN --- gtsam/nonlinear/NonlinearFactor.h | 360 ++++++++++++++++++++---------- 1 file changed, 240 insertions(+), 120 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index d7061215ed..212364af3c 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -309,68 +309,6 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { }; // \class NoiseModelFactor -/* ************************************************************************* */ -/* We need some helper structs to help us with NoiseModelFactorN - specifically - * we need to alias X1, X2, X3, ... in the templated NoiseModelFactorN class to - * maintain backwards compatibility with NoiseModelFactor1, NoiseModelFactor2, - * NoiseModelFactor3, ... - * - * The tricky part is that we want to _conditionally_ alias these only if the - * `sizeof...(VALUES)` is greater than the index we want to alias (e.g. a 3-way - * factor should only have up to X3). SFINAE doesn't work in this case with - * aliases so we have to come up with a different approach. - * - * The approach we use is to inherit from structs that conditionally typedef - * these types for us (using template specialization). Note: std::conditional - * doesn't work because it requires that both types exist at compile time. - * - * Usage: - * ``` - * template - * class MyClass : public AliasX3 { ... }; - * ``` - * This will only typedef X3 if VALUES has at least 3 template parameters. So - * then we can do something like: - * ``` - * int main { - * MyClass::X3 a; // variable a will have type double - * // MyClass::X3 b; // this won't compile - * MyClass::X3 c; // variable c will have type char - * } - * ``` - */ -namespace detail { - -// By default, we do not alias X (empty struct). -#define ALIAS_FALSE_X(NAME) \ - template \ - struct Alias##NAME##_ {}; -// But if the first template is true, then we do alias X by specializing. -#define ALIAS_TRUE_X(NAME, N) \ - template \ - struct Alias##NAME##_ { \ - using NAME = typename std::tuple_element>::type; \ - }; -// Finally, alias a convenience struct that chooses the right version. -#define ALIAS_X(NAME, N, CONDITION) \ - ALIAS_FALSE_X(NAME) \ - ALIAS_TRUE_X(NAME, N) \ - template \ - using Alias##NAME = Alias##NAME##_<(CONDITION), VALUES...>; - -ALIAS_X(X, 0, 1 == sizeof...(VALUES)); -ALIAS_X(X1, 0, 0 < sizeof...(VALUES)); -ALIAS_X(X2, 1, 1 < sizeof...(VALUES)); -ALIAS_X(X3, 2, 2 < sizeof...(VALUES)); -ALIAS_X(X4, 3, 3 < sizeof...(VALUES)); -ALIAS_X(X5, 4, 4 < sizeof...(VALUES)); -ALIAS_X(X6, 5, 5 < sizeof...(VALUES)); -#undef ALIAS_FALSE_X -#undef ALIAS_TRUE_X -#undef ALIAS_X - -} // namespace detail - /* ************************************************************************* */ /** * A convenient base class for creating your own NoiseModelFactor @@ -402,23 +340,14 @@ ALIAS_X(X6, 5, 5 < sizeof...(VALUES)); * objects in non-linear manifolds (Lie groups). */ template -class GTSAM_EXPORT NoiseModelFactorN - : public NoiseModelFactor, - public detail::AliasX, // using X = VALUE1 - public detail::AliasX1, // using X1 = VALUE1 - public detail::AliasX2, // using X2 = VALUE2 - public detail::AliasX3, // using X3 = VALUE3 - public detail::AliasX4, // using X4 = VALUE4 - public detail::AliasX5, // using X5 = VALUE5 - public detail::AliasX6 // using X6 = VALUE6 -{ +class GTSAM_EXPORT NoiseModelFactorN : public NoiseModelFactor { public: /// N is the number of variables (N-way factor) enum { N = sizeof...(VALUES) }; - /** The type of the i'th template param can be obtained as X_ */ + /** The type of the i'th template param can be obtained as X */ template ::type = true> - using X_ = typename std::tuple_element>::type; + using X = typename std::tuple_element>::type; protected: using Base = NoiseModelFactor; @@ -573,56 +502,247 @@ class GTSAM_EXPORT NoiseModelFactorN ar& boost::serialization::make_nvp( "NoiseModelFactor", boost::serialization::base_object(*this)); } +}; // \class NoiseModelFactorN +/* ************************************************************************* */ +/** @deprecated: use NoiseModelFactorN, replacing .key() with .key<1> and X1 + * with X<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 1 variable. To derive from this class, implement evaluateError(). + */ +template +class NoiseModelFactor1 : public NoiseModelFactorN { public: - /** @defgroup deprecated key access - * Functions to retrieve keys (deprecated). Use the templated version: - * `key()` instead. - * @{ - */ -#define SUB(Old, New) template // to delay template deduction -#define KEY_IF_TRUE(Enable) typename std::enable_if<(Enable), Key>::type - /** @deprecated */ - SUB(T, N) inline KEY_IF_TRUE(T == 1) key() const { return keys_[0]; } - /** @deprecated */ - SUB(T, N) inline KEY_IF_TRUE(T >= 1) key1() const { return keys_[0]; } - /** @deprecated */ - SUB(T, N) inline KEY_IF_TRUE(T >= 2) key2() const { return keys_[1]; } - /** @deprecated */ - SUB(T, N) inline KEY_IF_TRUE(T >= 3) key3() const { return keys_[2]; } - /** @deprecated */ - SUB(T, N) inline KEY_IF_TRUE(T >= 4) key4() const { return keys_[3]; } - /** @deprecated */ - SUB(T, N) inline KEY_IF_TRUE(T >= 5) key5() const { return keys_[4]; } - /** @deprecated */ - SUB(T, N) inline KEY_IF_TRUE(T >= 6) key6() const { return keys_[5]; } -#undef SUB -#undef KEY_IF_TRUE - /** @} */ -}; // \class NoiseModelFactorN + // aliases for value types pulled from keys + using X = VALUE; + + protected: + using Base = NoiseModelFactor; // grandparent, for backwards compatibility + using This = NoiseModelFactor1; + + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; + ~NoiseModelFactor1() override {} + + /** method to retrieve key */ + inline Key key() const { return this->keys_[0]; } + + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactor1 /* ************************************************************************* */ -/** @deprecated: use NoiseModelFactorN - * Convenient base classes for creating your own NoiseModelFactors with 1-6 - * variables. To derive from these classes, implement evaluateError(). - * - * Note: we cannot use `using NoiseModelFactor1 = NoiseModelFactorN` due - * to class name injection making backwards compatibility difficult. - * - * Note: This has the side-effect that you could e.g. NoiseModelFactor6. - * That is, there is nothing stopping you from using any number of template - * arguments with any `NoiseModelFactorX`. +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with X<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 2 variables. To derive from this class, implement evaluateError(). + */ +template +class NoiseModelFactor2 : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + + protected: + using Base = NoiseModelFactor; + using This = NoiseModelFactor2; + + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; + ~NoiseModelFactor2() override {} + + /** methods to retrieve both keys */ + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactor2 + +/* ************************************************************************* */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with X<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 3 variables. To derive from this class, implement evaluateError(). */ -#define NoiseModelFactor1 NoiseModelFactorN -/** @deprecated */ -#define NoiseModelFactor2 NoiseModelFactorN -/** @deprecated */ -#define NoiseModelFactor3 NoiseModelFactorN -/** @deprecated */ -#define NoiseModelFactor4 NoiseModelFactorN -/** @deprecated */ -#define NoiseModelFactor5 NoiseModelFactorN -/** @deprecated */ -#define NoiseModelFactor6 NoiseModelFactorN +template +class NoiseModelFactor3 : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; + + protected: + using Base = NoiseModelFactor; + using This = NoiseModelFactor3; + + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; + ~NoiseModelFactor3() override {} + + /** methods to retrieve keys */ + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactor3 + +/* ************************************************************************* */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with X<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 4 variables. To derive from this class, implement evaluateError(). + */ +template +class NoiseModelFactor4 + : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; + using X4 = VALUE4; + + protected: + using Base = NoiseModelFactor; + using This = NoiseModelFactor4; + + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; + ~NoiseModelFactor4() override {} + + /** methods to retrieve keys */ + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + inline Key key4() const { return this->keys_[3]; } + + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactor4 + +/* ************************************************************************* */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with X<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 5 variables. To derive from this class, implement evaluateError(). + */ +template +class NoiseModelFactor5 + : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; + using X4 = VALUE4; + using X5 = VALUE5; + + protected: + using Base = NoiseModelFactor; + using This = NoiseModelFactor5; + + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; + ~NoiseModelFactor5() override {} + + /** methods to retrieve keys */ + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + inline Key key4() const { return this->keys_[3]; } + inline Key key5() const { return this->keys_[4]; } + + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactor5 + +/* ************************************************************************* */ +/** @deprecated: use NoiseModelFactorN, replacing .key1() with .key<1> and X1 + * with X<1>. + * A convenient base class for creating your own NoiseModelFactor + * with 6 variables. To derive from this class, implement evaluateError(). + */ +template +class NoiseModelFactor6 + : public NoiseModelFactorN { + public: + // aliases for value types pulled from keys + using X1 = VALUE1; + using X2 = VALUE2; + using X3 = VALUE3; + using X4 = VALUE4; + using X5 = VALUE5; + using X6 = VALUE6; + + protected: + using Base = NoiseModelFactor; + using This = + NoiseModelFactor6; + + public: + // inherit NoiseModelFactorN's constructors + using NoiseModelFactorN::NoiseModelFactorN; + ~NoiseModelFactor6() override {} + + /** methods to retrieve keys */ + inline Key key1() const { return this->keys_[0]; } + inline Key key2() const { return this->keys_[1]; } + inline Key key3() const { return this->keys_[2]; } + inline Key key4() const { return this->keys_[3]; } + inline Key key5() const { return this->keys_[4]; } + inline Key key6() const { return this->keys_[5]; } + + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + ar& boost::serialization::make_nvp( + "NoiseModelFactor", boost::serialization::base_object(*this)); + } +}; // \class NoiseModelFactor6 } // \namespace gtsam From 82e0d205190577e7f3fc669829b9ff1b364bcb67 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Sun, 30 Jan 2022 17:26:54 -0500 Subject: [PATCH 0022/1497] move boost::index_sequence stuff to utilities file --- gtsam/base/utilities.h | 38 ++++++++++++++++++++++++++++++ gtsam/nonlinear/NonlinearFactor.h | 39 +------------------------------ 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/gtsam/base/utilities.h b/gtsam/base/utilities.h index d9b92b8aa3..22e90d2754 100644 --- a/gtsam/base/utilities.h +++ b/gtsam/base/utilities.h @@ -27,3 +27,41 @@ struct RedirectCout { }; } + +// boost::index_sequence was introduced in 1.66, so we'll manually define an +// implementation if user has 1.65. boost::index_sequence is used to get array +// indices that align with a parameter pack. +#if BOOST_VERSION >= 106600 +#include +#else +namespace boost { +namespace mp11 { +// Adapted from https://stackoverflow.com/a/32223343/9151520 +template +struct index_sequence { + using type = index_sequence; + using value_type = size_t; + static constexpr std::size_t size() noexcept { return sizeof...(Ints); } +}; +namespace detail { +template +struct _merge_and_renumber; + +template +struct _merge_and_renumber, index_sequence > + : index_sequence {}; +} // namespace detail +template +struct make_index_sequence + : detail::_merge_and_renumber< + typename make_index_sequence::type, + typename make_index_sequence::type> {}; +template <> +struct make_index_sequence<0> : index_sequence<> {}; +template <> +struct make_index_sequence<1> : index_sequence<0> {}; +template +using index_sequence_for = make_index_sequence; +} // namespace mp11 +} // namespace boost +#endif diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 212364af3c..4deef0d3ac 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -25,48 +25,11 @@ #include #include #include +#include // boost::index_sequence #include #include -// boost::index_sequence was introduced in 1.66, so we'll manually define an -// implementation if user has 1.65. boost::index_sequence is used to get array -// indices that align with a parameter pack. -#if BOOST_VERSION >= 106600 -#include -#else -namespace boost { -namespace mp11 { -// Adapted from https://stackoverflow.com/a/32223343/9151520 -template -struct index_sequence { - using type = index_sequence; - using value_type = size_t; - static constexpr std::size_t size() noexcept { return sizeof...(Ints); } -}; -namespace detail { -template -struct _merge_and_renumber; - -template -struct _merge_and_renumber, index_sequence > - : index_sequence {}; -} // namespace detail -template -struct make_index_sequence - : detail::_merge_and_renumber< - typename make_index_sequence::type, - typename make_index_sequence::type> {}; -template <> -struct make_index_sequence<0> : index_sequence<> {}; -template <> -struct make_index_sequence<1> : index_sequence<0> {}; -template -using index_sequence_for = make_index_sequence; -} // namespace mp11 -} // namespace boost -#endif - namespace gtsam { using boost::assign::cref_list_of; From d62033a856f4e78ce0625ff9dd43539d30e39a2a Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Sun, 30 Jan 2022 17:38:42 -0500 Subject: [PATCH 0023/1497] fix namespace collision with symbol_shorthand::X in unit test --- tests/testNonlinearFactor.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/testNonlinearFactor.cpp b/tests/testNonlinearFactor.cpp index 27b61cf894..bdc2d576d0 100644 --- a/tests/testNonlinearFactor.cpp +++ b/tests/testNonlinearFactor.cpp @@ -382,8 +382,9 @@ class TestFactor4 : public NoiseModelFactor4 { "This type wrong"); public: + static constexpr auto X_ = symbol_shorthand::X; // collision with X<1> typedef NoiseModelFactor4 Base; - TestFactor4() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X(1), X(2), X(3), X(4)) {} + TestFactor4() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X_(1), X_(2), X_(3), X_(4)) {} Vector evaluateError(const double& x1, const double& x2, const double& x3, const double& x4, @@ -446,8 +447,9 @@ TEST(NonlinearFactor, NoiseModelFactor4) { /* ************************************************************************* */ class TestFactor5 : public NoiseModelFactor5 { public: + static constexpr auto X_ = symbol_shorthand::X; // collision with X<1> typedef NoiseModelFactor5 Base; - TestFactor5() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X(1), X(2), X(3), X(4), X(5)) {} + TestFactor5() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X_(1), X_(2), X_(3), X_(4), X_(5)) {} Vector evaluateError(const X1& x1, const X2& x2, const X3& x3, const X4& x4, const X5& x5, @@ -495,8 +497,9 @@ TEST(NonlinearFactor, NoiseModelFactor5) { /* ************************************************************************* */ class TestFactor6 : public NoiseModelFactor6 { public: + static constexpr auto X_ = symbol_shorthand::X; // collision with X<1> typedef NoiseModelFactor6 Base; - TestFactor6() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X(1), X(2), X(3), X(4), X(5), X(6)) {} + TestFactor6() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X_(1), X_(2), X_(3), X_(4), X_(5), X_(6)) {} Vector evaluateError(const X1& x1, const X2& x2, const X3& x3, const X4& x4, const X5& x5, const X6& x6, @@ -551,8 +554,9 @@ TEST(NonlinearFactor, NoiseModelFactor6) { /* ************************************************************************* */ class TestFactorN : public NoiseModelFactorN { public: + static constexpr auto X_ = symbol_shorthand::X; // collision with X<1> typedef NoiseModelFactorN Base; - TestFactorN() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X(1), X(2), X(3), X(4)) {} + TestFactorN() : Base(noiseModel::Diagonal::Sigmas((Vector(1) << 2.0).finished()), X_(1), X_(2), X_(3), X_(4)) {} Vector evaluateError(const double& x1, const double& x2, const double& x3, const double& x4, From a2fb0e49d51c9c822ad13f017c2521e572d6274c Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Sun, 30 Jan 2022 21:30:03 -0500 Subject: [PATCH 0024/1497] Revert "create backwards compatibility unit test for NoiseModelFactor1" This reverts commit c9dbb6e04085dad6dc7e48c99dbe6b5624a4575f. --- gtsam/nonlinear/tests/priorFactor.xml | 77 ------------------- .../tests/testSerializationNonlinear.cpp | 53 ------------- 2 files changed, 130 deletions(-) delete mode 100644 gtsam/nonlinear/tests/priorFactor.xml diff --git a/gtsam/nonlinear/tests/priorFactor.xml b/gtsam/nonlinear/tests/priorFactor.xml deleted file mode 100644 index 46752262b9..0000000000 --- a/gtsam/nonlinear/tests/priorFactor.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - 1 - 0 - 12345 - - - - - - - - - 6 - - - 0 - - - - 6 - - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - - - - 6 - - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - 1.00000000000000000e+00 - - - - 1.00000000000000000e+00 - 1.00000000000000000e+00 - - - - - - - - 4.11982245665682978e-01 - -8.33737651774156818e-01 - -3.67630462924899259e-01 - -5.87266449276209815e-02 - -4.26917621276207360e-01 - 9.02381585483330806e-01 - -9.09297426825681709e-01 - -3.50175488374014632e-01 - -2.24845095366152908e-01 - - - - 4.00000000000000000e+00 - 5.00000000000000000e+00 - 6.00000000000000000e+00 - - - - - diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index f7b524a5c7..4a73cbb0b4 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -107,59 +107,6 @@ TEST (Serialization, TemplatedValues) { EXPECT(equalsBinary(values)); } -bool str_assert_equal(const string& expected, const string& actual) { - if (actual == expected) return true; - printf("Not equal:\n"); - std::cout << "expected:\n" << expected << std::endl; - std::cout << "actual:\n" << actual << std::endl; - return false; -} -TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { - PriorFactor factor( - 12345, Pose3(Rot3::RzRyRx(Vector3(1., 2., 3.)), Point3(4., 5., 6.)), - noiseModel::Unit::Create(6)); - - // String - std::string actual_str = serialize(factor); - // Generated from hash 3ba65669113f41d0e56a03b4b314047776bab5c4 (>4.2a4) - std::string expected_str = - "22 serialization::archive 19 1 0\n" - "0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" - "1 1 0\n" - "2 1 0\n" - "3 0 0 0 0 6 0 1 0 0 0 6 1.00000000000000000e+00 1.00000000000000000e+00 " - "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " - "1.00000000000000000e+00 6 1.00000000000000000e+00 " - "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " - "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " - "1.00000000000000000e+00 0 0 0 0 4.11982245665682978e-01 " - "-8.33737651774156818e-01 -3.67630462924899259e-01 " - "-5.87266449276209815e-02 -4.26917621276207360e-01 " - "9.02381585483330806e-01 -9.09297426825681709e-01 " - "-3.50175488374014632e-01 -2.24845095366152908e-01 0 0 " - "4.00000000000000000e+00 5.00000000000000000e+00 " - "6.00000000000000000e+00\n"; - EXPECT(str_assert_equal(expected_str, actual_str)); - PriorFactor factor_deserialized_str = PriorFactor(); - deserializeFromString(expected_str, factor_deserialized_str); - EXPECT(assert_equal(factor, factor_deserialized_str)); - - // XML - std::string actual_xml = serializeXML(factor); - std::string expected_xml; - { // read from file - // Generated from hash 3ba65669113f41d0e56a03b4b314047776bab5c4 (>4.2a4) - std::ifstream f("priorFactor.xml"); - std::stringstream buffer; - buffer << f.rdbuf(); - expected_xml = buffer.str(); - } - EXPECT(str_assert_equal(expected_xml, actual_xml)); - PriorFactor factor_deserialized_xml = PriorFactor(); - deserializeFromXMLFile("priorFactor.xml", factor_deserialized_xml); - EXPECT(assert_equal(factor, factor_deserialized_xml)); -} - TEST(Serialization, ISAM2) { gtsam::ISAM2Params parameters; From 1a427cd96c3c00e20c5a4518256523ab966f7270 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Sun, 30 Jan 2022 23:48:22 -0500 Subject: [PATCH 0025/1497] Serialize test strings generated with Boost 1.65 --- gtsam/nonlinear/tests/priorFactor.xml | 77 +++++++++++++++++++ .../tests/testSerializationNonlinear.cpp | 47 +++++++++++ 2 files changed, 124 insertions(+) create mode 100644 gtsam/nonlinear/tests/priorFactor.xml diff --git a/gtsam/nonlinear/tests/priorFactor.xml b/gtsam/nonlinear/tests/priorFactor.xml new file mode 100644 index 0000000000..0c580fb211 --- /dev/null +++ b/gtsam/nonlinear/tests/priorFactor.xml @@ -0,0 +1,77 @@ + + + + + + + + + 1 + 0 + 12345 + + + + + + + + + 6 + + + 0 + + + + 6 + + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + + + + 6 + + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + 1.00000000000000000e+00 + + + + 1.00000000000000000e+00 + 1.00000000000000000e+00 + + + + + + + + 4.11982245665682978e-01 + -8.33737651774156818e-01 + -3.67630462924899259e-01 + -5.87266449276209815e-02 + -4.26917621276207360e-01 + 9.02381585483330806e-01 + -9.09297426825681709e-01 + -3.50175488374014632e-01 + -2.24845095366152908e-01 + + + + 4.00000000000000000e+00 + 5.00000000000000000e+00 + 6.00000000000000000e+00 + + + + + diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index 4a73cbb0b4..023785f219 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -107,6 +107,53 @@ TEST (Serialization, TemplatedValues) { EXPECT(equalsBinary(values)); } +/** + * Test deserializing from a known serialization generated by code from commit + * 3ba65669113f41d0e56a03b4b314047776bab5c4 (>4.2a4) + * We only test that deserialization matches since + * (1) that's the main backward compatibility requirement and + * (2) serialized string depends on boost version + */ +TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { + PriorFactor factor( + 12345, Pose3(Rot3::RzRyRx(Vector3(1., 2., 3.)), Point3(4., 5., 6.)), + noiseModel::Unit::Create(6)); + + // String + std::string expected_str = + "22 serialization::archive 15 1 0\n" + "0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" + "1 1 0\n" + "2 1 0\n" + "3 0 0 0 0 6 0 1 0 0 0 6 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 6 1.00000000000000000e+00 " + "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 " + "1.00000000000000000e+00 0 0 0 0 4.11982245665682978e-01 " + "-8.33737651774156818e-01 -3.67630462924899259e-01 " + "-5.87266449276209815e-02 -4.26917621276207360e-01 " + "9.02381585483330806e-01 -9.09297426825681709e-01 " + "-3.50175488374014632e-01 -2.24845095366152908e-01 0 0 " + "4.00000000000000000e+00 5.00000000000000000e+00 " + "6.00000000000000000e+00\n"; + PriorFactor factor_deserialized_str = PriorFactor(); + deserializeFromString(expected_str, factor_deserialized_str); + EXPECT(assert_equal(factor, factor_deserialized_str)); + + // XML + std::string expected_xml; + { // read from file + std::ifstream f("priorFactor.xml"); + std::stringstream buffer; + buffer << f.rdbuf(); + expected_xml = buffer.str(); + } + PriorFactor factor_deserialized_xml = PriorFactor(); + deserializeFromXMLFile("priorFactor.xml", factor_deserialized_xml); + EXPECT(assert_equal(factor, factor_deserialized_xml)); +} + TEST(Serialization, ISAM2) { gtsam::ISAM2Params parameters; From 6653d666ef6e23eab9366545344e689492287edf Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Mon, 31 Jan 2022 01:08:47 -0500 Subject: [PATCH 0026/1497] fix test xml file path --- gtsam/nonlinear/tests/testSerializationNonlinear.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index 023785f219..b6b5033a2e 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -142,15 +142,10 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { EXPECT(assert_equal(factor, factor_deserialized_str)); // XML - std::string expected_xml; - { // read from file - std::ifstream f("priorFactor.xml"); - std::stringstream buffer; - buffer << f.rdbuf(); - expected_xml = buffer.str(); - } PriorFactor factor_deserialized_xml = PriorFactor(); - deserializeFromXMLFile("priorFactor.xml", factor_deserialized_xml); + deserializeFromXMLFile(GTSAM_SOURCE_TREE_DATASET_DIR + "/../../gtsam/nonlinear/tests/priorFactor.xml", + factor_deserialized_xml); EXPECT(assert_equal(factor, factor_deserialized_xml)); } From d0279d2738548b8e25aca2b9a39c172b99a561a6 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 11:57:31 -0500 Subject: [PATCH 0027/1497] Add pybind11/stl.h and get it compiling --- gtsam/base/base.i | 36 ----------------------------- python/gtsam/gtsam.tpl | 1 + python/gtsam/specializations/base.h | 3 --- 3 files changed, 1 insertion(+), 39 deletions(-) diff --git a/gtsam/base/base.i b/gtsam/base/base.i index 9838f97d38..f4184fa125 100644 --- a/gtsam/base/base.i +++ b/gtsam/base/base.i @@ -41,45 +41,9 @@ class DSFMap { std::map sets(); }; -class IndexPairSet { - IndexPairSet(); - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - void insert(gtsam::IndexPair key); - bool erase(gtsam::IndexPair key); // returns true if value was removed - bool count(gtsam::IndexPair key) const; // returns true if value exists -}; - -class IndexPairVector { - IndexPairVector(); - IndexPairVector(const gtsam::IndexPairVector& other); - - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - gtsam::IndexPair at(size_t i) const; - void push_back(gtsam::IndexPair key) const; -}; gtsam::IndexPairVector IndexPairSetAsArray(gtsam::IndexPairSet& set); -class IndexPairSetMap { - IndexPairSetMap(); - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - gtsam::IndexPairSet at(gtsam::IndexPair& key); -}; #include bool linear_independent(Matrix A, Matrix B, double tol); diff --git a/python/gtsam/gtsam.tpl b/python/gtsam/gtsam.tpl index b760e4eb5a..bdeb2bccce 100644 --- a/python/gtsam/gtsam.tpl +++ b/python/gtsam/gtsam.tpl @@ -11,6 +11,7 @@ {include_boost} #include +#include #include #include #include diff --git a/python/gtsam/specializations/base.h b/python/gtsam/specializations/base.h index 9eefdeca82..995753da10 100644 --- a/python/gtsam/specializations/base.h +++ b/python/gtsam/specializations/base.h @@ -11,7 +11,4 @@ * and saves one copy operation. */ -py::bind_map(m_, "IndexPairSetMap"); -py::bind_vector(m_, "IndexPairVector"); - py::bind_vector >(m_, "JacobianVector"); From 394bb82dba39cb8b8f456612957cc1f8025dd19b Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 12:14:31 -0500 Subject: [PATCH 0028/1497] remove unnecessary includes --- python/gtsam/preamble/basis.h | 2 -- python/gtsam/preamble/discrete.h | 2 -- python/gtsam/preamble/inference.h | 2 -- 3 files changed, 6 deletions(-) diff --git a/python/gtsam/preamble/basis.h b/python/gtsam/preamble/basis.h index 56a07cfdd1..d07a75f6fb 100644 --- a/python/gtsam/preamble/basis.h +++ b/python/gtsam/preamble/basis.h @@ -10,5 +10,3 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ - -#include diff --git a/python/gtsam/preamble/discrete.h b/python/gtsam/preamble/discrete.h index 608508c32f..598ab626dd 100644 --- a/python/gtsam/preamble/discrete.h +++ b/python/gtsam/preamble/discrete.h @@ -11,6 +11,4 @@ * mutations on Python side will not be reflected on C++. */ -#include - PYBIND11_MAKE_OPAQUE(gtsam::DiscreteKeys); diff --git a/python/gtsam/preamble/inference.h b/python/gtsam/preamble/inference.h index 320e0ac718..bd71c08179 100644 --- a/python/gtsam/preamble/inference.h +++ b/python/gtsam/preamble/inference.h @@ -11,5 +11,3 @@ * mutations on Python side will not be reflected on C++. */ -#include - From 19287ad5c889b08cf64855fe48b7a89bd0d4e174 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 12:15:43 -0500 Subject: [PATCH 0029/1497] fix geometry modules --- gtsam/geometry/geometry.i | 54 ------------------------- python/gtsam/preamble/geometry.h | 12 ++---- python/gtsam/specializations/geometry.h | 7 ---- 3 files changed, 3 insertions(+), 70 deletions(-) diff --git a/gtsam/geometry/geometry.i b/gtsam/geometry/geometry.i index 1e42966f84..97ffe6f189 100644 --- a/gtsam/geometry/geometry.i +++ b/gtsam/geometry/geometry.i @@ -29,38 +29,6 @@ class Point2 { void serialize() const; }; -class Point2Pairs { - Point2Pairs(); - size_t size() const; - bool empty() const; - gtsam::Point2Pair at(size_t n) const; - void push_back(const gtsam::Point2Pair& point_pair); -}; - -// std::vector -class Point2Vector { - // Constructors - Point2Vector(); - Point2Vector(const gtsam::Point2Vector& v); - - // Capacity - size_t size() const; - size_t max_size() const; - void resize(size_t sz); - size_t capacity() const; - bool empty() const; - void reserve(size_t n); - - // Element access - gtsam::Point2 at(size_t n) const; - gtsam::Point2 front() const; - gtsam::Point2 back() const; - - // Modifiers - void assign(size_t n, const gtsam::Point2& u); - void push_back(const gtsam::Point2& x); - void pop_back(); -}; #include class StereoPoint2 { @@ -127,13 +95,6 @@ class Point3 { void serialize() const; }; -class Point3Pairs { - Point3Pairs(); - size_t size() const; - bool empty() const; - gtsam::Point3Pair at(size_t n) const; - void push_back(const gtsam::Point3Pair& point_pair); -}; #include class Rot2 { @@ -486,21 +447,6 @@ class Pose3 { void serialize() const; }; -class Pose3Pairs { - Pose3Pairs(); - size_t size() const; - bool empty() const; - gtsam::Pose3Pair at(size_t n) const; - void push_back(const gtsam::Pose3Pair& pose_pair); -}; - -class Pose3Vector { - Pose3Vector(); - size_t size() const; - bool empty() const; - gtsam::Pose3 at(size_t n) const; - void push_back(const gtsam::Pose3& pose); -}; #include class Unit3 { diff --git a/python/gtsam/preamble/geometry.h b/python/gtsam/preamble/geometry.h index 35fe2a577a..ca03cdfe28 100644 --- a/python/gtsam/preamble/geometry.h +++ b/python/gtsam/preamble/geometry.h @@ -10,7 +10,6 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ -#include // Support for binding boost::optional types in C++11. // https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html @@ -19,12 +18,7 @@ namespace pybind11 { namespace detail { struct type_caster> : optional_caster> {}; }} -PYBIND11_MAKE_OPAQUE( - std::vector>); -PYBIND11_MAKE_OPAQUE(gtsam::Point2Pairs); -PYBIND11_MAKE_OPAQUE(gtsam::Point3Pairs); -PYBIND11_MAKE_OPAQUE(gtsam::Pose3Pairs); -PYBIND11_MAKE_OPAQUE(std::vector); -PYBIND11_MAKE_OPAQUE( - gtsam::CameraSet>); PYBIND11_MAKE_OPAQUE(gtsam::CameraSet>); +PYBIND11_MAKE_OPAQUE(gtsam::CameraSet>); +PYBIND11_MAKE_OPAQUE(gtsam::CameraSet>); +PYBIND11_MAKE_OPAQUE(gtsam::CameraSet>); diff --git a/python/gtsam/specializations/geometry.h b/python/gtsam/specializations/geometry.h index a492ce8eb2..f63e942a23 100644 --- a/python/gtsam/specializations/geometry.h +++ b/python/gtsam/specializations/geometry.h @@ -11,13 +11,6 @@ * and saves one copy operation. */ -py::bind_vector< - std::vector>>( - m_, "Point2Vector"); -py::bind_vector>(m_, "Point2Pairs"); -py::bind_vector>(m_, "Point3Pairs"); -py::bind_vector>(m_, "Pose3Pairs"); -py::bind_vector>(m_, "Pose3Vector"); py::bind_vector>>( m_, "CameraSetCal3_S2"); py::bind_vector>>( From f5da8522221b6d6e2e5f7de0eeec890f08074a5c Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 12:49:06 -0500 Subject: [PATCH 0030/1497] remove KeyVector --- gtsam/gtsam.i | 54 ---------------------------- python/gtsam/preamble/gtsam.h | 5 --- python/gtsam/specializations/gtsam.h | 8 ----- 3 files changed, 67 deletions(-) diff --git a/gtsam/gtsam.i b/gtsam/gtsam.i index d4e959c3dd..45bd61d0b1 100644 --- a/gtsam/gtsam.i +++ b/gtsam/gtsam.i @@ -66,27 +66,6 @@ class KeySet { void serialize() const; }; -// Actually a vector -class KeyVector { - KeyVector(); - KeyVector(const gtsam::KeyVector& other); - - // Note: no print function - - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - size_t at(size_t i) const; - size_t front() const; - size_t back() const; - void push_back(size_t key) const; - - void serialize() const; -}; - // Actually a FastMap class KeyGroupMap { KeyGroupMap(); @@ -104,39 +83,6 @@ class KeyGroupMap { bool insert2(size_t key, int val); }; -// Actually a FastSet -class FactorIndexSet { - FactorIndexSet(); - FactorIndexSet(const gtsam::FactorIndexSet& set); - - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - void insert(size_t factorIndex); - bool erase(size_t factorIndex); // returns true if value was removed - bool count(size_t factorIndex) const; // returns true if value exists -}; - -// Actually a vector -class FactorIndices { - FactorIndices(); - FactorIndices(const gtsam::FactorIndices& other); - - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - size_t at(size_t i) const; - size_t front() const; - size_t back() const; - void push_back(size_t factorIndex) const; -}; - //************************************************************************* // Utilities //************************************************************************* diff --git a/python/gtsam/preamble/gtsam.h b/python/gtsam/preamble/gtsam.h index ec39c410a8..d07a75f6fb 100644 --- a/python/gtsam/preamble/gtsam.h +++ b/python/gtsam/preamble/gtsam.h @@ -10,8 +10,3 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ -#ifdef GTSAM_ALLOCATOR_TBB -PYBIND11_MAKE_OPAQUE(std::vector>); -#else -PYBIND11_MAKE_OPAQUE(std::vector); -#endif diff --git a/python/gtsam/specializations/gtsam.h b/python/gtsam/specializations/gtsam.h index 490d719023..da8842eaf4 100644 --- a/python/gtsam/specializations/gtsam.h +++ b/python/gtsam/specializations/gtsam.h @@ -10,11 +10,3 @@ * with `PYBIND11_MAKE_OPAQUE` this allows the types to be modified with Python, * and saves one copy operation. */ - -#ifdef GTSAM_ALLOCATOR_TBB -py::bind_vector > >(m_, "KeyVector"); -py::implicitly_convertible > >(); -#else -py::bind_vector >(m_, "KeyVector"); -py::implicitly_convertible >(); -#endif From b93145cd89c420a47a95cd0deea29474548dad6a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 13:33:09 -0500 Subject: [PATCH 0031/1497] remove unneeded code --- gtsam/geometry/Rot3.h | 3 --- gtsam/sfm/sfm.i | 16 ---------------- gtsam/slam/slam.i | 20 +------------------- python/gtsam/gtsam.tpl | 2 +- python/gtsam/preamble/base.h | 1 - python/gtsam/preamble/slam.h | 6 ------ python/gtsam/specializations/sfm.h | 4 ---- python/gtsam/specializations/slam.h | 8 -------- 8 files changed, 2 insertions(+), 58 deletions(-) diff --git a/gtsam/geometry/Rot3.h b/gtsam/geometry/Rot3.h index 18bd88b52c..d313883d92 100644 --- a/gtsam/geometry/Rot3.h +++ b/gtsam/geometry/Rot3.h @@ -564,9 +564,6 @@ class GTSAM_EXPORT Rot3 : public LieGroup { #endif }; - /// std::vector of Rot3s, mainly for wrapper - using Rot3Vector = std::vector >; - /** * [RQ] receives a 3 by 3 matrix and returns an upper triangular matrix R * and 3 rotation angles corresponding to the rotation matrix Q=Qz'*Qy'*Qx' diff --git a/gtsam/sfm/sfm.i b/gtsam/sfm/sfm.i index 705892e60f..31057ec4b7 100644 --- a/gtsam/sfm/sfm.i +++ b/gtsam/sfm/sfm.i @@ -29,13 +29,6 @@ class BinaryMeasurement { typedef gtsam::BinaryMeasurement BinaryMeasurementUnit3; typedef gtsam::BinaryMeasurement BinaryMeasurementRot3; -class BinaryMeasurementsUnit3 { - BinaryMeasurementsUnit3(); - size_t size() const; - gtsam::BinaryMeasurement at(size_t idx) const; - void push_back(const gtsam::BinaryMeasurement& measurement); -}; - #include // TODO(frank): copy/pasta below until we have integer template paremeters in @@ -178,15 +171,6 @@ class ShonanAveraging3 { #include -class KeyPairDoubleMap { - KeyPairDoubleMap(); - KeyPairDoubleMap(const gtsam::KeyPairDoubleMap& other); - - size_t size() const; - bool empty() const; - void clear(); - size_t at(const pair& keypair) const; -}; class MFAS { MFAS(const gtsam::BinaryMeasurementsUnit3& relativeTranslations, diff --git a/gtsam/slam/slam.i b/gtsam/slam/slam.i index e044dd2c19..da06c0e267 100644 --- a/gtsam/slam/slam.i +++ b/gtsam/slam/slam.i @@ -268,24 +268,6 @@ void save2D(const gtsam::NonlinearFactorGraph& graph, const gtsam::Values& config, gtsam::noiseModel::Diagonal* model, string filename); -// std::vector::shared_ptr> -// Ignored by pybind -> will be List[BetweenFactorPose2] -class BetweenFactorPose2s { - BetweenFactorPose2s(); - size_t size() const; - gtsam::BetweenFactor* at(size_t i) const; - void push_back(const gtsam::BetweenFactor* factor); -}; -gtsam::BetweenFactorPose2s parse2DFactors(string filename); - -// std::vector::shared_ptr> -// Ignored by pybind -> will be List[BetweenFactorPose3] -class BetweenFactorPose3s { - BetweenFactorPose3s(); - size_t size() const; - gtsam::BetweenFactor* at(size_t i) const; - void push_back(const gtsam::BetweenFactor* factor); -}; gtsam::BetweenFactorPose3s parse3DFactors(string filename); pair load3D(string filename); @@ -323,7 +305,7 @@ virtual class KarcherMeanFactor : gtsam::NonlinearFactor { KarcherMeanFactor(const gtsam::KeyVector& keys); }; -gtsam::Rot3 FindKarcherMean(const gtsam::Rot3Vector& rotations); +gtsam::Rot3 FindKarcherMean(const std::vector& rotations); #include gtsam::noiseModel::Isotropic* ConvertNoiseModel(gtsam::noiseModel::Base* model, diff --git a/python/gtsam/gtsam.tpl b/python/gtsam/gtsam.tpl index bdeb2bccce..a974b246b1 100644 --- a/python/gtsam/gtsam.tpl +++ b/python/gtsam/gtsam.tpl @@ -11,8 +11,8 @@ {include_boost} #include -#include #include +#include #include #include #include diff --git a/python/gtsam/preamble/base.h b/python/gtsam/preamble/base.h index 626b47ae4a..a7effd1caa 100644 --- a/python/gtsam/preamble/base.h +++ b/python/gtsam/preamble/base.h @@ -12,5 +12,4 @@ */ PYBIND11_MAKE_OPAQUE(std::vector); - PYBIND11_MAKE_OPAQUE(std::vector); // JacobianVector diff --git a/python/gtsam/preamble/slam.h b/python/gtsam/preamble/slam.h index f7bf5863c6..d07a75f6fb 100644 --- a/python/gtsam/preamble/slam.h +++ b/python/gtsam/preamble/slam.h @@ -10,9 +10,3 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ - -PYBIND11_MAKE_OPAQUE( - std::vector > >); -PYBIND11_MAKE_OPAQUE( - std::vector > >); -PYBIND11_MAKE_OPAQUE(gtsam::Rot3Vector); diff --git a/python/gtsam/specializations/sfm.h b/python/gtsam/specializations/sfm.h index 6de15217fb..da8842eaf4 100644 --- a/python/gtsam/specializations/sfm.h +++ b/python/gtsam/specializations/sfm.h @@ -10,7 +10,3 @@ * with `PYBIND11_MAKE_OPAQUE` this allows the types to be modified with Python, * and saves one copy operation. */ - -py::bind_vector > >( - m_, "BinaryMeasurementsUnit3"); -py::bind_map(m_, "KeyPairDoubleMap"); diff --git a/python/gtsam/specializations/slam.h b/python/gtsam/specializations/slam.h index 6a439c370e..da8842eaf4 100644 --- a/python/gtsam/specializations/slam.h +++ b/python/gtsam/specializations/slam.h @@ -10,11 +10,3 @@ * with `PYBIND11_MAKE_OPAQUE` this allows the types to be modified with Python, * and saves one copy operation. */ - -py::bind_vector< - std::vector>>>( - m_, "BetweenFactorPose3s"); -py::bind_vector< - std::vector>>>( - m_, "BetweenFactorPose2s"); -py::bind_vector(m_, "Rot3Vector"); From 042c236123a9a804676fc1bcbbd72ba82cdb6390 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 14:08:13 -0500 Subject: [PATCH 0032/1497] update python tests --- gtsam/base/base.i | 14 +++++++- .../examples/TranslationAveragingExample.py | 11 +++--- python/gtsam/symbol_shorthand.py | 2 +- python/gtsam/tests/test_Cal3Fisheye.py | 13 ++++--- python/gtsam/tests/test_Cal3Unified.py | 13 ++++--- python/gtsam/tests/test_DecisionTreeFactor.py | 3 +- python/gtsam/tests/test_KarcherMeanFactor.py | 11 +++--- python/gtsam/tests/test_Pose2.py | 7 ++-- python/gtsam/tests/test_ShonanAveraging.py | 15 +++----- python/gtsam/tests/test_Sim3.py | 13 ++++--- .../gtsam/tests/test_TranslationRecovery.py | 6 ++-- python/gtsam/tests/test_Triangulation.py | 34 ++++++------------- 12 files changed, 63 insertions(+), 79 deletions(-) diff --git a/gtsam/base/base.i b/gtsam/base/base.i index f4184fa125..fbbd915533 100644 --- a/gtsam/base/base.i +++ b/gtsam/base/base.i @@ -41,9 +41,21 @@ class DSFMap { std::map sets(); }; +class IndexPairVector { + IndexPairVector(); + IndexPairVector(const gtsam::IndexPairVector& other); -gtsam::IndexPairVector IndexPairSetAsArray(gtsam::IndexPairSet& set); + // common STL methods + size_t size() const; + bool empty() const; + void clear(); + + // structure specific methods + gtsam::IndexPair at(size_t i) const; + void push_back(gtsam::IndexPair key) const; +}; +gtsam::IndexPairVector IndexPairSetAsArray(gtsam::IndexPairSet& set); #include bool linear_independent(Matrix A, Matrix B, double tol); diff --git a/python/gtsam/examples/TranslationAveragingExample.py b/python/gtsam/examples/TranslationAveragingExample.py index 054b61126c..a29b7e6a4a 100644 --- a/python/gtsam/examples/TranslationAveragingExample.py +++ b/python/gtsam/examples/TranslationAveragingExample.py @@ -17,9 +17,8 @@ from collections import defaultdict from typing import List, Tuple -import numpy as np - import gtsam +import numpy as np from gtsam.examples import SFMdata # Hyperparameters for 1dsfm, values used from Kyle Wilson's code. @@ -59,7 +58,7 @@ def get_data() -> Tuple[gtsam.Values, List[gtsam.BinaryMeasurementUnit3]]: return wRc_values, i_iZj_list -def filter_outliers(w_iZj_list: gtsam.BinaryMeasurementsUnit3) -> gtsam.BinaryMeasurementsUnit3: +def filter_outliers(w_iZj_list: List[gtsam.BinaryMeasurementUnit3]) -> List[gtsam.BinaryMeasurementUnit3]: """Removes outliers from a list of Unit3 measurements that are the translation directions from camera i to camera j in the world frame.""" @@ -89,14 +88,14 @@ def filter_outliers(w_iZj_list: gtsam.BinaryMeasurementsUnit3) -> gtsam.BinaryMe avg_outlier_weights[keypair] += weight / len(outlier_weights) # Remove w_iZj that have weight greater than threshold, these are outliers. - w_iZj_inliers = gtsam.BinaryMeasurementsUnit3() + w_iZj_inliers = [] [w_iZj_inliers.append(w_iZj) for w_iZj in w_iZj_list if avg_outlier_weights[( w_iZj.key1(), w_iZj.key2())] < OUTLIER_WEIGHT_THRESHOLD] return w_iZj_inliers -def estimate_poses(i_iZj_list: gtsam.BinaryMeasurementsUnit3, +def estimate_poses(i_iZj_list: List[gtsam.BinaryMeasurementUnit3], wRc_values: gtsam.Values) -> gtsam.Values: """Estimate poses given rotations and normalized translation directions between cameras. @@ -112,7 +111,7 @@ def estimate_poses(i_iZj_list: gtsam.BinaryMeasurementsUnit3, """ # Convert the translation direction measurements to world frame using the rotations. - w_iZj_list = gtsam.BinaryMeasurementsUnit3() + w_iZj_list = [] for i_iZj in i_iZj_list: w_iZj = gtsam.Unit3(wRc_values.atRot3(i_iZj.key1()) .rotate(i_iZj.measured().point3())) diff --git a/python/gtsam/symbol_shorthand.py b/python/gtsam/symbol_shorthand.py index 748d365584..5f7866d181 100644 --- a/python/gtsam/symbol_shorthand.py +++ b/python/gtsam/symbol_shorthand.py @@ -1,4 +1,4 @@ # This trick is to allow direct import of sub-modules # without this, we can only do `from gtsam.gtsam.symbol_shorthand import X` # with this trick, we can do `from gtsam.symbol_shorthand import X` -from .gtsam.symbol_shorthand import * \ No newline at end of file +from .gtsam.symbol_shorthand import * diff --git a/python/gtsam/tests/test_Cal3Fisheye.py b/python/gtsam/tests/test_Cal3Fisheye.py index e54afc7574..246ec19eea 100644 --- a/python/gtsam/tests/test_Cal3Fisheye.py +++ b/python/gtsam/tests/test_Cal3Fisheye.py @@ -11,11 +11,10 @@ """ import unittest -import numpy as np - import gtsam -from gtsam.utils.test_case import GtsamTestCase +import numpy as np from gtsam.symbol_shorthand import K, L, P +from gtsam.utils.test_case import GtsamTestCase def ulp(ftype=np.float64): @@ -51,9 +50,9 @@ def setUpClass(cls): camera1 = gtsam.PinholeCameraCal3Fisheye(pose1) camera2 = gtsam.PinholeCameraCal3Fisheye(pose2) cls.origin = np.array([0.0, 0.0, 0.0]) - cls.poses = gtsam.Pose3Vector([pose1, pose2]) - cls.cameras = gtsam.CameraSetCal3Fisheye([camera1, camera2]) - cls.measurements = gtsam.Point2Vector([k.project(cls.origin) for k in cls.cameras]) + cls.poses = [pose1, pose2] + cls.cameras = [camera1, camera2] + cls.measurements = [k.project(cls.origin) for k in cls.cameras] def test_Cal3Fisheye(self): K = gtsam.Cal3Fisheye() @@ -187,7 +186,7 @@ def test_triangulation_skipped(self): def test_triangulation_rectify(self): """Estimate spatial point from image measurements using rectification""" - rectified = gtsam.Point2Vector([k.calibration().calibrate(pt) for k, pt in zip(self.cameras, self.measurements)]) + rectified = [k.calibration().calibrate(pt) for k, pt in zip(self.cameras, self.measurements)] shared_cal = gtsam.Cal3_S2() triangulated = gtsam.triangulatePoint3(self.poses, shared_cal, rectified, rank_tol=1e-9, optimize=False) self.gtsamAssertEquals(triangulated, self.origin) diff --git a/python/gtsam/tests/test_Cal3Unified.py b/python/gtsam/tests/test_Cal3Unified.py index bafbacfa40..da9f4a9393 100644 --- a/python/gtsam/tests/test_Cal3Unified.py +++ b/python/gtsam/tests/test_Cal3Unified.py @@ -10,11 +10,10 @@ """ import unittest -import numpy as np - import gtsam -from gtsam.utils.test_case import GtsamTestCase +import numpy as np from gtsam.symbol_shorthand import K, L, P +from gtsam.utils.test_case import GtsamTestCase class TestCal3Unified(GtsamTestCase): @@ -48,9 +47,9 @@ def setUpClass(cls): camera1 = gtsam.PinholeCameraCal3Unified(pose1, cls.stereographic) camera2 = gtsam.PinholeCameraCal3Unified(pose2, cls.stereographic) cls.origin = np.array([0.0, 0.0, 0.0]) - cls.poses = gtsam.Pose3Vector([pose1, pose2]) - cls.cameras = gtsam.CameraSetCal3Unified([camera1, camera2]) - cls.measurements = gtsam.Point2Vector([k.project(cls.origin) for k in cls.cameras]) + cls.poses = [pose1, pose2] + cls.cameras = [camera1, camera2] + cls.measurements = [k.project(cls.origin) for k in cls.cameras] def test_Cal3Unified(self): K = gtsam.Cal3Unified() @@ -147,7 +146,7 @@ def test_triangulation(self): def test_triangulation_rectify(self): """Estimate spatial point from image measurements using rectification""" - rectified = gtsam.Point2Vector([k.calibration().calibrate(pt) for k, pt in zip(self.cameras, self.measurements)]) + rectified = [k.calibration().calibrate(pt) for k, pt in zip(self.cameras, self.measurements)] shared_cal = gtsam.Cal3_S2() triangulated = gtsam.triangulatePoint3(self.poses, shared_cal, rectified, rank_tol=1e-9, optimize=False) self.gtsamAssertEquals(triangulated, self.origin) diff --git a/python/gtsam/tests/test_DecisionTreeFactor.py b/python/gtsam/tests/test_DecisionTreeFactor.py index 0499e72154..1b85989536 100644 --- a/python/gtsam/tests/test_DecisionTreeFactor.py +++ b/python/gtsam/tests/test_DecisionTreeFactor.py @@ -13,7 +13,8 @@ import unittest -from gtsam import DecisionTreeFactor, DiscreteValues, DiscreteDistribution, Ordering +from gtsam import (DecisionTreeFactor, DiscreteDistribution, DiscreteValues, + Ordering) from gtsam.utils.test_case import GtsamTestCase diff --git a/python/gtsam/tests/test_KarcherMeanFactor.py b/python/gtsam/tests/test_KarcherMeanFactor.py index f4ec642830..9ec33ad8ab 100644 --- a/python/gtsam/tests/test_KarcherMeanFactor.py +++ b/python/gtsam/tests/test_KarcherMeanFactor.py @@ -31,7 +31,7 @@ class TestKarcherMean(GtsamTestCase): def test_find(self): # Check that optimizing for Karcher mean (which minimizes Between distance) # gets correct result. - rotations = gtsam.Rot3Vector([R, R.inverse()]) + rotations = [R, R.inverse()] expected = Rot3() actual = gtsam.FindKarcherMean(rotations) self.gtsamAssertEquals(expected, actual) @@ -42,7 +42,7 @@ def test_find_karcher_mean_identity(self): a2Rb2 = Rot3() a3Rb3 = Rot3() - aRb_list = gtsam.Rot3Vector([a1Rb1, a2Rb2, a3Rb3]) + aRb_list = [a1Rb1, a2Rb2, a3Rb3] aRb_expected = Rot3() aRb = gtsam.FindKarcherMean(aRb_list) @@ -58,9 +58,7 @@ def test_factor(self): graph = gtsam.NonlinearFactorGraph() R12 = R.compose(R.compose(R)) graph.add(gtsam.BetweenFactorRot3(1, 2, R12, MODEL)) - keys = gtsam.KeyVector() - keys.append(1) - keys.append(2) + keys = [1, 2] graph.add(gtsam.KarcherMeanFactorRot3(keys)) initial = gtsam.Values() @@ -69,8 +67,7 @@ def test_factor(self): expected = Rot3() result = gtsam.GaussNewtonOptimizer(graph, initial).optimize() - actual = gtsam.FindKarcherMean( - gtsam.Rot3Vector([result.atRot3(1), result.atRot3(2)])) + actual = gtsam.FindKarcherMean([result.atRot3(1), result.atRot3(2)]) self.gtsamAssertEquals(expected, actual) self.gtsamAssertEquals( R12, result.atRot3(1).between(result.atRot3(2))) diff --git a/python/gtsam/tests/test_Pose2.py b/python/gtsam/tests/test_Pose2.py index e5ffbad7d1..d70483482e 100644 --- a/python/gtsam/tests/test_Pose2.py +++ b/python/gtsam/tests/test_Pose2.py @@ -10,10 +10,9 @@ """ import unittest -import numpy as np - import gtsam -from gtsam import Point2, Point2Pairs, Pose2 +import numpy as np +from gtsam import Point2, Pose2 from gtsam.utils.test_case import GtsamTestCase @@ -55,7 +54,7 @@ def test_align(self) -> None: ] # fmt: on - ab_pairs = Point2Pairs(list(zip(pts_a, pts_b))) + ab_pairs = list(zip(pts_a, pts_b)) bTa = gtsam.align(ab_pairs) aTb = bTa.inverse() assert aTb is not None diff --git a/python/gtsam/tests/test_ShonanAveraging.py b/python/gtsam/tests/test_ShonanAveraging.py index 19b9f8dc1a..036ea401cf 100644 --- a/python/gtsam/tests/test_ShonanAveraging.py +++ b/python/gtsam/tests/test_ShonanAveraging.py @@ -14,16 +14,9 @@ import gtsam import numpy as np -from gtsam import ( - BetweenFactorPose2, - LevenbergMarquardtParams, - Rot2, - Pose2, - ShonanAveraging2, - ShonanAveragingParameters2, - ShonanAveraging3, - ShonanAveragingParameters3, -) +from gtsam import (BetweenFactorPose2, LevenbergMarquardtParams, Pose2, Rot2, + ShonanAveraging2, ShonanAveraging3, + ShonanAveragingParameters2, ShonanAveragingParameters3) from gtsam.utils.test_case import GtsamTestCase DEFAULT_PARAMS = ShonanAveragingParameters3( @@ -183,7 +176,7 @@ def test_constructorBetweenFactorPose2s(self) -> None: shonan_params.setCertifyOptimality(True) noise_model = gtsam.noiseModel.Unit.Create(3) - between_factors = gtsam.BetweenFactorPose2s() + between_factors = [] for (i1, i2), i2Ri1 in i2Ri1_dict.items(): i2Ti1 = Pose2(i2Ri1, np.zeros(2)) between_factors.append( diff --git a/python/gtsam/tests/test_Sim3.py b/python/gtsam/tests/test_Sim3.py index c00a36435e..c3fd9e9091 100644 --- a/python/gtsam/tests/test_Sim3.py +++ b/python/gtsam/tests/test_Sim3.py @@ -12,10 +12,9 @@ import unittest from typing import List, Optional -import numpy as np - import gtsam -from gtsam import Point3, Pose3, Pose3Pairs, Rot3, Similarity3 +import numpy as np +from gtsam import Point3, Pose3, Rot3, Similarity3 from gtsam.utils.test_case import GtsamTestCase @@ -49,7 +48,7 @@ def test_align_poses_along_straight_line(self): wToi_list = [wTo0, wTo1, wTo2] - we_pairs = Pose3Pairs(list(zip(wToi_list, eToi_list))) + we_pairs = list(zip(wToi_list, eToi_list)) # Recover the transformation wSe (i.e. world_S_egovehicle) wSe = Similarity3.Align(we_pairs) @@ -84,7 +83,7 @@ def test_align_poses_along_straight_line_gauge(self): wToi_list = [wTo0, wTo1, wTo2] - we_pairs = Pose3Pairs(list(zip(wToi_list, eToi_list))) + we_pairs = list(zip(wToi_list, eToi_list)) # Recover the transformation wSe (i.e. world_S_egovehicle) wSe = Similarity3.Align(we_pairs) @@ -122,7 +121,7 @@ def test_align_poses_scaled_squares(self): bTi_list = [bTi0, bTi1, bTi2, bTi3] - ab_pairs = Pose3Pairs(list(zip(aTi_list, bTi_list))) + ab_pairs = list(zip(aTi_list, bTi_list)) # Recover the transformation wSe (i.e. world_S_egovehicle) aSb = Similarity3.Align(ab_pairs) @@ -689,7 +688,7 @@ def align_poses_sim3(aTi_list: List[Pose3], bTi_list: List[Pose3]) -> Similarity assert len(aTi_list) == len(bTi_list) assert n_to_align >= 2, "SIM(3) alignment uses at least 2 frames" - ab_pairs = Pose3Pairs(list(zip(aTi_list, bTi_list))) + ab_pairs = list(zip(aTi_list, bTi_list)) aSb = Similarity3.Align(ab_pairs) diff --git a/python/gtsam/tests/test_TranslationRecovery.py b/python/gtsam/tests/test_TranslationRecovery.py index 0fb0518b60..962b3cc9a4 100644 --- a/python/gtsam/tests/test_TranslationRecovery.py +++ b/python/gtsam/tests/test_TranslationRecovery.py @@ -1,9 +1,9 @@ from __future__ import print_function -import numpy as np import unittest import gtsam +import numpy as np """ Returns example pose values of 3 points A, B and C in the world frame """ def ExampleValues(): @@ -19,7 +19,7 @@ def ExampleValues(): """ Returns binary measurements for the points in the given edges.""" def SimulateMeasurements(gt_poses, graph_edges): - measurements = gtsam.BinaryMeasurementsUnit3() + measurements = [] for edge in graph_edges: Ta = gt_poses.atPose3(edge[0]).translation() Tb = gt_poses.atPose3(edge[1]).translation() @@ -34,7 +34,7 @@ class TestTranslationRecovery(unittest.TestCase): def test_constructor(self): """Construct from binary measurements.""" - algorithm = gtsam.TranslationRecovery(gtsam.BinaryMeasurementsUnit3()) + algorithm = gtsam.TranslationRecovery([]) self.assertIsInstance(algorithm, gtsam.TranslationRecovery) def test_run(self): diff --git a/python/gtsam/tests/test_Triangulation.py b/python/gtsam/tests/test_Triangulation.py index 0a258a0afc..0de0f6d95d 100644 --- a/python/gtsam/tests/test_Triangulation.py +++ b/python/gtsam/tests/test_Triangulation.py @@ -11,23 +11,11 @@ import unittest from typing import Iterable, List, Optional, Tuple, Union -import numpy as np - import gtsam -from gtsam import ( - Cal3_S2, - Cal3Bundler, - CameraSetCal3_S2, - CameraSetCal3Bundler, - PinholeCameraCal3_S2, - PinholeCameraCal3Bundler, - Point2, - Point2Vector, - Point3, - Pose3, - Pose3Vector, - Rot3, -) +import numpy as np +from gtsam import (Cal3_S2, Cal3Bundler, CameraSetCal3_S2, + CameraSetCal3Bundler, PinholeCameraCal3_S2, + PinholeCameraCal3Bundler, Point2, Point3, Pose3, Rot3) from gtsam.utils.test_case import GtsamTestCase UPRIGHT = Rot3.Ypr(-np.pi / 2, 0.0, -np.pi / 2) @@ -44,9 +32,7 @@ def setUp(self): # create second camera 1 meter to the right of first camera pose2 = pose1.compose(Pose3(Rot3(), Point3(1, 0, 0))) # twoPoses - self.poses = Pose3Vector() - self.poses.append(pose1) - self.poses.append(pose2) + self.poses = [pose1, pose2] # landmark ~5 meters infront of camera self.landmark = Point3(5, 0.5, 1.2) @@ -58,7 +44,7 @@ def generate_measurements( cal_params: Iterable[Iterable[Union[int, float]]], camera_set: Optional[Union[CameraSetCal3Bundler, CameraSetCal3_S2]] = None, - ) -> Tuple[Point2Vector, Union[CameraSetCal3Bundler, CameraSetCal3_S2, + ) -> Tuple[List[Point2], Union[CameraSetCal3Bundler, CameraSetCal3_S2, List[Cal3Bundler], List[Cal3_S2]]]: """ Generate vector of measurements for given calibration and camera model. @@ -76,7 +62,7 @@ def generate_measurements( cameras = camera_set() else: cameras = [] - measurements = Point2Vector() + measurements = [] for k, pose in zip(cal_params, self.poses): K = calibration(*k) @@ -105,7 +91,7 @@ def test_TriangulationExample(self) -> None: self.gtsamAssertEquals(self.landmark, triangulated_landmark, 1e-9) # Add some noise and try again: result should be ~ (4.995, 0.499167, 1.19814) - measurements_noisy = Point2Vector() + measurements_noisy = [] measurements_noisy.append(measurements[0] - np.array([0.1, 0.5])) measurements_noisy.append(measurements[1] - np.array([-0.2, 0.3])) @@ -172,8 +158,8 @@ def test_triangulation_robust_three_poses(self) -> None: z2: Point2 = camera2.project(landmark) z3: Point2 = camera3.project(landmark) - poses = gtsam.Pose3Vector([pose1, pose2, pose3]) - measurements = Point2Vector([z1, z2, z3]) + poses = [pose1, pose2, pose3] + measurements = [z1, z2, z3] # noise free, so should give exactly the landmark actual = gtsam.triangulatePoint3(poses, From fe9c5718bbea01f523eb4afb344d5b82f948a484 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 14:09:57 -0500 Subject: [PATCH 0033/1497] update CMake ignore list --- python/CMakeLists.txt | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 85ddc7b6d8..e666dced38 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -34,22 +34,7 @@ set(ignore gtsam::Point2 gtsam::Point3 gtsam::ISAM2ThresholdMapValue - gtsam::FactorIndices - gtsam::FactorIndexSet - gtsam::IndexPairSetMap - gtsam::IndexPairVector - gtsam::BetweenFactorPose2s - gtsam::BetweenFactorPose3s - gtsam::Point2Vector - gtsam::Point2Pairs - gtsam::Point3Pairs - gtsam::Pose3Pairs - gtsam::Pose3Vector - gtsam::Rot3Vector - gtsam::KeyVector - gtsam::BinaryMeasurementsUnit3 - gtsam::DiscreteKey - gtsam::KeyPairDoubleMap) + gtsam::DiscreteKey) set(interface_headers ${PROJECT_SOURCE_DIR}/gtsam/gtsam.i @@ -117,19 +102,11 @@ if(GTSAM_UNSTABLE_BUILD_PYTHON) gtsam::Point2 gtsam::Point3 gtsam::ISAM2ThresholdMapValue - gtsam::FactorIndices - gtsam::FactorIndexSet - gtsam::BetweenFactorPose3s - gtsam::Point2Vector - gtsam::Pose3Vector - gtsam::KeyVector gtsam::FixedLagSmootherKeyTimestampMapValue - gtsam::BinaryMeasurementsUnit3 gtsam::CameraSetCal3_S2 gtsam::CameraSetCal3Bundler gtsam::CameraSetCal3Unified - gtsam::CameraSetCal3Fisheye - gtsam::KeyPairDoubleMap) + gtsam::CameraSetCal3Fisheye) pybind_wrap(${GTSAM_PYTHON_UNSTABLE_TARGET} # target ${PROJECT_SOURCE_DIR}/gtsam_unstable/gtsam_unstable.i # interface_header From c68c986321d2b88fd17900da87c6302e8c236a5c Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 17:54:50 -0500 Subject: [PATCH 0034/1497] Fix IndexPairVector wrapping --- gtsam/base/base.i | 13 ------------- python/gtsam/preamble/base.h | 1 - 2 files changed, 14 deletions(-) diff --git a/gtsam/base/base.i b/gtsam/base/base.i index fbbd915533..212578736d 100644 --- a/gtsam/base/base.i +++ b/gtsam/base/base.i @@ -41,19 +41,6 @@ class DSFMap { std::map sets(); }; -class IndexPairVector { - IndexPairVector(); - IndexPairVector(const gtsam::IndexPairVector& other); - - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - gtsam::IndexPair at(size_t i) const; - void push_back(gtsam::IndexPair key) const; -}; gtsam::IndexPairVector IndexPairSetAsArray(gtsam::IndexPairSet& set); diff --git a/python/gtsam/preamble/base.h b/python/gtsam/preamble/base.h index a7effd1caa..affb03ffae 100644 --- a/python/gtsam/preamble/base.h +++ b/python/gtsam/preamble/base.h @@ -11,5 +11,4 @@ * mutations on Python side will not be reflected on C++. */ -PYBIND11_MAKE_OPAQUE(std::vector); PYBIND11_MAKE_OPAQUE(std::vector); // JacobianVector From ef912eefd3689edf05133c45e3f74483970456e1 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 18:53:39 -0500 Subject: [PATCH 0035/1497] minor cleanup --- python/gtsam/preamble/base.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/gtsam/preamble/base.h b/python/gtsam/preamble/base.h index affb03ffae..d07a75f6fb 100644 --- a/python/gtsam/preamble/base.h +++ b/python/gtsam/preamble/base.h @@ -10,5 +10,3 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ - -PYBIND11_MAKE_OPAQUE(std::vector); // JacobianVector From fbe9a21070c90454bfdf9e3c5dc43d6387e64ffc Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 31 Jan 2022 18:55:40 -0500 Subject: [PATCH 0036/1497] attempt to get custom factor tests passing --- gtsam/nonlinear/CustomFactor.cpp | 16 +++++++++---- gtsam/nonlinear/CustomFactor.h | 5 ++-- python/gtsam/tests/test_custom_factor.py | 29 ++++++++++++------------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/gtsam/nonlinear/CustomFactor.cpp b/gtsam/nonlinear/CustomFactor.cpp index e33caed6fc..b8368c4973 100644 --- a/gtsam/nonlinear/CustomFactor.cpp +++ b/gtsam/nonlinear/CustomFactor.cpp @@ -22,13 +22,14 @@ namespace gtsam { /* * Calculates the unwhitened error by invoking the callback functor (i.e. from Python). */ -Vector CustomFactor::unwhitenedError(const Values& x, boost::optional&> H) const { +Vector CustomFactor::unwhitenedError( + const Values &x, boost::optional&> H) const { if(this->active(x)) { if(H) { /* * In this case, we pass the raw pointer to the `std::vector` object directly to pybind. - * As the type `std::vector` has been marked as opaque in `preamble.h`, any changes in + * As the type `std::vector` has been marked as opaque in `preamble/base.h`, any changes in * Python will be immediately reflected on the C++ side. * * Example: @@ -43,13 +44,20 @@ Vector CustomFactor::unwhitenedError(const Values& x, boost::optionalerror_function_(*this, x, H.get_ptr()); + std::pair errorAndJacobian = + this->error_function_(*this, x, H.get_ptr()); + + Vector error = errorAndJacobian.first; + (*H) = errorAndJacobian.second; + + return error; } else { /* * In this case, we pass the a `nullptr` to pybind, and it will translate to `None` in Python. * Users can check for `None` in their callback to determine if the Jacobian is requested. */ - return this->error_function_(*this, x, nullptr); + auto errorAndJacobian = this->error_function_(*this, x, nullptr); + return errorAndJacobian.first; } } else { return Vector::Zero(this->dim()); diff --git a/gtsam/nonlinear/CustomFactor.h b/gtsam/nonlinear/CustomFactor.h index 615b5418e8..6261636b5f 100644 --- a/gtsam/nonlinear/CustomFactor.h +++ b/gtsam/nonlinear/CustomFactor.h @@ -35,7 +35,8 @@ class CustomFactor; * This is safe because this is passing a const pointer, and pybind11 will maintain the `std::vector` memory layout. * Thus the pointer will never be invalidated. */ -using CustomErrorFunction = std::function; +using CustomErrorFunction = std::function( + const CustomFactor &, const Values &, JacobianVector *)>; /** * @brief Custom factor that takes a std::function as the error @@ -77,7 +78,7 @@ class CustomFactor: public NoiseModelFactor { * Calls the errorFunction closure, which is a std::function object * One can check if a derivative is needed in the errorFunction by checking the length of Jacobian array */ - Vector unwhitenedError(const Values &x, boost::optional &> H = boost::none) const override; + Vector unwhitenedError(const Values &x, boost::optional&> H = boost::none) const override; /** print */ void print(const std::string &s, diff --git a/python/gtsam/tests/test_custom_factor.py b/python/gtsam/tests/test_custom_factor.py index 4f0f333619..03e6917f09 100644 --- a/python/gtsam/tests/test_custom_factor.py +++ b/python/gtsam/tests/test_custom_factor.py @@ -8,13 +8,12 @@ CustomFactor unit tests. Author: Fan Jiang """ -from typing import List import unittest -from gtsam import Values, Pose2, CustomFactor - -import numpy as np +from typing import List import gtsam +import numpy as np +from gtsam import CustomFactor, JacobianFactor, Pose2, Values from gtsam.utils.test_case import GtsamTestCase @@ -24,17 +23,17 @@ def test_new(self): def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): """Minimal error function stub""" - return np.array([1, 0, 0]) + return np.array([1, 0, 0]), H noise_model = gtsam.noiseModel.Unit.Create(3) - cf = CustomFactor(noise_model, gtsam.KeyVector([0]), error_func) + cf = CustomFactor(noise_model, [0], error_func) def test_new_keylist(self): """Test the creation of a new CustomFactor""" def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): """Minimal error function stub""" - return np.array([1, 0, 0]) + return np.array([1, 0, 0]), H noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0], error_func) @@ -47,7 +46,7 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]) -> np.n """Minimal error function with no Jacobian""" key0 = this.keys()[0] error = -v.atPose2(key0).localCoordinates(expected_pose) - return error + return error, H noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0], error_func) @@ -81,10 +80,10 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): result = gT1.between(gT2) H[0] = -result.inverse().AdjointMap() H[1] = np.eye(3) - return error + return error, H noise_model = gtsam.noiseModel.Unit.Create(3) - cf = CustomFactor(noise_model, gtsam.KeyVector([0, 1]), error_func) + cf = CustomFactor(noise_model, [0, 1], error_func) v = Values() v.insert(0, gT1) v.insert(1, gT2) @@ -104,9 +103,9 @@ def test_printing(self): gT1 = Pose2(1, 2, np.pi / 2) gT2 = Pose2(-1, 4, np.pi) - def error_func(this: CustomFactor, v: gtsam.Values, _: List[np.ndarray]): + def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): """Minimal error function stub""" - return np.array([1, 0, 0]) + return np.array([1, 0, 0]), H noise_model = gtsam.noiseModel.Unit.Create(3) from gtsam.symbol_shorthand import X @@ -144,10 +143,10 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): result = gT1.between(gT2) H[0] = -result.inverse().AdjointMap() H[1] = np.eye(3) - return error + return error, H noise_model = gtsam.noiseModel.Unit.Create(3) - cf = CustomFactor(noise_model, gtsam.KeyVector([0, 1]), error_func) + cf = CustomFactor(noise_model, [0, 1], error_func) v = Values() v.insert(0, gT1) v.insert(1, gT2) @@ -182,7 +181,7 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): result = gT1.between(gT2) H[0] = -result.inverse().AdjointMap() H[1] = np.eye(3) - return error + return error, H noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0, 1], error_func) From 0f951643bd1395a11068a6132f8e773d40c2d268 Mon Sep 17 00:00:00 2001 From: Grady Williams Date: Tue, 15 Feb 2022 13:52:12 -0800 Subject: [PATCH 0037/1497] Adding failing tests for ISAM2 marginalization --- tests/testGaussianISAM2.cpp | 150 ++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/tests/testGaussianISAM2.cpp b/tests/testGaussianISAM2.cpp index e8e916f046..efe34ee31f 100644 --- a/tests/testGaussianISAM2.cpp +++ b/tests/testGaussianISAM2.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -662,6 +663,76 @@ namespace { bool ok = treeEqual && /*linEqual &&*/ nonlinEqual && /*linCorrect &&*/ /*afterLinCorrect &&*/ afterNonlinCorrect; return ok; } + + boost::optional> createOrderingConstraints(const ISAM2& isam, const KeyVector& newKeys, const KeySet& marginalizableKeys) + { + if (marginalizableKeys.empty()) { + return boost::none; + } else { + FastMap constrainedKeys = FastMap(); + // Generate ordering constraints so that the marginalizable variables will be eliminated first + // Set all existing and new variables to Group1 + for (const auto& key_val : isam.getDelta()) { + constrainedKeys.emplace(key_val.first, 1); + } + for (const auto& key : newKeys) { + constrainedKeys.emplace(key, 1); + } + // And then re-assign the marginalizable variables to Group0 so that they'll all be leaf nodes + for (const auto& key : marginalizableKeys) { + constrainedKeys.at(key) = 0; + } + return constrainedKeys; + } + } + + void markAffectedKeys(const Key& key, const ISAM2Clique::shared_ptr& rootClique, KeyList& additionalKeys) + { + std::stack frontier; + frontier.push(rootClique); + // Basic DFS to find additional keys + while (!frontier.empty()) { + // Get the top of the stack + const ISAM2Clique::shared_ptr clique = frontier.top(); + frontier.pop(); + // Check if we have more keys and children to add + if (std::find(clique->conditional()->beginParents(), clique->conditional()->endParents(), key) != + clique->conditional()->endParents()) { + for (Key i : clique->conditional()->frontals()) { + additionalKeys.push_back(i); + } + for (const ISAM2Clique::shared_ptr& child : clique->children) { + frontier.push(child); + } + } + } + } + + bool updateAndMarginalize(const NonlinearFactorGraph& newFactors, const Values& newValues, const KeySet& marginalizableKeys, ISAM2& isam) + { + // Force ISAM2 to put marginalizable variables at the beginning + const boost::optional> orderingConstraints = createOrderingConstraints(isam, newValues.keys(), marginalizableKeys); + + // Mark additional keys between the marginalized keys and the leaves + KeyList additionalMarkedKeys; + for (Key key : marginalizableKeys) { + ISAM2Clique::shared_ptr clique = isam[key]; + for (const ISAM2Clique::shared_ptr& child : clique->children) { + markAffectedKeys(key, child, additionalMarkedKeys); + } + } + + // Update + isam.update(newFactors, newValues, FactorIndices{}, orderingConstraints, boost::none, additionalMarkedKeys); + + if (!marginalizableKeys.empty()) { + FastList leafKeys(marginalizableKeys.begin(), marginalizableKeys.end()); + return checkMarginalizeLeaves(isam, leafKeys); + } + else { + return true; + } + } } /* ************************************************************************* */ @@ -795,6 +866,85 @@ TEST(ISAM2, marginalizeLeaves5) EXPECT(checkMarginalizeLeaves(isam, marginalizeKeys)); } +/* ************************************************************************* */ +TEST(ISAM2, marginalizeLeaves6) +{ + const boost::shared_ptr nm = noiseModel::Isotropic::Sigma(6, 1.0); + + int gridDim = 10; + + auto idxToKey = [gridDim](int i, int j){return i * gridDim + j;}; + + NonlinearFactorGraph factors; + Values values; + ISAM2 isam; + + // Create a grid of pose variables + for (int i = 0; i < gridDim; ++i) { + for (int j = 0; j < gridDim; ++j) { + Pose3 pose = Pose3(Rot3::identity(), Point3(i, j, 0)); + Key key = idxToKey(i, j); + // Place a prior on the first pose + factors.addPrior(key, Pose3(Rot3::identity(), Point3(i, j, 0)), nm); + values.insert(key, pose); + if (i > 0) { + factors.emplace_shared>(idxToKey(i - 1, j), key, Pose3(Rot3::identity(), Point3(1, 0, 0)),nm); + } + if (j > 0) { + factors.emplace_shared>(idxToKey(i, j - 1), key, Pose3(Rot3::identity(), Point3(0, 1, 0)),nm); + } + } + } + + // Optimize the graph + EXPECT(updateAndMarginalize(factors, values, {}, isam)); + auto estimate = isam.calculateBestEstimate(); + + // Get the list of keys + std::vector key_list(gridDim * gridDim); + std::iota(key_list.begin(), key_list.end(), 0); + + // Shuffle the keys -> we will marginalize the keys one by one in this order + std::shuffle(key_list.begin(), key_list.end(), std::default_random_engine(1234)); + + for (const auto& key : key_list) { + KeySet marginalKeys; + marginalKeys.insert(key); + EXPECT(updateAndMarginalize({}, {}, marginalKeys, isam)); + estimate = isam.calculateBestEstimate(); + } +} + +/* ************************************************************************* */ +TEST(ISAM2, MarginalizeRoot) +{ + const boost::shared_ptr nm = noiseModel::Isotropic::Sigma(6, 1.0); + + NonlinearFactorGraph factors; + Values values; + ISAM2 isam; + + // Create a factor graph with one variable and a prior + Pose3 root = Pose3::identity(); + Key rootKey(0); + values.insert(rootKey, root); + factors.addPrior(rootKey, Pose3::identity(), nm); + + // Optimize the graph + EXPECT(updateAndMarginalize(factors, values, {}, isam)); + auto estimate = isam.calculateBestEstimate(); + EXPECT(estimate.size() == 1); + + // And remove the node from the graph + KeySet marginalizableKeys; + marginalizableKeys.insert(rootKey); + + EXPECT(updateAndMarginalize({}, {}, marginalizableKeys, isam)); + + estimate = isam.calculateBestEstimate(); + EXPECT(estimate.empty()); +} + /* ************************************************************************* */ TEST(ISAM2, marginalCovariance) { From 9e1046f40e21bd66b4db5fe300aa0e46b39365a4 Mon Sep 17 00:00:00 2001 From: Grady Williams Date: Sat, 16 Apr 2022 13:53:39 -0700 Subject: [PATCH 0038/1497] Test for not increasing graph size when adding marginal factors --- tests/testGaussianISAM2.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/testGaussianISAM2.cpp b/tests/testGaussianISAM2.cpp index efe34ee31f..940051b96a 100644 --- a/tests/testGaussianISAM2.cpp +++ b/tests/testGaussianISAM2.cpp @@ -945,6 +945,37 @@ TEST(ISAM2, MarginalizeRoot) EXPECT(estimate.empty()); } +/* ************************************************************************* */ +TEST(ISAM2, marginalizationSize) +{ + const boost::shared_ptr nm = noiseModel::Isotropic::Sigma(6, 1.0); + + NonlinearFactorGraph factors; + Values values; + ISAM2Params params; + params.findUnusedFactorSlots = true; + ISAM2 isam{params}; + + // Create a pose variable + Key aKey(0); + values.insert(aKey, Pose3::identity()); + factors.addPrior(aKey, Pose3::identity(), nm); + // Create another pose variable linked to the first + Pose3 b = Pose3::identity(); + Key bKey(1); + values.insert(bKey, Pose3::identity()); + factors.emplace_shared>(aKey, bKey, Pose3::identity(), nm); + // Optimize the graph + EXPECT(updateAndMarginalize(factors, values, {}, isam)); + + // Now remove a variable -> we should not see the number of factors increase + gtsam::KeySet to_remove; + to_remove.insert(aKey); + const auto numFactorsBefore = isam.getFactorsUnsafe().size(); + updateAndMarginalize({}, {}, to_remove, isam); + EXPECT(numFactorsBefore == isam.getFactorsUnsafe().size()); +} + /* ************************************************************************* */ TEST(ISAM2, marginalCovariance) { From 66720e0b0276360d1581335332714d2c7e1ecc93 Mon Sep 17 00:00:00 2001 From: Grady Williams Date: Sat, 16 Apr 2022 13:29:53 -0700 Subject: [PATCH 0039/1497] Bugfixes for ISAM2 --- gtsam/nonlinear/ISAM2.cpp | 66 +++++++++++++++++++++++-------------- tests/testGaussianISAM2.cpp | 7 ++-- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/gtsam/nonlinear/ISAM2.cpp b/gtsam/nonlinear/ISAM2.cpp index f56b23777c..a7feca2398 100644 --- a/gtsam/nonlinear/ISAM2.cpp +++ b/gtsam/nonlinear/ISAM2.cpp @@ -552,9 +552,12 @@ void ISAM2::marginalizeLeaves( // We do not need the marginal factors associated with this clique // because their information is already incorporated in the new // marginal factor. So, now associate this marginal factor with the - // parent of this clique. - marginalFactors[clique->parent()->conditional()->front()].push_back( - marginalFactor); + // parent of this clique. If the clique is a root and has no parent, then + // we can discard it without keeping track of the marginal factor. + if (clique->parent()) { + marginalFactors[clique->parent()->conditional()->front()].push_back( + marginalFactor); + } // Now remove this clique and its subtree - all of its marginal // information has been stored in marginalFactors. trackingRemoveSubtree(clique); @@ -632,7 +635,7 @@ void ISAM2::marginalizeLeaves( // Make the clique's matrix appear as a subset const DenseIndex dimToRemove = cg->matrixObject().offset(nToRemove); - cg->matrixObject().firstBlock() = nToRemove; + cg->matrixObject().firstBlock() += nToRemove; cg->matrixObject().rowStart() = dimToRemove; // Change the keys in the clique @@ -658,42 +661,55 @@ void ISAM2::marginalizeLeaves( // At this point we have updated the BayesTree, now update the remaining iSAM2 // data structures + // Remove the factors to remove that will be summarized in marginal factors + NonlinearFactorGraph removedFactors; + for (const auto index : factorIndicesToRemove) { + removedFactors.push_back(nonlinearFactors_[index]); + nonlinearFactors_.remove(index); + if (params_.cacheLinearizedFactors) { + linearFactors_.remove(index); + } + } + variableIndex_.remove(factorIndicesToRemove.begin(), + factorIndicesToRemove.end(), removedFactors); + // Gather factors to add - the new marginal factors - GaussianFactorGraph factorsToAdd; + GaussianFactorGraph factorsToAdd{}; + NonlinearFactorGraph nonlinearFactorsToAdd{}; for (const auto& key_factors : marginalFactors) { for (const auto& factor : key_factors.second) { if (factor) { factorsToAdd.push_back(factor); - if (marginalFactorsIndices) - marginalFactorsIndices->push_back(nonlinearFactors_.size()); - nonlinearFactors_.push_back( - boost::make_shared(factor)); - if (params_.cacheLinearizedFactors) linearFactors_.push_back(factor); + nonlinearFactorsToAdd.emplace_shared(factor); for (Key factorKey : *factor) { fixedVariables_.insert(factorKey); } } } } - variableIndex_.augment(factorsToAdd); // Augment the variable index - - // Remove the factors to remove that have been summarized in the newly-added - // marginal factors - NonlinearFactorGraph removedFactors; - for (const auto index : factorIndicesToRemove) { - removedFactors.push_back(nonlinearFactors_[index]); - nonlinearFactors_.remove(index); - if (params_.cacheLinearizedFactors) linearFactors_.remove(index); + // Add the nonlinear factors and keep track of the new factor indices + auto newFactorIndices = nonlinearFactors_.add_factors(nonlinearFactorsToAdd, + params_.findUnusedFactorSlots); + // Add cached linear factors. + if (params_.cacheLinearizedFactors){ + linearFactors_.resize(nonlinearFactors_.size()); + for (std::size_t i = 0; i < nonlinearFactorsToAdd.size(); ++i){ + linearFactors_[newFactorIndices[i]] = factorsToAdd[i]; + } } - variableIndex_.remove(factorIndicesToRemove.begin(), - factorIndicesToRemove.end(), removedFactors); - - if (deletedFactorsIndices) - deletedFactorsIndices->assign(factorIndicesToRemove.begin(), - factorIndicesToRemove.end()); + // Augment the variable index + variableIndex_.augment(factorsToAdd, newFactorIndices); // Remove the marginalized variables removeVariables(KeySet(leafKeys.begin(), leafKeys.end())); + + if (deletedFactorsIndices) { + deletedFactorsIndices->assign(factorIndicesToRemove.begin(), + factorIndicesToRemove.end()); + } + if (marginalFactorsIndices){ + *marginalFactorsIndices = std::move(newFactorIndices); + } } /* ************************************************************************* */ diff --git a/tests/testGaussianISAM2.cpp b/tests/testGaussianISAM2.cpp index 940051b96a..b2a679d658 100644 --- a/tests/testGaussianISAM2.cpp +++ b/tests/testGaussianISAM2.cpp @@ -714,16 +714,17 @@ namespace { const boost::optional> orderingConstraints = createOrderingConstraints(isam, newValues.keys(), marginalizableKeys); // Mark additional keys between the marginalized keys and the leaves - KeyList additionalMarkedKeys; + KeyList markedKeys; for (Key key : marginalizableKeys) { + markedKeys.push_back(key); ISAM2Clique::shared_ptr clique = isam[key]; for (const ISAM2Clique::shared_ptr& child : clique->children) { - markAffectedKeys(key, child, additionalMarkedKeys); + markAffectedKeys(key, child, markedKeys); } } // Update - isam.update(newFactors, newValues, FactorIndices{}, orderingConstraints, boost::none, additionalMarkedKeys); + isam.update(newFactors, newValues, FactorIndices{}, orderingConstraints, boost::none, markedKeys); if (!marginalizableKeys.empty()) { FastList leafKeys(marginalizableKeys.begin(), marginalizableKeys.end()); From 782a8949882cc851c02f339ce27673185768cd33 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Thu, 21 Apr 2022 15:41:44 -0400 Subject: [PATCH 0040/1497] fix expected serialization string --- gtsam/nonlinear/tests/testSerializationNonlinear.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index b6b5033a2e..63e2ae1dd9 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -120,9 +120,9 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { noiseModel::Unit::Create(6)); // String - std::string expected_str = + std::string serialized_str = "22 serialization::archive 15 1 0\n" - "0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" + "0 0 0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" "1 1 0\n" "2 1 0\n" "3 0 0 0 0 6 0 1 0 0 0 6 1.00000000000000000e+00 1.00000000000000000e+00 " @@ -135,10 +135,9 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { "-5.87266449276209815e-02 -4.26917621276207360e-01 " "9.02381585483330806e-01 -9.09297426825681709e-01 " "-3.50175488374014632e-01 -2.24845095366152908e-01 0 0 " - "4.00000000000000000e+00 5.00000000000000000e+00 " - "6.00000000000000000e+00\n"; + "4.00000000000000000e+00 5.00000000000000000e+00 6.00000000000000000e+00"; PriorFactor factor_deserialized_str = PriorFactor(); - deserializeFromString(expected_str, factor_deserialized_str); + deserializeFromString(serialized_str, factor_deserialized_str); EXPECT(assert_equal(factor, factor_deserialized_str)); // XML From 2927d92a52ceffaa4af1f743f3b58793ced382cd Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 28 May 2022 15:43:37 -0400 Subject: [PATCH 0041/1497] add HybridNonlinearFactor and nonlinear HybridFactorGraph --- gtsam/hybrid/HybridFactorGraph.h | 108 +++++++++++++++++++++ gtsam/hybrid/HybridNonlinearFactor.cpp | 45 +++++++++ gtsam/hybrid/HybridNonlinearFactor.h | 60 ++++++++++++ gtsam/hybrid/tests/testHybridFactorGraph.h | 50 ++++++++++ 4 files changed, 263 insertions(+) create mode 100644 gtsam/hybrid/HybridFactorGraph.h create mode 100644 gtsam/hybrid/HybridNonlinearFactor.cpp create mode 100644 gtsam/hybrid/HybridNonlinearFactor.h create mode 100644 gtsam/hybrid/tests/testHybridFactorGraph.h diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h new file mode 100644 index 0000000000..f415386ea4 --- /dev/null +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -0,0 +1,108 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file HybridFactorGraph.h + * @brief Nonlinear hybrid factor graph that uses type erasure + * @author Varun Agrawal + * @date May 28, 2022 + */ + +#pragma once + +#include +#include +#include +#include + +namespace gtsam { + +/** + * Hybrid Factor Graph + * ----------------------- + * This is the non-linear version of a hybrid factor graph. + * Everything inside needs to be hybrid factor or hybrid conditional. + */ +class HybridFactorGraph : public FactorGraph { + public: + using Base = FactorGraph; + using This = HybridFactorGraph; ///< this class + using shared_ptr = boost::shared_ptr; ///< shared_ptr to This + + using Values = gtsam::Values; ///< backwards compatibility + using Indices = KeyVector; ///> map from keys to values + + /// @name Constructors + /// @{ + + HybridFactorGraph() = default; + + /** + * Implicit copy/downcast constructor to override explicit template container + * constructor. In BayesTree this is used for: + * `cachedSeparatorMarginal_.reset(*separatorMarginal)` + * */ + template + HybridFactorGraph(const FactorGraph& graph) : Base(graph) {} + + /// @} + + // Allow use of selected FactorGraph methods: + using Base::empty; + using Base::reserve; + using Base::size; + using FactorGraph::add; + using Base::operator[]; + + /// Add a Jacobian factor to the factor graph. + void add(JacobianFactor&& factor); + + /// Add a Jacobian factor as a shared ptr. + void add(boost::shared_ptr factor); + + /// Add a DecisionTreeFactor to the factor graph. + void add(DecisionTreeFactor&& factor); + + /// Add a DecisionTreeFactor as a shared ptr. + void add(boost::shared_ptr factor); + + /** + * @brief Linearize all the continuous factors in the + * NonlinearHybridFactorGraph. + * + * @param continuousValues: Dictionary of continuous values. + * @return GaussianHybridFactorGraph::shared_ptr + */ + GaussianHybridFactorGraph::shared_ptr linearize( + const Values& continuousValues) const { + // create an empty linear FG + GaussianHybridFactorGraph::shared_ptr linearFG = + boost::make_shared(); + + linearFG->reserve(size()); + + // linearize all factors + for (const sharedFactor& factor : factors_) { + if (factor) { + if (auto nf = boost::dynamic_pointer_cast) { + (*linearFG) += factor->linearize(linearizationPoint); + } else if (auto hf = boost::dynamic_pointer_cast) { + if (hf->isContinuous()) { + } + } + + } else + (*linearFG) += GaussianFactor::shared_ptr(); + } + } +}; + +} // namespace gtsam diff --git a/gtsam/hybrid/HybridNonlinearFactor.cpp b/gtsam/hybrid/HybridNonlinearFactor.cpp new file mode 100644 index 0000000000..ee6e76431e --- /dev/null +++ b/gtsam/hybrid/HybridNonlinearFactor.cpp @@ -0,0 +1,45 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file HybridNonlinearFactor.cpp + * @date May 28, 2022 + * @author Varun Agrawal + */ + +#include + +#include + +namespace gtsam { + +/* ************************************************************************* */ +HybridNonlinearFactor::HybridNonlinearFactor(NonlinearFactor::shared_ptr other) + : Base(other->keys()), inner_(other) {} + +/* ************************************************************************* */ +HybridNonlinearFactor::HybridNonlinearFactor(NonlinearFactor &&nf) + : Base(nf.keys()), + inner_(boost::make_shared(std::move(nf))) {} + +/* ************************************************************************* */ +bool HybridNonlinearFactor::equals(const HybridFactor &lf, double tol) const { + return Base(lf, tol); +} + +/* ************************************************************************* */ +void HybridNonlinearFactor::print(const std::string &s, + const KeyFormatter &formatter) const { + HybridFactor::print(s, formatter); + inner_->print("inner: ", formatter); +}; + +} // namespace gtsam diff --git a/gtsam/hybrid/HybridNonlinearFactor.h b/gtsam/hybrid/HybridNonlinearFactor.h new file mode 100644 index 0000000000..74feb05312 --- /dev/null +++ b/gtsam/hybrid/HybridNonlinearFactor.h @@ -0,0 +1,60 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file HybridNonlinearFactor.h + * @date May 28, 2022 + * @author Varun Agrawal + */ + +#pragma once + +#include +#include + +namespace gtsam { + +/** + * A HybridNonlinearFactor is a layer over NonlinearFactor so that we do not + * have a diamond inheritance. + */ +class HybridNonlinearFactor : public HybridFactor { + private: + NonlinearFactor::shared_ptr inner_; + + public: + using Base = HybridFactor; + using This = HybridNonlinearFactor; + using shared_ptr = boost::shared_ptr; + + // Explicit conversion from a shared ptr of GF + explicit HybridNonlinearFactor(NonlinearFactor::shared_ptr other); + + // Forwarding constructor from concrete NonlinearFactor + explicit HybridNonlinearFactor(NonlinearFactor &&jf); + + public: + /// @name Testable + /// @{ + + /// Check equality. + virtual bool equals(const HybridFactor &lf, double tol) const override; + + /// GTSAM print utility. + void print( + const std::string &s = "HybridNonlinearFactor\n", + const KeyFormatter &formatter = DefaultKeyFormatter) const override; + + /// @} + + NonlinearFactor::shared_ptr inner() const { return inner_; } +}; +} // namespace gtsam diff --git a/gtsam/hybrid/tests/testHybridFactorGraph.h b/gtsam/hybrid/tests/testHybridFactorGraph.h new file mode 100644 index 0000000000..284e996ce6 --- /dev/null +++ b/gtsam/hybrid/tests/testHybridFactorGraph.h @@ -0,0 +1,50 @@ +/* ---------------------------------------------------------------------------- + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + * See LICENSE for the license information + * -------------------------------------------------------------------------- */ + +/** + * @file testHybridFactorGraph.cpp + * @brief Unit tests for HybridFactorGraph + * @author Varun Agrawal + * @date May 2021 + */ + +#include +#include +#include + +/* **************************************************************************** + * Test that any linearizedFactorGraph gaussian factors are appended to the + * existing gaussian factor graph in the hybrid factor graph. + */ +TEST(HybridFactorGraph, GaussianFactorGraph) { + // Initialize the hybrid factor graph + HybridFactorGraph fg; + + // Add a simple prior factor to the nonlinear factor graph + fg.emplace_shared>(X(0), 0, Isotropic::Sigma(1, 0.1)); + + // Add a linear factor to the nonlinear factor graph + fg.add(X(0), I_1x1, Vector1(5)); + + // Linearization point + Values linearizationPoint; + linearizationPoint.insert(X(0), 0); + + GaussianHybridFactorGraph ghfg = fg.linearize(linearizationPoint); + + // ghfg.push_back(ghfg.gaussianGraph().begin(), ghfg.gaussianGraph().end()); + + // EXPECT_LONGS_EQUAL(2, dcmfg.gaussianGraph().size()); +} + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +/* ************************************************************************* */ From 78ea90bb27ea338f445100e7eabce390675747a3 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 28 May 2022 18:44:09 -0400 Subject: [PATCH 0042/1497] Add MixtureFactor for nonlinear factor types --- gtsam/hybrid/HybridNonlinearFactor.cpp | 7 +- gtsam/hybrid/HybridNonlinearFactor.h | 3 - gtsam/hybrid/MixtureFactor.h | 240 +++++++++++++++++++++++++ 3 files changed, 241 insertions(+), 9 deletions(-) create mode 100644 gtsam/hybrid/MixtureFactor.h diff --git a/gtsam/hybrid/HybridNonlinearFactor.cpp b/gtsam/hybrid/HybridNonlinearFactor.cpp index ee6e76431e..69a9767900 100644 --- a/gtsam/hybrid/HybridNonlinearFactor.cpp +++ b/gtsam/hybrid/HybridNonlinearFactor.cpp @@ -25,14 +25,9 @@ namespace gtsam { HybridNonlinearFactor::HybridNonlinearFactor(NonlinearFactor::shared_ptr other) : Base(other->keys()), inner_(other) {} -/* ************************************************************************* */ -HybridNonlinearFactor::HybridNonlinearFactor(NonlinearFactor &&nf) - : Base(nf.keys()), - inner_(boost::make_shared(std::move(nf))) {} - /* ************************************************************************* */ bool HybridNonlinearFactor::equals(const HybridFactor &lf, double tol) const { - return Base(lf, tol); + return Base::equals(lf, tol); } /* ************************************************************************* */ diff --git a/gtsam/hybrid/HybridNonlinearFactor.h b/gtsam/hybrid/HybridNonlinearFactor.h index 74feb05312..53d7bfbf47 100644 --- a/gtsam/hybrid/HybridNonlinearFactor.h +++ b/gtsam/hybrid/HybridNonlinearFactor.h @@ -38,9 +38,6 @@ class HybridNonlinearFactor : public HybridFactor { // Explicit conversion from a shared ptr of GF explicit HybridNonlinearFactor(NonlinearFactor::shared_ptr other); - // Forwarding constructor from concrete NonlinearFactor - explicit HybridNonlinearFactor(NonlinearFactor &&jf); - public: /// @name Testable /// @{ diff --git a/gtsam/hybrid/MixtureFactor.h b/gtsam/hybrid/MixtureFactor.h new file mode 100644 index 0000000000..556402058e --- /dev/null +++ b/gtsam/hybrid/MixtureFactor.h @@ -0,0 +1,240 @@ +/* ---------------------------------------------------------------------------- + * Copyright 2020 The Ambitious Folks of the MRG + * See LICENSE for the license information + * -------------------------------------------------------------------------- */ + +/** + * @file MixtureFactor.h + * @brief Nonlinear Mixture factor of continuous and discrete. + * @author Kevin Doherty, kdoherty@mit.edu + * @author Varun Agrawal + * @date December 2021 + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace gtsam { + +/** + * @brief Implementation of a discrete conditional mixture factor. Implements a + * joint discrete-continuous factor where the discrete variable serves to + * "select" a mixture component corresponding to a NonlinearFactor type + * of measurement. + */ +template +class MixtureFactor : public HybridFactor { + public: + using Base = HybridFactor; + using This = MixtureFactor; + using shared_ptr = boost::shared_ptr; + using sharedFactor = boost::shared_ptr; + + /// typedef for DecisionTree which has Keys as node labels and + /// NonlinearFactorType as leaf nodes. + using Factors = DecisionTree; + + private: + /// Decision tree of Gaussian factors indexed by discrete keys. + Factors factors_; + bool normalized_; + + public: + MixtureFactor() = default; + + /** + * @brief Construct from Decision tree. + * + * @param keys Vector of keys for continuous factors. + * @param discreteKeys Vector of discrete keys. + * @param factors Decision tree with of shared factors. + * @param normalized Flag indicating if the factor error is already + * normalized. + */ + MixtureFactor(const KeyVector& keys, const DiscreteKeys& discreteKeys, + const Factors& factors, bool normalized = false) + : Base(keys, discreteKeys), factors_(factors), normalized_(normalized) {} + + /** + * @brief Convenience constructor that generates the underlying factor + * decision tree for us. + * + * Here it is important that the vector of factors has the correct number of + * elements based on the number of discrete keys and the cardinality of the + * keys, so that the decision tree is constructed appropriately. + * + * @param keys Vector of keys for continuous factors. + * @param discreteKeys Vector of discrete keys. + * @param factors Vector of shared pointers to factors. + * @param normalized Flag indicating if the factor error is already + * normalized. + */ + MixtureFactor(const KeyVector& keys, const DiscreteKeys& discreteKeys, + const std::vector& factors, + bool normalized = false) + : MixtureFactor(keys, discreteKeys, Factors(discreteKeys, factors), + normalized) {} + + ~MixtureFactor() = default; + + /** + * @brief Compute error of factor given both continuous and discrete values. + * + * @param continuousVals The continuous Values. + * @param discreteVals The discrete Values. + * @return double The error of this factor. + */ + double error(const Values& continuousVals, + const DiscreteValues& discreteVals) const { + // Retrieve the factor corresponding to the assignment in discreteVals. + auto factor = factors_(discreteVals); + // Compute the error for the selected factor + const double factorError = factor->error(continuousVals); + if (normalized_) return factorError; + return factorError + + this->nonlinearFactorLogNormalizingConstant(*factor, continuousVals); + } + + size_t dim() const { + // TODO(Varun) + throw std::runtime_error("MixtureFactor::dim not implemented."); + } + + /// Testable + /// @{ + + /// print to stdout + void print( + const std::string& s = "MixtureFactor", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override { + std::cout << (s.empty() ? "" : s + " "); + std::cout << "("; + auto contKeys = keys(); + auto dKeys = discreteKeys(); + for (DiscreteKey key : dKeys) { + auto it = std::find(contKeys.begin(), contKeys.end(), key.first); + contKeys.erase(it); + } + for (Key key : contKeys) { + std::cout << " " << keyFormatter(key); + } + std::cout << ";"; + for (DiscreteKey key : dKeys) { + std::cout << " " << keyFormatter(key.first); + } + std::cout << " ) \n"; + auto valueFormatter = [](const sharedFactor& v) { + if (v) { + return (boost::format("Nonlinear factor on %d keys") % v->size()).str(); + } else { + return std::string("nullptr"); + } + }; + factors_.print("", keyFormatter, valueFormatter); + } + + /// Check equality + bool equals(const HybridFactor& other, double tol = 1e-9) const override { + // We attempt a dynamic cast from HybridFactor to MixtureFactor. If it + // fails, return false. + if (!dynamic_cast(&other)) return false; + + // If the cast is successful, we'll properly construct a MixtureFactor + // object from `other` + const MixtureFactor& f(static_cast(other)); + + // Ensure that this MixtureFactor and `f` have the same `factors_`. + auto compare = [tol](const sharedFactor& a, const sharedFactor& b) { + return traits::Equals(*a, *b, tol); + }; + if (!factors_.equals(f.factors_, compare)) return false; + + // If everything above passes, and the keys_, discreteKeys_ and normalized_ + // member variables are identical, return true. + return (std::equal(keys_.begin(), keys_.end(), f.keys().begin()) && + (discreteKeys_ == f.discreteKeys_) && + (normalized_ == f.normalized_)); + } + + /// @} + + /// Linearize specific nonlinear factors based on the assignment in + /// discreteValues. + GaussianFactor::shared_ptr linearize( + const Values& continuousVals, const DiscreteValues& discreteVals) const { + auto factor = factors_(discreteVals); + return factor->linearize(continuousVals); + } + + /// Linearize all the continuous factors to get a GaussianMixtureFactor. + boost::shared_ptr linearize( + const Values& continuousVals) const { + // functional to linearize each factor in the decision tree + auto linearizeDT = [continuousVals](const sharedFactor& factor) { + return factor->linearize(continuousVals); + }; + + DecisionTree linearized_factors( + factors_, linearizeDT); + + return boost::make_shared(keys_, discreteKeys_, + linearized_factors); + } + + /** + * If the component factors are not already normalized, we want to compute + * their normalizing constants so that the resulting joint distribution is + * appropriately computed. Remember, this is the _negative_ normalizing + * constant for the measurement likelihood (since we are minimizing the + * _negative_ log-likelihood). + */ + double nonlinearFactorLogNormalizingConstant( + const NonlinearFactorType& factor, const Values& values) const { + // Information matrix (inverse covariance matrix) for the factor. + Matrix infoMat; + + // NOTE: This is sloppy (and mallocs!), is there a cleaner way? + auto factorPtr = boost::make_shared(factor); + + // If this is a NoiseModelFactor, we'll use its noiseModel to + // otherwise noiseModelFactor will be nullptr + auto noiseModelFactor = + boost::dynamic_pointer_cast(factorPtr); + if (noiseModelFactor) { + // If dynamic cast to NoiseModelFactor succeeded, see if the noise model + // is Gaussian + auto noiseModel = noiseModelFactor->noiseModel(); + + auto gaussianNoiseModel = + boost::dynamic_pointer_cast(noiseModel); + if (gaussianNoiseModel) { + // If the noise model is Gaussian, retrieve the information matrix + infoMat = gaussianNoiseModel->information(); + } else { + // If the factor is not a Gaussian factor, we'll linearize it to get + // something with a normalized noise model + // TODO(kevin): does this make sense to do? I think maybe not in + // general? Should we just yell at the user? + auto gaussianFactor = factor.linearize(values); + infoMat = gaussianFactor->information(); + } + } + + // Compute the (negative) log of the normalizing constant + return -(factor.dim() * log(2.0 * M_PI) / 2.0) - + (log(infoMat.determinant()) / 2.0); + } +}; + +} // namespace gtsam From e91a35453a5fdbeb26b9a57c405de3a5a1e94898 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 28 May 2022 20:44:30 -0400 Subject: [PATCH 0043/1497] convert to cpp --- .../{testHybridFactorGraph.h => testHybridFactorGraph.cpp} | 7 +++++++ 1 file changed, 7 insertions(+) rename gtsam/hybrid/tests/{testHybridFactorGraph.h => testHybridFactorGraph.cpp} (91%) diff --git a/gtsam/hybrid/tests/testHybridFactorGraph.h b/gtsam/hybrid/tests/testHybridFactorGraph.cpp similarity index 91% rename from gtsam/hybrid/tests/testHybridFactorGraph.h rename to gtsam/hybrid/tests/testHybridFactorGraph.cpp index 284e996ce6..36f5f38ae6 100644 --- a/gtsam/hybrid/tests/testHybridFactorGraph.h +++ b/gtsam/hybrid/tests/testHybridFactorGraph.cpp @@ -13,9 +13,14 @@ * @date May 2021 */ +#include +#include #include #include #include +#include + +using namespace gtsam; /* **************************************************************************** * Test that any linearizedFactorGraph gaussian factors are appended to the @@ -37,6 +42,8 @@ TEST(HybridFactorGraph, GaussianFactorGraph) { GaussianHybridFactorGraph ghfg = fg.linearize(linearizationPoint); + EXPECT_LONGS_EQUAL(ghfg); + // ghfg.push_back(ghfg.gaussianGraph().begin(), ghfg.gaussianGraph().end()); // EXPECT_LONGS_EQUAL(2, dcmfg.gaussianGraph().size()); From 9cbd2ef477f40f47ba9281cd2a09aaf1af853eb7 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 12:44:56 -0400 Subject: [PATCH 0044/1497] Base Hybrid Factor Graph --- gtsam/hybrid/HybridFactorGraph.h | 105 +++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 33 deletions(-) diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h index f415386ea4..f19eb0faff 100644 --- a/gtsam/hybrid/HybridFactorGraph.h +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -20,15 +20,19 @@ #include #include +#include +#include #include #include +#include +#include namespace gtsam { /** * Hybrid Factor Graph * ----------------------- - * This is the non-linear version of a hybrid factor graph. + * This is the base hybrid factor graph. * Everything inside needs to be hybrid factor or hybrid conditional. */ class HybridFactorGraph : public FactorGraph { @@ -40,9 +44,22 @@ class HybridFactorGraph : public FactorGraph { using Values = gtsam::Values; ///< backwards compatibility using Indices = KeyVector; ///> map from keys to values + protected: + /// Check if FACTOR type is derived from DiscreteFactor. + template + using IsDiscrete = typename std::enable_if< + std::is_base_of::value>::type; + + /// Check if FACTOR type is derived from HybridFactor. + template + using IsHybrid = typename std::enable_if< + std::is_base_of::value>::type; + + public: /// @name Constructors /// @{ + /// Default constructor HybridFactorGraph() = default; /** @@ -61,46 +78,68 @@ class HybridFactorGraph : public FactorGraph { using Base::size; using FactorGraph::add; using Base::operator[]; + using Base::resize; + + /** + * Add a discrete factor *pointer* to the internal discrete graph + * @param discreteFactor - boost::shared_ptr to the factor to add + */ + template + IsDiscrete push_discrete( + const boost::shared_ptr& discreteFactor) { + Base::push_back(boost::make_shared(discreteFactor)); + } - /// Add a Jacobian factor to the factor graph. - void add(JacobianFactor&& factor); + /** + * Add a discrete-continuous (Hybrid) factor *pointer* to the graph + * @param hybridFactor - boost::shared_ptr to the factor to add + */ + template + IsHybrid push_hybrid(const boost::shared_ptr& hybridFactor) { + Base::push_back(boost::make_shared(factor)); + } - /// Add a Jacobian factor as a shared ptr. - void add(boost::shared_ptr factor); + /// delete emplace_shared. + template + void emplace_shared(Args&&... args) = delete; - /// Add a DecisionTreeFactor to the factor graph. - void add(DecisionTreeFactor&& factor); + /// Construct a factor and add (shared pointer to it) to factor graph. + template + IsDiscrete emplace_discrete(Args&&... args) { + auto factor = boost::allocate_shared( + Eigen::aligned_allocator(), std::forward(args)...); + push_discrete(factor); + } - /// Add a DecisionTreeFactor as a shared ptr. - void add(boost::shared_ptr factor); + /// Construct a factor and add (shared pointer to it) to factor graph. + template + IsHybrid emplace_hybrid(Args&&... args) { + auto factor = boost::allocate_shared( + Eigen::aligned_allocator(), std::forward(args)...); + push_hybrid(factor); + } /** - * @brief Linearize all the continuous factors in the - * NonlinearHybridFactorGraph. + * @brief Add a single factor shared pointer to the hybrid factor graph. + * Dynamically handles the factor type and assigns it to the correct + * underlying container. * - * @param continuousValues: Dictionary of continuous values. - * @return GaussianHybridFactorGraph::shared_ptr + * @param sharedFactor The factor to add to this factor graph. */ - GaussianHybridFactorGraph::shared_ptr linearize( - const Values& continuousValues) const { - // create an empty linear FG - GaussianHybridFactorGraph::shared_ptr linearFG = - boost::make_shared(); - - linearFG->reserve(size()); - - // linearize all factors - for (const sharedFactor& factor : factors_) { - if (factor) { - if (auto nf = boost::dynamic_pointer_cast) { - (*linearFG) += factor->linearize(linearizationPoint); - } else if (auto hf = boost::dynamic_pointer_cast) { - if (hf->isContinuous()) { - } - } - - } else - (*linearFG) += GaussianFactor::shared_ptr(); + void push_back(const SharedFactor& sharedFactor) { + if (auto p = boost::dynamic_pointer_cast(sharedFactor)) { + push_discrete(p); + } + if (auto p = boost::dynamic_pointer_cast(sharedFactor)) { + push_hybrid(p); + } + } + + /** Constructor from iterator over factors (shared_ptr or plain objects) */ + template + void push_back(ITERATOR firstFactor, ITERATOR lastFactor) { + for (auto&& it = firstFactor; it != lastFactor; it++) { + push_back(*it); } } }; From 01b9a65e1e522d75db2a3dd69e31a5115024183a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 12:47:45 -0400 Subject: [PATCH 0045/1497] make GaussianMixtureFactor a subclass of HybridGaussianFactor --- gtsam/hybrid/GaussianMixtureFactor.h | 8 ++++---- gtsam/hybrid/HybridGaussianFactor.h | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gtsam/hybrid/GaussianMixtureFactor.h b/gtsam/hybrid/GaussianMixtureFactor.h index b2fbe4aefd..bd2e079cba 100644 --- a/gtsam/hybrid/GaussianMixtureFactor.h +++ b/gtsam/hybrid/GaussianMixtureFactor.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include namespace gtsam { @@ -40,9 +40,9 @@ using GaussianFactorVector = std::vector; * of discrete variables indexes to the continuous gaussian distribution. * */ -class GaussianMixtureFactor : public HybridFactor { +class GaussianMixtureFactor : public HybridGaussianFactor { public: - using Base = HybridFactor; + using Base = HybridGaussianFactor; using This = GaussianMixtureFactor; using shared_ptr = boost::shared_ptr; @@ -93,7 +93,7 @@ class GaussianMixtureFactor : public HybridFactor { bool equals(const HybridFactor &lf, double tol = 1e-9) const override; void print( - const std::string &s = "HybridFactor\n", + const std::string &s = "GaussianMixtureFactor\n", const KeyFormatter &formatter = DefaultKeyFormatter) const override; /// @} diff --git a/gtsam/hybrid/HybridGaussianFactor.h b/gtsam/hybrid/HybridGaussianFactor.h index 8d457e7783..4c8ede12cc 100644 --- a/gtsam/hybrid/HybridGaussianFactor.h +++ b/gtsam/hybrid/HybridGaussianFactor.h @@ -27,7 +27,7 @@ namespace gtsam { * A HybridGaussianFactor is a layer over GaussianFactor so that we do not have * a diamond inheritance. */ -class HybridGaussianFactor : public HybridFactor { +class GTSAM_EXPORT HybridGaussianFactor : public HybridFactor { private: GaussianFactor::shared_ptr inner_; @@ -36,6 +36,12 @@ class HybridGaussianFactor : public HybridFactor { using This = HybridGaussianFactor; using shared_ptr = boost::shared_ptr; + HybridGaussianFactor() = default; + + HybridGaussianFactor(const KeyVector &continuousKeys, + const DiscreteKeys &discreteKeys) + : Base(continuousKeys, discreteKeys) {} + // Explicit conversion from a shared ptr of GF explicit HybridGaussianFactor(GaussianFactor::shared_ptr other); @@ -51,7 +57,7 @@ class HybridGaussianFactor : public HybridFactor { /// GTSAM print utility. void print( - const std::string &s = "HybridFactor\n", + const std::string &s = "HybridGaussianFactor\n", const KeyFormatter &formatter = DefaultKeyFormatter) const override; /// @} From fe0d666b3a56d62daf44689eb01a1ceb4a8be8a1 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 13:15:04 -0400 Subject: [PATCH 0046/1497] HybridFactorGraph fixes --- gtsam/hybrid/HybridFactorGraph.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h index f19eb0faff..ef27caec8a 100644 --- a/gtsam/hybrid/HybridFactorGraph.h +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -18,17 +18,17 @@ #pragma once -#include +#include +#include #include -#include -#include #include #include -#include #include namespace gtsam { +using SharedFactor = boost::shared_ptr; + /** * Hybrid Factor Graph * ----------------------- @@ -96,7 +96,7 @@ class HybridFactorGraph : public FactorGraph { */ template IsHybrid push_hybrid(const boost::shared_ptr& hybridFactor) { - Base::push_back(boost::make_shared(factor)); + Base::push_back(hybridFactor); } /// delete emplace_shared. From cdd030b88b71f5e46132c25fb232c84028132ea7 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 13:32:21 -0400 Subject: [PATCH 0047/1497] Make MixtureFactor only work with NonlinearFactors and make some improvements --- gtsam/hybrid/MixtureFactor.h | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/gtsam/hybrid/MixtureFactor.h b/gtsam/hybrid/MixtureFactor.h index 556402058e..b2423d20eb 100644 --- a/gtsam/hybrid/MixtureFactor.h +++ b/gtsam/hybrid/MixtureFactor.h @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include @@ -28,21 +28,27 @@ namespace gtsam { /** - * @brief Implementation of a discrete conditional mixture factor. Implements a - * joint discrete-continuous factor where the discrete variable serves to - * "select" a mixture component corresponding to a NonlinearFactor type - * of measurement. + * @brief Implementation of a discrete conditional mixture factor. + * + * Implements a joint discrete-continuous factor where the discrete variable + * serves to "select" a mixture component corresponding to a NonlinearFactor + * type of measurement. + * + * This class stores all factors as HybridFactors which can then be typecast to + * one of (NonlinearFactor, GaussianFactor) which can then be checked to perform + * the correct operation. */ -template -class MixtureFactor : public HybridFactor { +class MixtureFactor : public HybridNonlinearFactor { public: using Base = HybridFactor; using This = MixtureFactor; using shared_ptr = boost::shared_ptr; - using sharedFactor = boost::shared_ptr; + using sharedFactor = boost::shared_ptr; - /// typedef for DecisionTree which has Keys as node labels and - /// NonlinearFactorType as leaf nodes. + /** + * @brief typedef for DecisionTree which has Keys as node labels and + * NonlinearFactor as leaf nodes. + */ using Factors = DecisionTree; private: @@ -103,7 +109,7 @@ class MixtureFactor : public HybridFactor { const double factorError = factor->error(continuousVals); if (normalized_) return factorError; return factorError + - this->nonlinearFactorLogNormalizingConstant(*factor, continuousVals); + this->nonlinearFactorLogNormalizingConstant(factor, continuousVals); } size_t dim() const { @@ -156,7 +162,7 @@ class MixtureFactor : public HybridFactor { // Ensure that this MixtureFactor and `f` have the same `factors_`. auto compare = [tol](const sharedFactor& a, const sharedFactor& b) { - return traits::Equals(*a, *b, tol); + return traits::Equals(*a, *b, tol); }; if (!factors_.equals(f.factors_, compare)) return false; @@ -199,19 +205,15 @@ class MixtureFactor : public HybridFactor { * constant for the measurement likelihood (since we are minimizing the * _negative_ log-likelihood). */ - double nonlinearFactorLogNormalizingConstant( - const NonlinearFactorType& factor, const Values& values) const { + double nonlinearFactorLogNormalizingConstant(const sharedFactor& factor, + const Values& values) const { // Information matrix (inverse covariance matrix) for the factor. Matrix infoMat; - // NOTE: This is sloppy (and mallocs!), is there a cleaner way? - auto factorPtr = boost::make_shared(factor); - // If this is a NoiseModelFactor, we'll use its noiseModel to // otherwise noiseModelFactor will be nullptr - auto noiseModelFactor = - boost::dynamic_pointer_cast(factorPtr); - if (noiseModelFactor) { + if (auto noiseModelFactor = + boost::dynamic_pointer_cast(factor);) { // If dynamic cast to NoiseModelFactor succeeded, see if the noise model // is Gaussian auto noiseModel = noiseModelFactor->noiseModel(); From 08fab8a9362d4cc12365afb76233eae85fa2db6c Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 13:33:04 -0400 Subject: [PATCH 0048/1497] HybridNonlinearFactor linearize method --- gtsam/hybrid/HybridNonlinearFactor.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gtsam/hybrid/HybridNonlinearFactor.h b/gtsam/hybrid/HybridNonlinearFactor.h index 53d7bfbf47..504992e22d 100644 --- a/gtsam/hybrid/HybridNonlinearFactor.h +++ b/gtsam/hybrid/HybridNonlinearFactor.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include namespace gtsam { @@ -53,5 +54,10 @@ class HybridNonlinearFactor : public HybridFactor { /// @} NonlinearFactor::shared_ptr inner() const { return inner_; } + + /// Linearize to a HybridGaussianFactor at the linearization point `c`. + boost::shared_ptr linearize(const Values &c) const { + return boost::make_shared(inner_->linearize(c)); + } }; } // namespace gtsam From 9279bd607648098043e8c1f60f533e0a31b4412c Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 13:33:19 -0400 Subject: [PATCH 0049/1497] push_back for GaussianHybridFactor --- gtsam/hybrid/GaussianHybridFactorGraph.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gtsam/hybrid/GaussianHybridFactorGraph.h b/gtsam/hybrid/GaussianHybridFactorGraph.h index c8e0718fc4..23d5918d46 100644 --- a/gtsam/hybrid/GaussianHybridFactorGraph.h +++ b/gtsam/hybrid/GaussianHybridFactorGraph.h @@ -100,6 +100,7 @@ class GaussianHybridFactorGraph /// @} using FactorGraph::add; + using FactorGraph::push_back; /// Add a Jacobian factor to the factor graph. void add(JacobianFactor&& factor); From 3274cb12a411260e2d3ab1640362636eb651ed0b Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 13:33:56 -0400 Subject: [PATCH 0050/1497] clean up testHybridFactorGraph, need to add more tests --- gtsam/hybrid/tests/testHybridFactorGraph.cpp | 26 ++++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/gtsam/hybrid/tests/testHybridFactorGraph.cpp b/gtsam/hybrid/tests/testHybridFactorGraph.cpp index 36f5f38ae6..f5b4ec0b19 100644 --- a/gtsam/hybrid/tests/testHybridFactorGraph.cpp +++ b/gtsam/hybrid/tests/testHybridFactorGraph.cpp @@ -18,35 +18,23 @@ #include #include #include +#include #include +using namespace std; using namespace gtsam; +using noiseModel::Isotropic; +using symbol_shorthand::L; +using symbol_shorthand::M; +using symbol_shorthand::X; /* **************************************************************************** * Test that any linearizedFactorGraph gaussian factors are appended to the * existing gaussian factor graph in the hybrid factor graph. */ -TEST(HybridFactorGraph, GaussianFactorGraph) { +TEST(HybridFactorGraph, Constructor) { // Initialize the hybrid factor graph HybridFactorGraph fg; - - // Add a simple prior factor to the nonlinear factor graph - fg.emplace_shared>(X(0), 0, Isotropic::Sigma(1, 0.1)); - - // Add a linear factor to the nonlinear factor graph - fg.add(X(0), I_1x1, Vector1(5)); - - // Linearization point - Values linearizationPoint; - linearizationPoint.insert(X(0), 0); - - GaussianHybridFactorGraph ghfg = fg.linearize(linearizationPoint); - - EXPECT_LONGS_EQUAL(ghfg); - - // ghfg.push_back(ghfg.gaussianGraph().begin(), ghfg.gaussianGraph().end()); - - // EXPECT_LONGS_EQUAL(2, dcmfg.gaussianGraph().size()); } /* ************************************************************************* */ From 6c36b2c35598790d3e181b8fa5a87064388507a7 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 29 May 2022 14:51:30 -0400 Subject: [PATCH 0051/1497] GaussianHybridFactorGraph inherits from HybridFactorGraph --- gtsam/hybrid/GaussianHybridFactorGraph.h | 14 ++++++++++---- gtsam/hybrid/HybridFactorGraph.h | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gtsam/hybrid/GaussianHybridFactorGraph.h b/gtsam/hybrid/GaussianHybridFactorGraph.h index 23d5918d46..341a0838e5 100644 --- a/gtsam/hybrid/GaussianHybridFactorGraph.h +++ b/gtsam/hybrid/GaussianHybridFactorGraph.h @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include #include @@ -71,10 +72,10 @@ struct EliminationTraits { * Everything inside needs to be hybrid factor or hybrid conditional. */ class GaussianHybridFactorGraph - : public FactorGraph, + : public HybridFactorGraph, public EliminateableFactorGraph { public: - using Base = FactorGraph; + using Base = HybridFactorGraph; using This = GaussianHybridFactorGraph; ///< this class using BaseEliminateable = EliminateableFactorGraph; ///< for elimination @@ -99,8 +100,13 @@ class GaussianHybridFactorGraph /// @} - using FactorGraph::add; - using FactorGraph::push_back; + using Base::empty; + using Base::reserve; + using Base::size; + using Base::operator[]; + using Base::add; + using Base::push_back; + using Base::resize; /// Add a Jacobian factor to the factor graph. void add(JacobianFactor&& factor); diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h index ef27caec8a..892136b86c 100644 --- a/gtsam/hybrid/HybridFactorGraph.h +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -76,8 +76,9 @@ class HybridFactorGraph : public FactorGraph { using Base::empty; using Base::reserve; using Base::size; - using FactorGraph::add; using Base::operator[]; + using Base::add; + using Base::push_back; using Base::resize; /** From 85f4b4892586ad166dffa83d8e0b914c87868097 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 30 May 2022 08:21:46 -0400 Subject: [PATCH 0052/1497] Improvements to GaussianHybridFactorGraph, make MixtureFactor a subclass of HybridFactor --- gtsam/hybrid/GaussianHybridFactorGraph.h | 51 ++++++++++++++++++++++++ gtsam/hybrid/HybridNonlinearFactor.cpp | 3 +- gtsam/hybrid/HybridNonlinearFactor.h | 4 +- gtsam/hybrid/MixtureFactor.h | 8 ++-- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/gtsam/hybrid/GaussianHybridFactorGraph.h b/gtsam/hybrid/GaussianHybridFactorGraph.h index 341a0838e5..b38a1ebd8d 100644 --- a/gtsam/hybrid/GaussianHybridFactorGraph.h +++ b/gtsam/hybrid/GaussianHybridFactorGraph.h @@ -20,9 +20,11 @@ #include #include +#include #include #include #include +#include namespace gtsam { @@ -74,6 +76,12 @@ struct EliminationTraits { class GaussianHybridFactorGraph : public HybridFactorGraph, public EliminateableFactorGraph { + protected: + /// Check if FACTOR type is derived from GaussianFactor. + template + using IsGaussian = typename std::enable_if< + std::is_base_of::value>::type; + public: using Base = HybridFactorGraph; using This = GaussianHybridFactorGraph; ///< this class @@ -119,6 +127,49 @@ class GaussianHybridFactorGraph /// Add a DecisionTreeFactor as a shared ptr. void add(boost::shared_ptr factor); + + /** + * Add a gaussian factor *pointer* to the internal gaussian factor graph + * @param gaussianFactor - boost::shared_ptr to the factor to add + */ + template + IsGaussian push_gaussian( + const boost::shared_ptr& gaussianFactor) { + Base::Base::push_back( + boost::make_shared(gaussianFactor)); + } + + /// Construct a factor and add (shared pointer to it) to factor graph. + template + IsGaussian emplace_gaussian(Args&&... args) { + auto factor = boost::allocate_shared( + Eigen::aligned_allocator(), std::forward(args)...); + push_gaussian(factor); + } + + /** + * @brief Add a single factor shared pointer to the hybrid factor graph. + * Dynamically handles the factor type and assigns it to the correct + * underlying container. + * + * @param sharedFactor The factor to add to this factor graph. + */ + void push_back(const SharedFactor& sharedFactor) { + if (auto p = boost::dynamic_pointer_cast(sharedFactor)) { + push_gaussian(p); + } else { + Base::push_back(sharedFactor); + } + } + + /** + * @brief Push back for Gaussian Factor specifically. + * + * @param sharedFactor Shared ptr to a gaussian factor. + */ + void push_back(const GaussianFactor::shared_ptr& sharedFactor) { + push_gaussian(sharedFactor); + } }; } // namespace gtsam diff --git a/gtsam/hybrid/HybridNonlinearFactor.cpp b/gtsam/hybrid/HybridNonlinearFactor.cpp index 69a9767900..0938fd2b12 100644 --- a/gtsam/hybrid/HybridNonlinearFactor.cpp +++ b/gtsam/hybrid/HybridNonlinearFactor.cpp @@ -22,7 +22,8 @@ namespace gtsam { /* ************************************************************************* */ -HybridNonlinearFactor::HybridNonlinearFactor(NonlinearFactor::shared_ptr other) +HybridNonlinearFactor::HybridNonlinearFactor( + const NonlinearFactor::shared_ptr &other) : Base(other->keys()), inner_(other) {} /* ************************************************************************* */ diff --git a/gtsam/hybrid/HybridNonlinearFactor.h b/gtsam/hybrid/HybridNonlinearFactor.h index 504992e22d..4a0c0fd9c1 100644 --- a/gtsam/hybrid/HybridNonlinearFactor.h +++ b/gtsam/hybrid/HybridNonlinearFactor.h @@ -36,8 +36,8 @@ class HybridNonlinearFactor : public HybridFactor { using This = HybridNonlinearFactor; using shared_ptr = boost::shared_ptr; - // Explicit conversion from a shared ptr of GF - explicit HybridNonlinearFactor(NonlinearFactor::shared_ptr other); + // Explicit conversion from a shared ptr of NonlinearFactor + explicit HybridNonlinearFactor(const NonlinearFactor::shared_ptr &other); public: /// @name Testable diff --git a/gtsam/hybrid/MixtureFactor.h b/gtsam/hybrid/MixtureFactor.h index b2423d20eb..d2d1a8d74f 100644 --- a/gtsam/hybrid/MixtureFactor.h +++ b/gtsam/hybrid/MixtureFactor.h @@ -38,7 +38,7 @@ namespace gtsam { * one of (NonlinearFactor, GaussianFactor) which can then be checked to perform * the correct operation. */ -class MixtureFactor : public HybridNonlinearFactor { +class MixtureFactor : public HybridFactor { public: using Base = HybridFactor; using This = MixtureFactor; @@ -213,7 +213,7 @@ class MixtureFactor : public HybridNonlinearFactor { // If this is a NoiseModelFactor, we'll use its noiseModel to // otherwise noiseModelFactor will be nullptr if (auto noiseModelFactor = - boost::dynamic_pointer_cast(factor);) { + boost::dynamic_pointer_cast(factor)) { // If dynamic cast to NoiseModelFactor succeeded, see if the noise model // is Gaussian auto noiseModel = noiseModelFactor->noiseModel(); @@ -228,13 +228,13 @@ class MixtureFactor : public HybridNonlinearFactor { // something with a normalized noise model // TODO(kevin): does this make sense to do? I think maybe not in // general? Should we just yell at the user? - auto gaussianFactor = factor.linearize(values); + auto gaussianFactor = factor->linearize(values); infoMat = gaussianFactor->information(); } } // Compute the (negative) log of the normalizing constant - return -(factor.dim() * log(2.0 * M_PI) / 2.0) - + return -(factor->dim() * log(2.0 * M_PI) / 2.0) - (log(infoMat.determinant()) / 2.0); } }; From 53e8c32b40fc934f6491778c3638f5972214c8ab Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 30 May 2022 08:33:16 -0400 Subject: [PATCH 0053/1497] Add NonlinearHybridFactorGraph class --- gtsam/hybrid/NonlinearHybridFactorGraph.h | 209 +++++ gtsam/hybrid/tests/Switching.h | 3 + .../tests/testNonlinearHybridFactorGraph.cpp | 770 ++++++++++++++++++ 3 files changed, 982 insertions(+) create mode 100644 gtsam/hybrid/NonlinearHybridFactorGraph.h create mode 100644 gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp diff --git a/gtsam/hybrid/NonlinearHybridFactorGraph.h b/gtsam/hybrid/NonlinearHybridFactorGraph.h new file mode 100644 index 0000000000..aeb5a4545a --- /dev/null +++ b/gtsam/hybrid/NonlinearHybridFactorGraph.h @@ -0,0 +1,209 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file NonlinearHybridFactorGraph.h + * @brief Nonlinear hybrid factor graph that uses type erasure + * @author Varun Agrawal + * @date May 28, 2022 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include +namespace gtsam { + +/** + * Nonlinear Hybrid Factor Graph + * ----------------------- + * This is the non-linear version of a hybrid factor graph. + * Everything inside needs to be hybrid factor or hybrid conditional. + */ +class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { + protected: + /// Check if FACTOR type is derived from NonlinearFactor. + template + using IsNonlinear = typename std::enable_if< + std::is_base_of::value>::type; + + public: + using Base = FactorGraph; + using This = NonlinearHybridFactorGraph; ///< this class + using shared_ptr = boost::shared_ptr; ///< shared_ptr to This + + using Values = gtsam::Values; ///< backwards compatibility + using Indices = KeyVector; ///> map from keys to values + + /// @name Constructors + /// @{ + + NonlinearHybridFactorGraph() = default; + + /** + * Implicit copy/downcast constructor to override explicit template container + * constructor. In BayesTree this is used for: + * `cachedSeparatorMarginal_.reset(*separatorMarginal)` + * */ + template + NonlinearHybridFactorGraph(const FactorGraph& graph) + : Base(graph) {} + + /// @} + + // Allow use of selected FactorGraph methods: + using Base::empty; + using Base::reserve; + using Base::size; + using Base::operator[]; + using Base::add; + using Base::push_back; + using Base::resize; + + /** + * Add a nonlinear factor *pointer* to the internal nonlinear factor graph + * @param nonlinearFactor - boost::shared_ptr to the factor to add + */ + template + IsNonlinear push_nonlinear( + const boost::shared_ptr& nonlinearFactor) { + Base::push_back(boost::make_shared(nonlinearFactor)); + } + + /// Construct a factor and add (shared pointer to it) to factor graph. + template + IsNonlinear emplace_nonlinear(Args&&... args) { + auto factor = boost::allocate_shared( + Eigen::aligned_allocator(), std::forward(args)...); + push_nonlinear(factor); + } + + /** + * @brief Add a single factor shared pointer to the hybrid factor graph. + * Dynamically handles the factor type and assigns it to the correct + * underlying container. + * + * @tparam FACTOR The factor type template + * @param sharedFactor The factor to add to this factor graph. + */ + template + void push_back(const boost::shared_ptr& sharedFactor) { + if (auto p = boost::dynamic_pointer_cast(sharedFactor)) { + push_nonlinear(p); + } else { + Base::push_back(sharedFactor); + } + } + + /** Constructor from iterator over factors (shared_ptr or plain objects) */ + template + void push_back(ITERATOR firstFactor, ITERATOR lastFactor) { + for (auto&& it = firstFactor; it != lastFactor; it++) { + push_back(*it); + } + } + + // /// Add a nonlinear factor to the factor graph. + // void add(NonlinearFactor&& factor) { + // Base::add(boost::make_shared(std::move(factor))); + // } + + /// Add a nonlinear factor as a shared ptr. + void add(boost::shared_ptr factor) { + FactorGraph::add(boost::make_shared(factor)); + } + + /** + * Simply prints the factor graph. + */ + void print( + const std::string& str = "NonlinearHybridFactorGraph", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {} + + /** + * @return true if all internal graphs of `this` are equal to those of + * `other` + */ + bool equals(const NonlinearHybridFactorGraph& other, + double tol = 1e-9) const { + return false; + } + + /** + * @brief Linearize all the continuous factors in the + * NonlinearHybridFactorGraph. + * + * @param continuousValues: Dictionary of continuous values. + * @return GaussianHybridFactorGraph::shared_ptr + */ + GaussianHybridFactorGraph::shared_ptr linearize( + const Values& continuousValues) const { + // create an empty linear FG + GaussianHybridFactorGraph::shared_ptr linearFG = + boost::make_shared(); + + linearFG->reserve(size()); + + // linearize all hybrid factors + for (auto&& factor : factors_) { + // First check if it is a valid factor + if (factor) { + // Check if the factor is a hybrid factor. + // It can be either a nonlinear MixtureFactor or a linear + // GaussianMixtureFactor. + if (factor->isHybrid()) { + // Check if it is a nonlinear mixture factor + if (auto nlmf = boost::dynamic_pointer_cast(factor)) { + linearFG->push_back(nlmf->linearize(continuousValues)); + } else { + linearFG->push_back(factor); + } + + // Now check if the factor is a continuous only factor. + } else if (factor->isContinuous()) { + // In this case, we check if factor->inner() is nonlinear since + // HybridFactors wrap over continuous factors. + auto nlhf = + boost::dynamic_pointer_cast(factor); + if (auto nlf = + boost::dynamic_pointer_cast(nlhf->inner())) { + auto hgf = boost::make_shared( + nlf->linearize(continuousValues)); + linearFG->push_back(hgf); + } else { + linearFG->push_back(factor); + } + // Finally if nothing else, we are discrete-only which doesn't need + // lineariztion. + } else { + linearFG->push_back(factor); + } + + } else { + linearFG->push_back(GaussianFactor::shared_ptr()); + } + } + return linearFG; + } +}; + +template <> +struct traits + : public Testable {}; + +} // namespace gtsam diff --git a/gtsam/hybrid/tests/Switching.h b/gtsam/hybrid/tests/Switching.h index 77d8182c8e..be58824e00 100644 --- a/gtsam/hybrid/tests/Switching.h +++ b/gtsam/hybrid/tests/Switching.h @@ -29,6 +29,9 @@ using gtsam::symbol_shorthand::C; using gtsam::symbol_shorthand::X; namespace gtsam { + +using MotionModel = BetweenFactor; + inline GaussianHybridFactorGraph::shared_ptr makeSwitchingChain( size_t n, std::function keyFunc = X, std::function dKeyFunc = C) { diff --git a/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp b/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp new file mode 100644 index 0000000000..8043f78df8 --- /dev/null +++ b/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp @@ -0,0 +1,770 @@ +/* ---------------------------------------------------------------------------- + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + * See LICENSE for the license information + * -------------------------------------------------------------------------- */ + +/** + * @file testDCFactorGraph.cpp + * @brief Unit tests for DCFactorGraph + * @author Varun Agrawal + * @author Fan Jiang + * @author Frank Dellaert + * @date December 2021 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "Switching.h" + +// Include for test suite +#include + +using namespace std; +using namespace gtsam; +using noiseModel::Isotropic; +using symbol_shorthand::L; +using symbol_shorthand::M; +using symbol_shorthand::X; + +/* **************************************************************************** + * Test that any linearizedFactorGraph gaussian factors are appended to the + * existing gaussian factor graph in the hybrid factor graph. + */ +TEST(HybridFactorGraph, GaussianFactorGraph) { + NonlinearHybridFactorGraph fg; + + // Add a simple prior factor to the nonlinear factor graph + fg.emplace_nonlinear>(X(0), 0, Isotropic::Sigma(1, 0.1)); + + // Linearization point + Values linearizationPoint; + linearizationPoint.insert(X(0), 0); + + GaussianHybridFactorGraph ghfg = *fg.linearize(linearizationPoint); + + // Add a factor to the GaussianFactorGraph + ghfg.add(JacobianFactor(X(0), I_1x1, Vector1(5))); + + EXPECT_LONGS_EQUAL(2, ghfg.size()); +} + +/* ************************************************************************** + */ +/// Test that the resize method works correctly for a +/// NonlinearHybridFactorGraph. +TEST(NonlinearHybridFactorGraph, Resize) { + NonlinearHybridFactorGraph fg; + // auto nonlinearFactor = boost::make_shared>(); + // fg.push_back(nonlinearFactor); + + // auto discreteFactor = boost::make_shared(); + // fg.push_back(discreteFactor); + + // auto dcFactor = boost::make_shared>(); + // fg.push_back(dcFactor); + // EXPECT_LONGS_EQUAL(fg.size(), 3); + + fg.resize(0); + EXPECT_LONGS_EQUAL(fg.size(), 0); +} + +// /* ************************************************************************** +// */ +// /// Test that the resize method works correctly for a +// /// GaussianHybridFactorGraph. +// TEST(GaussianHybridFactorGraph, Resize) { +// NonlinearHybridFactorGraph nhfg; +// auto nonlinearFactor = boost::make_shared>( +// X(0), X(1), 0.0, Isotropic::Sigma(1, 0.1)); +// nhfg.push_back(nonlinearFactor); +// auto discreteFactor = boost::make_shared(); +// nhfg.push_back(discreteFactor); + +// KeyVector contKeys = {X(0), X(1)}; +// auto noise_model = noiseModel::Isotropic::Sigma(1, 1.0); +// auto still = boost::make_shared(X(0), X(1), 0.0, noise_model), +// moving = boost::make_shared(X(0), X(1), 1.0, +// noise_model); +// std::vector components = {still, moving}; +// auto dcFactor = boost::make_shared>( +// contKeys, DiscreteKeys{gtsam::DiscreteKey(M(1), 2)}, components); +// nhfg.push_back(dcFactor); + +// Values linearizationPoint; +// linearizationPoint.insert(X(0), 0); +// linearizationPoint.insert(X(1), 1); + +// // Generate `GaussianHybridFactorGraph` by linearizing +// GaussianHybridFactorGraph fg = nhfg.linearize(linearizationPoint); + +// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 1); +// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 1); +// EXPECT_LONGS_EQUAL(fg.gaussianGraph().size(), 1); + +// EXPECT_LONGS_EQUAL(fg.size(), 3); + +// fg.resize(0); +// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 0); +// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 0); +// EXPECT_LONGS_EQUAL(fg.gaussianGraph().size(), 0); + +// EXPECT_LONGS_EQUAL(fg.size(), 0); +// } + +// /* +// **************************************************************************** +// * Test push_back on HFG makes the correct distinction. +// */ +// TEST(HybridFactorGraph, PushBack) { +// NonlinearHybridFactorGraph fg; + +// auto nonlinearFactor = boost::make_shared>(); +// fg.push_back(nonlinearFactor); + +// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 0); +// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 0); +// EXPECT_LONGS_EQUAL(fg.nonlinearGraph().size(), 1); + +// fg = NonlinearHybridFactorGraph(); + +// auto discreteFactor = boost::make_shared(); +// fg.push_back(discreteFactor); + +// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 0); +// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 1); +// EXPECT_LONGS_EQUAL(fg.nonlinearGraph().size(), 0); + +// fg = NonlinearHybridFactorGraph(); + +// auto dcFactor = boost::make_shared>(); +// fg.push_back(dcFactor); + +// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 1); +// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 0); +// EXPECT_LONGS_EQUAL(fg.nonlinearGraph().size(), 0); + +// // Now do the same with GaussianHybridFactorGraph +// GaussianHybridFactorGraph ghfg; + +// auto gaussianFactor = boost::make_shared(); +// ghfg.push_back(gaussianFactor); + +// EXPECT_LONGS_EQUAL(ghfg.dcGraph().size(), 0); +// EXPECT_LONGS_EQUAL(ghfg.discreteGraph().size(), 0); +// EXPECT_LONGS_EQUAL(ghfg.gaussianGraph().size(), 1); + +// ghfg = GaussianHybridFactorGraph(); + +// ghfg.push_back(discreteFactor); + +// EXPECT_LONGS_EQUAL(ghfg.dcGraph().size(), 0); +// EXPECT_LONGS_EQUAL(ghfg.discreteGraph().size(), 1); +// EXPECT_LONGS_EQUAL(ghfg.gaussianGraph().size(), 0); + +// ghfg = GaussianHybridFactorGraph(); + +// ghfg.push_back(dcFactor); + +// EXPECT_LONGS_EQUAL(ghfg.dcGraph().size(), 1); +// EXPECT_LONGS_EQUAL(ghfg.discreteGraph().size(), 0); +// EXPECT_LONGS_EQUAL(ghfg.gaussianGraph().size(), 0); +// } + +// /* +// ****************************************************************************/ +// // Test construction of switching-like hybrid factor graph. +// TEST(HybridFactorGraph, Switching) { +// Switching self(3); + +// EXPECT_LONGS_EQUAL(8, self.nonlinearFactorGraph.size()); +// EXPECT_LONGS_EQUAL(4, self.nonlinearFactorGraph.nonlinearGraph().size()); +// EXPECT_LONGS_EQUAL(2, self.nonlinearFactorGraph.discreteGraph().size()); +// EXPECT_LONGS_EQUAL(2, self.nonlinearFactorGraph.dcGraph().size()); + +// EXPECT_LONGS_EQUAL(8, self.linearizedFactorGraph.size()); +// EXPECT_LONGS_EQUAL(2, self.linearizedFactorGraph.discreteGraph().size()); +// EXPECT_LONGS_EQUAL(2, self.linearizedFactorGraph.dcGraph().size()); +// EXPECT_LONGS_EQUAL(4, self.linearizedFactorGraph.gaussianGraph().size()); +// } + +// /* +// ****************************************************************************/ +// // Test linearization on a switching-like hybrid factor graph. +// TEST(HybridFactorGraph, Linearization) { +// Switching self(3); + +// // Linearize here: +// GaussianHybridFactorGraph actualLinearized = +// self.nonlinearFactorGraph.linearize(self.linearizationPoint); + +// EXPECT_LONGS_EQUAL(8, actualLinearized.size()); +// EXPECT_LONGS_EQUAL(2, actualLinearized.discreteGraph().size()); +// EXPECT_LONGS_EQUAL(2, actualLinearized.dcGraph().size()); +// EXPECT_LONGS_EQUAL(4, actualLinearized.gaussianGraph().size()); +// } + +// /* +// ****************************************************************************/ +// // Test elimination tree construction +// TEST(HybridFactorGraph, EliminationTree) { +// Switching self(3); + +// // Create ordering. +// Ordering ordering; +// for (size_t k = 1; k <= self.K; k++) ordering += X(k); + +// // Create elimination tree. +// HybridEliminationTree etree(self.linearizedFactorGraph, ordering); +// EXPECT_LONGS_EQUAL(1, etree.roots().size()) +// } + +// /* +// ****************************************************************************/ +// // Test elimination function by eliminating x1 in *-x1-*-x2 graph. +// TEST(DCGaussianElimination, Eliminate_x1) { +// Switching self(3); + +// // Gather factors on x1, has a simple Gaussian and a mixture factor. +// GaussianHybridFactorGraph factors; +// factors.push_gaussian(self.linearizedFactorGraph.gaussianGraph()[0]); +// factors.push_dc(self.linearizedFactorGraph.dcGraph()[0]); + +// // Check that sum works: +// auto sum = factors.sum(); +// Assignment mode; +// mode[M(1)] = 1; +// auto actual = sum(mode); // Selects one of 2 modes. +// EXPECT_LONGS_EQUAL(2, actual.size()); // Prior and motion model. + +// // Eliminate x1 +// Ordering ordering; +// ordering += X(1); + +// auto result = EliminateHybrid(factors, ordering); +// CHECK(result.first); +// EXPECT_LONGS_EQUAL(1, result.first->nrFrontals()); +// CHECK(result.second); +// // Has two keys, x2 and m1 +// EXPECT_LONGS_EQUAL(2, result.second->size()); +// } + +// /* +// ****************************************************************************/ +// // Test elimination function by eliminating x2 in x1-*-x2-*-x3 chain. +// // m1/ \m2 +// TEST(DCGaussianElimination, Eliminate_x2) { +// Switching self(3); + +// // Gather factors on x2, will be two mixture factors (with x1 and x3, +// resp.). GaussianHybridFactorGraph factors; +// factors.push_dc(self.linearizedFactorGraph.dcGraph()[0]); // involves m1 +// factors.push_dc(self.linearizedFactorGraph.dcGraph()[1]); // involves m2 + +// // Check that sum works: +// auto sum = factors.sum(); +// Assignment mode; +// mode[M(1)] = 0; +// mode[M(2)] = 1; +// auto actual = sum(mode); // Selects one of 4 mode +// combinations. EXPECT_LONGS_EQUAL(2, actual.size()); // 2 motion models. + +// // Eliminate x2 +// Ordering ordering; +// ordering += X(2); + +// std::pair> +// result = +// EliminateHybrid(factors, ordering); +// CHECK(result.first); +// EXPECT_LONGS_EQUAL(1, result.first->nrFrontals()); +// CHECK(result.second); +// // Note: separator keys should include m1, m2. +// EXPECT_LONGS_EQUAL(4, result.second->size()); +// } + +// /* +// ****************************************************************************/ +// // Helper method to generate gaussian factor graphs with a specific mode. +// GaussianFactorGraph::shared_ptr batchGFG(double between, +// Values linearizationPoint) { +// NonlinearFactorGraph graph; +// graph.addPrior(X(1), 0, Isotropic::Sigma(1, 0.1)); + +// auto between_x1_x2 = boost::make_shared( +// X(1), X(2), between, Isotropic::Sigma(1, 1.0)); + +// graph.push_back(between_x1_x2); + +// return graph.linearize(linearizationPoint); +// } + +// /* +// ****************************************************************************/ +// // Test elimination function by eliminating x1 and x2 in graph. +// TEST(DCGaussianElimination, EliminateHybrid_2_Variable) { +// Switching self(2, 1.0, 0.1); + +// auto factors = self.linearizedFactorGraph; + +// // Check that sum works: +// auto sum = factors.sum(); +// Assignment mode; +// mode[M(1)] = 1; +// auto actual = sum(mode); // Selects one of 2 modes. +// EXPECT_LONGS_EQUAL(4, +// actual.size()); // Prior, 1 motion models, 2 +// measurements. + +// // Eliminate x1 +// Ordering ordering; +// ordering += X(1); +// ordering += X(2); + +// AbstractConditional::shared_ptr abstractConditionalMixture; +// boost::shared_ptr factorOnModes; +// std::tie(abstractConditionalMixture, factorOnModes) = +// EliminateHybrid(factors, ordering); + +// auto gaussianConditionalMixture = +// dynamic_pointer_cast(abstractConditionalMixture); + +// CHECK(gaussianConditionalMixture); +// EXPECT_LONGS_EQUAL( +// 2, +// gaussianConditionalMixture->nrFrontals()); // Frontals = [x1, x2] +// EXPECT_LONGS_EQUAL( +// 1, +// gaussianConditionalMixture->nrParents()); // 1 parent, which is the +// mode + +// auto discreteFactor = +// dynamic_pointer_cast(factorOnModes); +// CHECK(discreteFactor); +// EXPECT_LONGS_EQUAL(1, discreteFactor->discreteKeys().size()); +// EXPECT(discreteFactor->root_->isLeaf() == false); +// } + +// /* +// ****************************************************************************/ +// /// Test the toDecisionTreeFactor method +// TEST(HybridFactorGraph, ToDecisionTreeFactor) { +// size_t K = 3; + +// // Provide tight sigma values so that the errors are visibly different. +// double between_sigma = 5e-8, prior_sigma = 1e-7; + +// Switching self(K, between_sigma, prior_sigma); + +// // Clear out discrete factors since sum() cannot hanldle those +// GaussianHybridFactorGraph linearizedFactorGraph( +// self.linearizedFactorGraph.gaussianGraph(), DiscreteFactorGraph(), +// self.linearizedFactorGraph.dcGraph()); + +// auto decisionTreeFactor = linearizedFactorGraph.toDecisionTreeFactor(); + +// auto allAssignments = +// DiscreteValues::CartesianProduct(linearizedFactorGraph.discreteKeys()); + +// // Get the error of the discrete assignment m1=0, m2=1. +// double actual = (*decisionTreeFactor)(allAssignments[1]); + +// /********************************************/ +// // Create equivalent factor graph for m1=0, m2=1 +// GaussianFactorGraph graph = linearizedFactorGraph.gaussianGraph(); + +// for (auto &p : linearizedFactorGraph.dcGraph()) { +// if (auto mixture = +// boost::dynamic_pointer_cast(p)) { +// graph.add((*mixture)(allAssignments[1])); +// } +// } + +// VectorValues values = graph.optimize(); +// double expected = graph.probPrime(values); +// /********************************************/ +// EXPECT_DOUBLES_EQUAL(expected, actual, 1e-12); +// // REGRESSION: +// EXPECT_DOUBLES_EQUAL(0.6125, actual, 1e-4); +// } + +// /* +// ****************************************************************************/ +// // Test partial elimination +// TEST_UNSAFE(HybridFactorGraph, Partial_Elimination) { +// Switching self(3); + +// auto linearizedFactorGraph = self.linearizedFactorGraph; + +// // Create ordering. +// Ordering ordering; +// for (size_t k = 1; k <= self.K; k++) ordering += X(k); + +// // Eliminate partially. +// HybridBayesNet::shared_ptr hybridBayesNet; +// GaussianHybridFactorGraph::shared_ptr remainingFactorGraph; +// std::tie(hybridBayesNet, remainingFactorGraph) = +// linearizedFactorGraph.eliminatePartialSequential(ordering); + +// CHECK(hybridBayesNet); +// // GTSAM_PRINT(*hybridBayesNet); // HybridBayesNet +// EXPECT_LONGS_EQUAL(3, hybridBayesNet->size()); +// EXPECT(hybridBayesNet->at(0)->frontals() == KeyVector{X(1)}); +// EXPECT(hybridBayesNet->at(0)->parents() == KeyVector({X(2), M(1)})); +// EXPECT(hybridBayesNet->at(1)->frontals() == KeyVector{X(2)}); +// EXPECT(hybridBayesNet->at(1)->parents() == KeyVector({X(3), M(2), M(1)})); +// EXPECT(hybridBayesNet->at(2)->frontals() == KeyVector{X(3)}); +// EXPECT(hybridBayesNet->at(2)->parents() == KeyVector({M(2), M(1)})); + +// CHECK(remainingFactorGraph); +// // GTSAM_PRINT(*remainingFactorGraph); // HybridFactorGraph +// EXPECT_LONGS_EQUAL(3, remainingFactorGraph->size()); +// EXPECT(remainingFactorGraph->discreteGraph().at(0)->keys() == +// KeyVector({M(1)})); +// EXPECT(remainingFactorGraph->discreteGraph().at(1)->keys() == +// KeyVector({M(2), M(1)})); +// EXPECT(remainingFactorGraph->discreteGraph().at(2)->keys() == +// KeyVector({M(2), M(1)})); +// } + +// /* +// ****************************************************************************/ +// // Test full elimination +// TEST_UNSAFE(HybridFactorGraph, Full_Elimination) { +// Switching self(3); + +// auto linearizedFactorGraph = self.linearizedFactorGraph; + +// // We first do a partial elimination +// HybridBayesNet::shared_ptr hybridBayesNet_partial; +// GaussianHybridFactorGraph::shared_ptr remainingFactorGraph_partial; +// DiscreteBayesNet discreteBayesNet; + +// { +// // Create ordering. +// Ordering ordering; +// for (size_t k = 1; k <= self.K; k++) ordering += X(k); + +// // Eliminate partially. +// std::tie(hybridBayesNet_partial, remainingFactorGraph_partial) = +// linearizedFactorGraph.eliminatePartialSequential(ordering); + +// DiscreteFactorGraph dfg; +// dfg.push_back(remainingFactorGraph_partial->discreteGraph()); +// ordering.clear(); +// for (size_t k = 1; k < self.K; k++) ordering += M(k); +// discreteBayesNet = *dfg.eliminateSequential(ordering, EliminateForMPE); +// } + +// // Create ordering. +// Ordering ordering; +// for (size_t k = 1; k <= self.K; k++) ordering += X(k); +// for (size_t k = 1; k < self.K; k++) ordering += M(k); + +// // Eliminate partially. +// HybridBayesNet::shared_ptr hybridBayesNet = +// linearizedFactorGraph.eliminateSequential(ordering); + +// CHECK(hybridBayesNet); +// EXPECT_LONGS_EQUAL(5, hybridBayesNet->size()); +// // p(x1 | x2, m1) +// EXPECT(hybridBayesNet->at(0)->frontals() == KeyVector{X(1)}); +// EXPECT(hybridBayesNet->at(0)->parents() == KeyVector({X(2), M(1)})); +// // p(x2 | x3, m1, m2) +// EXPECT(hybridBayesNet->at(1)->frontals() == KeyVector{X(2)}); +// EXPECT(hybridBayesNet->at(1)->parents() == KeyVector({X(3), M(2), M(1)})); +// // p(x3 | m1, m2) +// EXPECT(hybridBayesNet->at(2)->frontals() == KeyVector{X(3)}); +// EXPECT(hybridBayesNet->at(2)->parents() == KeyVector({M(2), M(1)})); +// // P(m1 | m2) +// EXPECT(hybridBayesNet->at(3)->frontals() == KeyVector{M(1)}); +// EXPECT(hybridBayesNet->at(3)->parents() == KeyVector({M(2)})); +// EXPECT(dynamic_pointer_cast(hybridBayesNet->at(3)) +// ->equals(*discreteBayesNet.at(0))); +// // P(m2) +// EXPECT(hybridBayesNet->at(4)->frontals() == KeyVector{M(2)}); +// EXPECT_LONGS_EQUAL(0, hybridBayesNet->at(4)->nrParents()); +// EXPECT(dynamic_pointer_cast(hybridBayesNet->at(4)) +// ->equals(*discreteBayesNet.at(1))); +// } + +// /* +// ****************************************************************************/ +// // Test printing +// TEST(HybridFactorGraph, Printing) { +// Switching self(3); + +// auto linearizedFactorGraph = self.linearizedFactorGraph; + +// // Create ordering. +// Ordering ordering; +// for (size_t k = 1; k <= self.K; k++) ordering += X(k); + +// // Eliminate partially. +// HybridBayesNet::shared_ptr hybridBayesNet; +// GaussianHybridFactorGraph::shared_ptr remainingFactorGraph; +// std::tie(hybridBayesNet, remainingFactorGraph) = +// linearizedFactorGraph.eliminatePartialSequential(ordering); + +// string expected_hybridFactorGraph = R"( +// size: 8 +// DiscreteFactorGraph +// size: 2 +// factor 0: P( m1 ): +// Leaf 0.5 +// factor 1: P( m2 | m1 ): +// Choice(m2) +// 0 Choice(m1) +// 0 0 Leaf 0.33333333 +// 0 1 Leaf 0.6 +// 1 Choice(m1) +// 1 0 Leaf 0.66666667 +// 1 1 Leaf 0.4 +// DCFactorGraph +// size: 2 +// factor 0: [ x1 x2; m1 ]{ +// Choice(m1) +// 0 Leaf Jacobian factor on 2 keys: +// A[x1] = [ +// -1 +// ] +// A[x2] = [ +// 1 +// ] +// b = [ -1 ] +// No noise model +// 1 Leaf Jacobian factor on 2 keys: +// A[x1] = [ +// -1 +// ] +// A[x2] = [ +// 1 +// ] +// b = [ -0 ] +// No noise model +// } +// factor 1: [ x2 x3; m2 ]{ +// Choice(m2) +// 0 Leaf Jacobian factor on 2 keys: +// A[x2] = [ +// -1 +// ] +// A[x3] = [ +// 1 +// ] +// b = [ -1 ] +// No noise model +// 1 Leaf Jacobian factor on 2 keys: +// A[x2] = [ +// -1 +// ] +// A[x3] = [ +// 1 +// ] +// b = [ -0 ] +// No noise model +// } +// GaussianGraph +// size: 4 +// factor 0: +// A[x1] = [ +// 10 +// ] +// b = [ -10 ] +// No noise model +// factor 1: +// A[x1] = [ +// 10 +// ] +// b = [ -10 ] +// No noise model +// factor 2: +// A[x2] = [ +// 10 +// ] +// b = [ -10 ] +// No noise model +// factor 3: +// A[x3] = [ +// 10 +// ] +// b = [ -10 ] +// No noise model +// )"; +// EXPECT(assert_print_equal(expected_hybridFactorGraph, +// linearizedFactorGraph)); + +// // Expected output for hybridBayesNet. +// string expected_hybridBayesNet = R"( +// size: 3 +// factor 0: GaussianMixture [ x1 | x2 m1 ]{ +// Choice(m1) +// 0 Leaf Jacobian factor on 2 keys: +// p(x1 | x2) +// R = [ 14.1774 ] +// S[x2] = [ -0.0705346 ] +// d = [ -14.0364 ] +// No noise model +// 1 Leaf Jacobian factor on 2 keys: +// p(x1 | x2) +// R = [ 14.1774 ] +// S[x2] = [ -0.0705346 ] +// d = [ -14.1069 ] +// No noise model +// } +// factor 1: GaussianMixture [ x2 | x3 m2 m1 ]{ +// Choice(m2) +// 0 Choice(m1) +// 0 0 Leaf Jacobian factor on 2 keys: +// p(x2 | x3) +// R = [ 10.0993 ] +// S[x3] = [ -0.0990172 ] +// d = [ -9.99975 ] +// No noise model +// 0 1 Leaf Jacobian factor on 2 keys: +// p(x2 | x3) +// R = [ 10.0993 ] +// S[x3] = [ -0.0990172 ] +// d = [ -9.90122 ] +// No noise model +// 1 Choice(m1) +// 1 0 Leaf Jacobian factor on 2 keys: +// p(x2 | x3) +// R = [ 10.0993 ] +// S[x3] = [ -0.0990172 ] +// d = [ -10.0988 ] +// No noise model +// 1 1 Leaf Jacobian factor on 2 keys: +// p(x2 | x3) +// R = [ 10.0993 ] +// S[x3] = [ -0.0990172 ] +// d = [ -10.0002 ] +// No noise model +// } +// factor 2: GaussianMixture [ x3 | m2 m1 ]{ +// Choice(m2) +// 0 Choice(m1) +// 0 0 Leaf Jacobian factor on 1 keys: +// p(x3) +// R = [ 10.0494 ] +// d = [ -10.1489 ] +// No noise model +// 0 1 Leaf Jacobian factor on 1 keys: +// p(x3) +// R = [ 10.0494 ] +// d = [ -10.1479 ] +// No noise model +// 1 Choice(m1) +// 1 0 Leaf Jacobian factor on 1 keys: +// p(x3) +// R = [ 10.0494 ] +// d = [ -10.0504 ] +// No noise model +// 1 1 Leaf Jacobian factor on 1 keys: +// p(x3) +// R = [ 10.0494 ] +// d = [ -10.0494 ] +// No noise model +// } +// )"; +// EXPECT(assert_print_equal(expected_hybridBayesNet, *hybridBayesNet)); +// } + +// /* ************************************************************************* +// */ +// // Simple PlanarSLAM example test with 2 poses and 2 landmarks (each pose +// // connects to 1 landmark) to expose issue with default decision tree +// creation +// // in hybrid elimination. The hybrid factor is between the poses X0 and X1. +// The +// // issue arises if we eliminate a landmark variable first since it is not +// // connected to a DCFactor. +// TEST(HybridFactorGraph, DefaultDecisionTree) { +// NonlinearHybridFactorGraph fg; + +// // Add a prior on pose x1 at the origin. A prior factor consists of a mean +// and +// // a noise model (covariance matrix) +// Pose2 prior(0.0, 0.0, 0.0); // prior mean is at origin +// auto priorNoise = noiseModel::Diagonal::Sigmas( +// Vector3(0.3, 0.3, 0.1)); // 30cm std on x,y, 0.1 rad on theta +// fg.emplace_nonlinear>(X(0), prior, priorNoise); + +// using PlanarMotionModel = BetweenFactor; + +// // Add odometry factor +// Pose2 odometry(2.0, 0.0, 0.0); +// KeyVector contKeys = {X(0), X(1)}; +// auto noise_model = noiseModel::Isotropic::Sigma(3, 1.0); +// auto still = boost::make_shared(X(0), X(1), Pose2(0, 0, +// 0), +// noise_model), +// moving = boost::make_shared(X(0), X(1), odometry, +// noise_model); +// std::vector components = {still, moving}; +// auto dcFactor = boost::make_shared>( +// contKeys, DiscreteKeys{gtsam::DiscreteKey(M(1), 2)}, components); +// fg.push_back(dcFactor); + +// // Add Range-Bearing measurements to from X0 to L0 and X1 to L1. +// // create a noise model for the landmark measurements +// auto measurementNoise = noiseModel::Diagonal::Sigmas( +// Vector2(0.1, 0.2)); // 0.1 rad std on bearing, 20cm on range +// // create the measurement values - indices are (pose id, landmark id) +// Rot2 bearing11 = Rot2::fromDegrees(45), bearing22 = Rot2::fromDegrees(90); +// double range11 = std::sqrt(4.0 + 4.0), range22 = 2.0; + +// // Add Bearing-Range factors +// fg.emplace_nonlinear>( +// X(0), L(0), bearing11, range11, measurementNoise); +// fg.emplace_nonlinear>( +// X(1), L(1), bearing22, range22, measurementNoise); + +// // Create (deliberately inaccurate) initial estimate +// Values initialEstimate; +// initialEstimate.insert(X(0), Pose2(0.5, 0.0, 0.2)); +// initialEstimate.insert(X(1), Pose2(2.3, 0.1, -0.2)); +// initialEstimate.insert(L(0), Point2(1.8, 2.1)); +// initialEstimate.insert(L(1), Point2(4.1, 1.8)); + +// // We want to eliminate variables not connected to DCFactors first. +// Ordering ordering; +// ordering += L(0); +// ordering += L(1); +// ordering += X(0); +// ordering += X(1); + +// GaussianHybridFactorGraph linearized = fg.linearize(initialEstimate); +// gtsam::HybridBayesNet::shared_ptr hybridBayesNet; +// gtsam::GaussianHybridFactorGraph::shared_ptr remainingFactorGraph; + +// // This should NOT fail +// std::tie(hybridBayesNet, remainingFactorGraph) = +// linearized.eliminatePartialSequential(ordering); +// EXPECT_LONGS_EQUAL(4, hybridBayesNet->size()); +// EXPECT_LONGS_EQUAL(1, remainingFactorGraph->size()); +// } + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +/* ************************************************************************* */ \ No newline at end of file From 7e1827784995db5c673c63671810231e32cbcb4d Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 30 May 2022 16:51:15 -0400 Subject: [PATCH 0054/1497] fix base class --- gtsam/hybrid/NonlinearHybridFactorGraph.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gtsam/hybrid/NonlinearHybridFactorGraph.h b/gtsam/hybrid/NonlinearHybridFactorGraph.h index aeb5a4545a..3f7f5ba10f 100644 --- a/gtsam/hybrid/NonlinearHybridFactorGraph.h +++ b/gtsam/hybrid/NonlinearHybridFactorGraph.h @@ -43,7 +43,7 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { std::is_base_of::value>::type; public: - using Base = FactorGraph; + using Base = HybridFactorGraph; using This = NonlinearHybridFactorGraph; ///< this class using shared_ptr = boost::shared_ptr; ///< shared_ptr to This @@ -72,7 +72,6 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { using Base::size; using Base::operator[]; using Base::add; - using Base::push_back; using Base::resize; /** From 119679a3668226ad6499a41c1eb705fc9b0b93a1 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 30 May 2022 17:30:25 -0400 Subject: [PATCH 0055/1497] linearize returns object instead of pointer --- gtsam/hybrid/NonlinearHybridFactorGraph.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/gtsam/hybrid/NonlinearHybridFactorGraph.h b/gtsam/hybrid/NonlinearHybridFactorGraph.h index 3f7f5ba10f..82a331531e 100644 --- a/gtsam/hybrid/NonlinearHybridFactorGraph.h +++ b/gtsam/hybrid/NonlinearHybridFactorGraph.h @@ -150,13 +150,11 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { * @param continuousValues: Dictionary of continuous values. * @return GaussianHybridFactorGraph::shared_ptr */ - GaussianHybridFactorGraph::shared_ptr linearize( - const Values& continuousValues) const { + GaussianHybridFactorGraph linearize(const Values& continuousValues) const { // create an empty linear FG - GaussianHybridFactorGraph::shared_ptr linearFG = - boost::make_shared(); + GaussianHybridFactorGraph linearFG; - linearFG->reserve(size()); + linearFG.reserve(size()); // linearize all hybrid factors for (auto&& factor : factors_) { @@ -168,9 +166,9 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { if (factor->isHybrid()) { // Check if it is a nonlinear mixture factor if (auto nlmf = boost::dynamic_pointer_cast(factor)) { - linearFG->push_back(nlmf->linearize(continuousValues)); + linearFG.push_back(nlmf->linearize(continuousValues)); } else { - linearFG->push_back(factor); + linearFG.push_back(factor); } // Now check if the factor is a continuous only factor. @@ -183,18 +181,18 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { boost::dynamic_pointer_cast(nlhf->inner())) { auto hgf = boost::make_shared( nlf->linearize(continuousValues)); - linearFG->push_back(hgf); + linearFG.push_back(hgf); } else { - linearFG->push_back(factor); + linearFG.push_back(factor); } // Finally if nothing else, we are discrete-only which doesn't need // lineariztion. } else { - linearFG->push_back(factor); + linearFG.push_back(factor); } } else { - linearFG->push_back(GaussianFactor::shared_ptr()); + linearFG.push_back(GaussianFactor::shared_ptr()); } } return linearFG; From 3212dde4aa493313b8f861eedde694a980757a75 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 30 May 2022 17:50:50 -0400 Subject: [PATCH 0056/1497] remove unneeded method --- gtsam/hybrid/GaussianHybridFactorGraph.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/gtsam/hybrid/GaussianHybridFactorGraph.h b/gtsam/hybrid/GaussianHybridFactorGraph.h index b38a1ebd8d..6998ff899a 100644 --- a/gtsam/hybrid/GaussianHybridFactorGraph.h +++ b/gtsam/hybrid/GaussianHybridFactorGraph.h @@ -161,15 +161,6 @@ class GaussianHybridFactorGraph Base::push_back(sharedFactor); } } - - /** - * @brief Push back for Gaussian Factor specifically. - * - * @param sharedFactor Shared ptr to a gaussian factor. - */ - void push_back(const GaussianFactor::shared_ptr& sharedFactor) { - push_gaussian(sharedFactor); - } }; } // namespace gtsam From 0c16799ef664fe0d4493e0b5d3bd7eaedf6f6719 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 30 May 2022 17:51:07 -0400 Subject: [PATCH 0057/1497] GaussianMixtureFactor inherits from HybridFactor --- gtsam/hybrid/GaussianMixtureFactor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtsam/hybrid/GaussianMixtureFactor.h b/gtsam/hybrid/GaussianMixtureFactor.h index bd2e079cba..494a44ccf9 100644 --- a/gtsam/hybrid/GaussianMixtureFactor.h +++ b/gtsam/hybrid/GaussianMixtureFactor.h @@ -40,9 +40,9 @@ using GaussianFactorVector = std::vector; * of discrete variables indexes to the continuous gaussian distribution. * */ -class GaussianMixtureFactor : public HybridGaussianFactor { +class GaussianMixtureFactor : public HybridFactor { public: - using Base = HybridGaussianFactor; + using Base = HybridFactor; using This = GaussianMixtureFactor; using shared_ptr = boost::shared_ptr; From e711a62e2d1f2ee3011024bfdc7b5081d65d5212 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 30 May 2022 17:51:25 -0400 Subject: [PATCH 0058/1497] More tests working --- gtsam/hybrid/tests/Switching.h | 1 + .../tests/testNonlinearHybridFactorGraph.cpp | 159 ++++++++---------- 2 files changed, 71 insertions(+), 89 deletions(-) diff --git a/gtsam/hybrid/tests/Switching.h b/gtsam/hybrid/tests/Switching.h index be58824e00..42c61767e0 100644 --- a/gtsam/hybrid/tests/Switching.h +++ b/gtsam/hybrid/tests/Switching.h @@ -22,6 +22,7 @@ #include #include #include +#include #pragma once diff --git a/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp b/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp index 8043f78df8..6e40199921 100644 --- a/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp +++ b/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp @@ -58,7 +58,7 @@ TEST(HybridFactorGraph, GaussianFactorGraph) { Values linearizationPoint; linearizationPoint.insert(X(0), 0); - GaussianHybridFactorGraph ghfg = *fg.linearize(linearizationPoint); + GaussianHybridFactorGraph ghfg = fg.linearize(linearizationPoint); // Add a factor to the GaussianFactorGraph ghfg.add(JacobianFactor(X(0), I_1x1, Vector1(5))); @@ -72,121 +72,102 @@ TEST(HybridFactorGraph, GaussianFactorGraph) { /// NonlinearHybridFactorGraph. TEST(NonlinearHybridFactorGraph, Resize) { NonlinearHybridFactorGraph fg; - // auto nonlinearFactor = boost::make_shared>(); - // fg.push_back(nonlinearFactor); + auto nonlinearFactor = boost::make_shared>(); + fg.push_back(nonlinearFactor); - // auto discreteFactor = boost::make_shared(); - // fg.push_back(discreteFactor); + auto discreteFactor = boost::make_shared(); + fg.push_back(discreteFactor); - // auto dcFactor = boost::make_shared>(); - // fg.push_back(dcFactor); - // EXPECT_LONGS_EQUAL(fg.size(), 3); + auto dcFactor = boost::make_shared(); + fg.push_back(dcFactor); + + EXPECT_LONGS_EQUAL(fg.size(), 3); fg.resize(0); EXPECT_LONGS_EQUAL(fg.size(), 0); } -// /* ************************************************************************** -// */ -// /// Test that the resize method works correctly for a -// /// GaussianHybridFactorGraph. -// TEST(GaussianHybridFactorGraph, Resize) { -// NonlinearHybridFactorGraph nhfg; -// auto nonlinearFactor = boost::make_shared>( -// X(0), X(1), 0.0, Isotropic::Sigma(1, 0.1)); -// nhfg.push_back(nonlinearFactor); -// auto discreteFactor = boost::make_shared(); -// nhfg.push_back(discreteFactor); - -// KeyVector contKeys = {X(0), X(1)}; -// auto noise_model = noiseModel::Isotropic::Sigma(1, 1.0); -// auto still = boost::make_shared(X(0), X(1), 0.0, noise_model), -// moving = boost::make_shared(X(0), X(1), 1.0, -// noise_model); -// std::vector components = {still, moving}; -// auto dcFactor = boost::make_shared>( -// contKeys, DiscreteKeys{gtsam::DiscreteKey(M(1), 2)}, components); -// nhfg.push_back(dcFactor); - -// Values linearizationPoint; -// linearizationPoint.insert(X(0), 0); -// linearizationPoint.insert(X(1), 1); - -// // Generate `GaussianHybridFactorGraph` by linearizing -// GaussianHybridFactorGraph fg = nhfg.linearize(linearizationPoint); - -// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 1); -// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 1); -// EXPECT_LONGS_EQUAL(fg.gaussianGraph().size(), 1); - -// EXPECT_LONGS_EQUAL(fg.size(), 3); +/* ************************************************************************** + */ +/// Test that the resize method works correctly for a +/// GaussianHybridFactorGraph. +TEST(GaussianHybridFactorGraph, Resize) { + NonlinearHybridFactorGraph nhfg; + auto nonlinearFactor = boost::make_shared>( + X(0), X(1), 0.0, Isotropic::Sigma(1, 0.1)); + nhfg.push_back(nonlinearFactor); + auto discreteFactor = boost::make_shared(); + nhfg.push_back(discreteFactor); + + KeyVector contKeys = {X(0), X(1)}; + auto noise_model = noiseModel::Isotropic::Sigma(1, 1.0); + auto still = boost::make_shared(X(0), X(1), 0.0, noise_model), + moving = boost::make_shared(X(0), X(1), 1.0, noise_model); + + // TODO(Varun) This is declared as NonlinearFactor instead of MotionModel, aka + // not clear!! + std::vector components = {still, moving}; + auto dcFactor = boost::make_shared( + contKeys, DiscreteKeys{gtsam::DiscreteKey(M(1), 2)}, components); + nhfg.push_back(dcFactor); -// fg.resize(0); -// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 0); -// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 0); -// EXPECT_LONGS_EQUAL(fg.gaussianGraph().size(), 0); + Values linearizationPoint; + linearizationPoint.insert(X(0), 0); + linearizationPoint.insert(X(1), 1); -// EXPECT_LONGS_EQUAL(fg.size(), 0); -// } + // Generate `GaussianHybridFactorGraph` by linearizing + GaussianHybridFactorGraph gfg = nhfg.linearize(linearizationPoint); -// /* -// **************************************************************************** -// * Test push_back on HFG makes the correct distinction. -// */ -// TEST(HybridFactorGraph, PushBack) { -// NonlinearHybridFactorGraph fg; + EXPECT_LONGS_EQUAL(gfg.size(), 3); -// auto nonlinearFactor = boost::make_shared>(); -// fg.push_back(nonlinearFactor); + gfg.resize(0); + EXPECT_LONGS_EQUAL(gfg.size(), 0); +} -// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 0); -// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 0); -// EXPECT_LONGS_EQUAL(fg.nonlinearGraph().size(), 1); +/* +**************************************************************************** +* Test push_back on HFG makes the correct distinction. +*/ +TEST(HybridFactorGraph, PushBack) { + NonlinearHybridFactorGraph fg; -// fg = NonlinearHybridFactorGraph(); + auto nonlinearFactor = boost::make_shared>(); + fg.push_back(nonlinearFactor); -// auto discreteFactor = boost::make_shared(); -// fg.push_back(discreteFactor); + EXPECT_LONGS_EQUAL(fg.size(), 1); -// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 0); -// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 1); -// EXPECT_LONGS_EQUAL(fg.nonlinearGraph().size(), 0); + fg = NonlinearHybridFactorGraph(); -// fg = NonlinearHybridFactorGraph(); + auto discreteFactor = boost::make_shared(); + fg.push_back(discreteFactor); -// auto dcFactor = boost::make_shared>(); -// fg.push_back(dcFactor); + EXPECT_LONGS_EQUAL(fg.size(), 1); -// EXPECT_LONGS_EQUAL(fg.dcGraph().size(), 1); -// EXPECT_LONGS_EQUAL(fg.discreteGraph().size(), 0); -// EXPECT_LONGS_EQUAL(fg.nonlinearGraph().size(), 0); + fg = NonlinearHybridFactorGraph(); -// // Now do the same with GaussianHybridFactorGraph -// GaussianHybridFactorGraph ghfg; + auto dcFactor = boost::make_shared(); + fg.push_back(dcFactor); -// auto gaussianFactor = boost::make_shared(); -// ghfg.push_back(gaussianFactor); + EXPECT_LONGS_EQUAL(fg.size(), 1); -// EXPECT_LONGS_EQUAL(ghfg.dcGraph().size(), 0); -// EXPECT_LONGS_EQUAL(ghfg.discreteGraph().size(), 0); -// EXPECT_LONGS_EQUAL(ghfg.gaussianGraph().size(), 1); + // Now do the same with GaussianHybridFactorGraph + GaussianHybridFactorGraph ghfg; -// ghfg = GaussianHybridFactorGraph(); + auto gaussianFactor = boost::make_shared(); + ghfg.push_back(gaussianFactor); -// ghfg.push_back(discreteFactor); + EXPECT_LONGS_EQUAL(ghfg.size(), 1); -// EXPECT_LONGS_EQUAL(ghfg.dcGraph().size(), 0); -// EXPECT_LONGS_EQUAL(ghfg.discreteGraph().size(), 1); -// EXPECT_LONGS_EQUAL(ghfg.gaussianGraph().size(), 0); + ghfg = GaussianHybridFactorGraph(); + ghfg.push_back(discreteFactor); -// ghfg = GaussianHybridFactorGraph(); + EXPECT_LONGS_EQUAL(ghfg.size(), 1); -// ghfg.push_back(dcFactor); + ghfg = GaussianHybridFactorGraph(); + ghfg.push_back(dcFactor); -// EXPECT_LONGS_EQUAL(ghfg.dcGraph().size(), 1); -// EXPECT_LONGS_EQUAL(ghfg.discreteGraph().size(), 0); -// EXPECT_LONGS_EQUAL(ghfg.gaussianGraph().size(), 0); -// } + EXPECT_LONGS_EQUAL(ghfg.size(), 1); +} // /* // ****************************************************************************/ From 9e737dbbd8efe75b1a183fc34983b8fab75e6250 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 3 Jun 2022 12:47:21 -0400 Subject: [PATCH 0059/1497] initial pruning method --- gtsam/hybrid/HybridBayesNet.cpp | 95 +++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/gtsam/hybrid/HybridBayesNet.cpp b/gtsam/hybrid/HybridBayesNet.cpp index 1292711d89..7d18347230 100644 --- a/gtsam/hybrid/HybridBayesNet.cpp +++ b/gtsam/hybrid/HybridBayesNet.cpp @@ -14,3 +14,98 @@ */ #include + +namespace gtsam { + +/* ************************************************************************* */ +/// Return the DiscreteKey vector as a set. +static std::set DiscreteKeysAsSet(const DiscreteKeys &dkeys) { + std::set s; + s.insert(dkeys.begin(), dkeys.end()); + return s; +} + +/* ************************************************************************* */ +HybridBayesNet HybridBayesNet::prune( + const DecisionTreeFactor::shared_ptr &discreteFactor) const { + /* To Prune, we visitWith every leaf in the GaussianMixture. + * For each leaf, using the assignment we can check the discrete decision tree + * for 0.0 probability, then just set the leaf to a nullptr. + * + * We can later check the GaussianMixture for just nullptrs. + */ + + HybridBayesNet prunedBayesNetFragment; + + // Functional which loops over all assignments and create a set of + // GaussianConditionals + auto pruner = + [&](const Assignment &choices, + const GaussianFactor::shared_ptr &gf) -> GaussianFactor::shared_ptr { + // typecast so we can use this to get probability value + DiscreteValues values(choices); + + if ((*discreteFactor)(values) == 0.0) { + // empty aka null pointer + boost::shared_ptr null; + return null; + } else { + return gf; + } + }; + + // Go through all the conditionals in the + // Bayes Net and prune them as per discreteFactor. + for (size_t i = 0; i < this->size(); i++) { + HybridConditional::shared_ptr conditional = this->at(i); + + GaussianMixture::shared_ptr gaussianMixture = + boost::dynamic_pointer_cast(conditional->inner()); + + if (gaussianMixture) { + // We may have mixtures with less discrete keys than discreteFactor so we + // skip those since the label assignment does not exist. + auto gmKeySet = DiscreteKeysAsSet(gaussianMixture->discreteKeys()); + auto dfKeySet = DiscreteKeysAsSet(discreteFactor->discreteKeys()); + if (gmKeySet != dfKeySet) { + // Add the gaussianMixture which doesn't have to be pruned. + prunedBayesNetFragment.push_back( + boost::make_shared(gaussianMixture)); + continue; + } + + // The GaussianMixture stores all the conditionals and uneliminated + // factors in the factors tree. + auto gaussianMixtureTree = gaussianMixture->factors(); + + // Run the pruning to get a new, pruned tree + auto prunedFactors = gaussianMixtureTree.apply(pruner); + + DiscreteKeys discreteKeys = gaussianMixture->discreteKeys(); + // reverse keys to get a natural ordering + std::reverse(discreteKeys.begin(), discreteKeys.end()); + + // Convert to GaussianConditionals + auto prunedTree = GaussianMixture::Conditionals( + prunedFactors, [](const GaussianFactor::shared_ptr &factor) { + return boost::dynamic_pointer_cast(factor); + }); + + // Create the new gaussian mixture and add it to the bayes net. + auto prunedGaussianMixture = boost::make_shared( + gaussianMixture->frontals(), gaussianMixture->parents(), discreteKeys, + prunedTree); + + prunedBayesNetFragment.push_back( + boost::make_shared(prunedGaussianMixture)); + + } else { + // Add the non-GaussianMixture conditional + prunedBayesNetFragment.push_back(conditional); + } + } + + return prunedBayesNetFragment; +} + +} // namespace gtsam From 89768cf692144a8ccc24d66f993bcd249059f32d Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 3 Jun 2022 13:07:46 -0400 Subject: [PATCH 0060/1497] record continuous keys separately --- gtsam/hybrid/HybridFactor.cpp | 9 +++++---- gtsam/hybrid/HybridFactor.h | 12 +++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gtsam/hybrid/HybridFactor.cpp b/gtsam/hybrid/HybridFactor.cpp index 127c9761c0..cdae5faa67 100644 --- a/gtsam/hybrid/HybridFactor.cpp +++ b/gtsam/hybrid/HybridFactor.cpp @@ -50,7 +50,7 @@ DiscreteKeys CollectDiscreteKeys(const DiscreteKeys &key1, /* ************************************************************************ */ HybridFactor::HybridFactor(const KeyVector &keys) - : Base(keys), isContinuous_(true), nrContinuous_(keys.size()) {} + : Base(keys), isContinuous_(true), continuousKeys_(keys) {} /* ************************************************************************ */ HybridFactor::HybridFactor(const KeyVector &continuousKeys, @@ -59,8 +59,8 @@ HybridFactor::HybridFactor(const KeyVector &continuousKeys, isDiscrete_((continuousKeys.size() == 0) && (discreteKeys.size() != 0)), isContinuous_((continuousKeys.size() != 0) && (discreteKeys.size() == 0)), isHybrid_((continuousKeys.size() != 0) && (discreteKeys.size() != 0)), - nrContinuous_(continuousKeys.size()), - discreteKeys_(discreteKeys) {} + discreteKeys_(discreteKeys), + continuousKeys_(continuousKeys) {} /* ************************************************************************ */ HybridFactor::HybridFactor(const DiscreteKeys &discreteKeys) @@ -73,7 +73,8 @@ bool HybridFactor::equals(const HybridFactor &lf, double tol) const { const This *e = dynamic_cast(&lf); return e != nullptr && Base::equals(*e, tol) && isDiscrete_ == e->isDiscrete_ && isContinuous_ == e->isContinuous_ && - isHybrid_ == e->isHybrid_ && nrContinuous_ == e->nrContinuous_; + isHybrid_ == e->isHybrid_ && continuousKeys_ == e->continuousKeys_ && + discreteKeys_ == e->discreteKeys_; } /* ************************************************************************ */ diff --git a/gtsam/hybrid/HybridFactor.h b/gtsam/hybrid/HybridFactor.h index 244fba4ccb..ffa28d3f71 100644 --- a/gtsam/hybrid/HybridFactor.h +++ b/gtsam/hybrid/HybridFactor.h @@ -50,7 +50,10 @@ class GTSAM_EXPORT HybridFactor : public Factor { size_t nrContinuous_ = 0; protected: + // Set of DiscreteKeys for this factor. DiscreteKeys discreteKeys_; + // For bookkeeping + KeyVector continuousKeys_; public: // typedefs needed to play nice with gtsam @@ -117,10 +120,13 @@ class GTSAM_EXPORT HybridFactor : public Factor { bool isHybrid() const { return isHybrid_; } /// Return the number of continuous variables in this factor. - size_t nrContinuous() const { return nrContinuous_; } + size_t nrContinuous() const { return continuousKeys_.size(); } - /// Return vector of discrete keys. - DiscreteKeys discreteKeys() const { return discreteKeys_; } + /// Return the discrete keys for this factor. + const DiscreteKeys &discreteKeys() const { return discreteKeys_; } + + /// Return only the continuous keys for this factor. + const KeyVector &continuousKeys() const { return continuousKeys_; } /// @} }; From ad77a45a0d9ded056d01a6e9b7af4331e9ac3425 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 3 Jun 2022 13:08:32 -0400 Subject: [PATCH 0061/1497] formatting and docs update --- gtsam/hybrid/GaussianMixture.cpp | 15 ++++++--------- gtsam/hybrid/GaussianMixture.h | 11 +++++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gtsam/hybrid/GaussianMixture.cpp b/gtsam/hybrid/GaussianMixture.cpp index 0000575182..8970a3993a 100644 --- a/gtsam/hybrid/GaussianMixture.cpp +++ b/gtsam/hybrid/GaussianMixture.cpp @@ -36,8 +36,7 @@ GaussianMixture::GaussianMixture( conditionals_(conditionals) {} /* *******************************************************************************/ -const GaussianMixture::Conditionals & -GaussianMixture::conditionals() { +const GaussianMixture::Conditionals &GaussianMixture::conditionals() { return conditionals_; } @@ -48,8 +47,8 @@ GaussianMixture GaussianMixture::FromConditionals( const std::vector &conditionalsList) { Conditionals dt(discreteParents, conditionalsList); - return GaussianMixture(continuousFrontals, continuousParents, - discreteParents, dt); + return GaussianMixture(continuousFrontals, continuousParents, discreteParents, + dt); } /* *******************************************************************************/ @@ -66,8 +65,7 @@ GaussianMixture::Sum GaussianMixture::add( } /* *******************************************************************************/ -GaussianMixture::Sum -GaussianMixture::asGaussianFactorGraphTree() const { +GaussianMixture::Sum GaussianMixture::asGaussianFactorGraphTree() const { auto lambda = [](const GaussianFactor::shared_ptr &factor) { GaussianFactorGraph result; result.push_back(factor); @@ -77,15 +75,14 @@ GaussianMixture::asGaussianFactorGraphTree() const { } /* *******************************************************************************/ -bool GaussianMixture::equals(const HybridFactor &lf, - double tol) const { +bool GaussianMixture::equals(const HybridFactor &lf, double tol) const { const This *e = dynamic_cast(&lf); return e != nullptr && BaseFactor::equals(*e, tol); } /* *******************************************************************************/ void GaussianMixture::print(const std::string &s, - const KeyFormatter &formatter) const { + const KeyFormatter &formatter) const { std::cout << s; if (isContinuous()) std::cout << "Continuous "; if (isDiscrete()) std::cout << "Discrete "; diff --git a/gtsam/hybrid/GaussianMixture.h b/gtsam/hybrid/GaussianMixture.h index e855067150..6100b49d19 100644 --- a/gtsam/hybrid/GaussianMixture.h +++ b/gtsam/hybrid/GaussianMixture.h @@ -28,11 +28,14 @@ namespace gtsam { /** * @brief A conditional of gaussian mixtures indexed by discrete variables, as - * part of a Bayes Network. + * part of a Bayes Network. This is the result of the elimination of a + * continuous variable in a hybrid scheme, such that the remaining variables are + * discrete+continuous. * - * Represents the conditional density P(X | M, Z) where X is a continuous random - * variable, M is the selection of discrete variables corresponding to a subset - * of the Gaussian variables and Z is parent of this node + * Represents the conditional density P(X | M, Z) where X is the set of + * continuous random variables, M is the selection of discrete variables + * corresponding to a subset of the Gaussian variables and Z is parent of this + * node . * * The probability P(x|y,z,...) is proportional to * \f$ \sum_i k_i \exp - \frac{1}{2} |R_i x - (d_i - S_i y - T_i z - ...)|^2 \f$ From c2e5061b711ecdf4f7308a01f0e3f6d5e7419391 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 3 Jun 2022 13:25:19 -0400 Subject: [PATCH 0062/1497] add pruning to HybridBayesNet --- gtsam/hybrid/HybridBayesNet.cpp | 34 ++++++++++++++++----------------- gtsam/hybrid/HybridBayesNet.h | 6 +++++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/gtsam/hybrid/HybridBayesNet.cpp b/gtsam/hybrid/HybridBayesNet.cpp index 7d18347230..d3c77d83e3 100644 --- a/gtsam/hybrid/HybridBayesNet.cpp +++ b/gtsam/hybrid/HybridBayesNet.cpp @@ -39,18 +39,18 @@ HybridBayesNet HybridBayesNet::prune( // Functional which loops over all assignments and create a set of // GaussianConditionals - auto pruner = - [&](const Assignment &choices, - const GaussianFactor::shared_ptr &gf) -> GaussianFactor::shared_ptr { + auto pruner = [&](const Assignment &choices, + const GaussianConditional::shared_ptr &conditional) + -> GaussianConditional::shared_ptr { // typecast so we can use this to get probability value DiscreteValues values(choices); if ((*discreteFactor)(values) == 0.0) { // empty aka null pointer - boost::shared_ptr null; + boost::shared_ptr null; return null; } else { - return gf; + return conditional; } }; @@ -74,28 +74,28 @@ HybridBayesNet HybridBayesNet::prune( continue; } - // The GaussianMixture stores all the conditionals and uneliminated - // factors in the factors tree. - auto gaussianMixtureTree = gaussianMixture->factors(); - // Run the pruning to get a new, pruned tree - auto prunedFactors = gaussianMixtureTree.apply(pruner); + GaussianMixture::Conditionals prunedTree = + gaussianMixture->conditionals().apply(pruner); DiscreteKeys discreteKeys = gaussianMixture->discreteKeys(); // reverse keys to get a natural ordering std::reverse(discreteKeys.begin(), discreteKeys.end()); - // Convert to GaussianConditionals - auto prunedTree = GaussianMixture::Conditionals( - prunedFactors, [](const GaussianFactor::shared_ptr &factor) { - return boost::dynamic_pointer_cast(factor); - }); + // Convert from boost::iterator_range to std::vector. + std::vector frontals, parents; + for (Key key : gaussianMixture->frontals()) { + frontals.push_back(key); + } + for (Key key : gaussianMixture->parents()) { + parents.push_back(key); + } // Create the new gaussian mixture and add it to the bayes net. auto prunedGaussianMixture = boost::make_shared( - gaussianMixture->frontals(), gaussianMixture->parents(), discreteKeys, - prunedTree); + frontals, parents, discreteKeys, prunedTree); + // Type-erase and add to the pruned Bayes Net fragment. prunedBayesNetFragment.push_back( boost::make_shared(prunedGaussianMixture)); diff --git a/gtsam/hybrid/HybridBayesNet.h b/gtsam/hybrid/HybridBayesNet.h index 43eead2801..834c4c3efd 100644 --- a/gtsam/hybrid/HybridBayesNet.h +++ b/gtsam/hybrid/HybridBayesNet.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include @@ -35,7 +36,10 @@ class GTSAM_EXPORT HybridBayesNet : public BayesNet { using sharedConditional = boost::shared_ptr; /** Construct empty bayes net */ - HybridBayesNet() = default; + HybridBayesNet() : Base() {} + + HybridBayesNet prune( + const DecisionTreeFactor::shared_ptr &discreteFactor) const; }; } // namespace gtsam From 28db8b20ff15e3b66e5e61c72e385e46212af702 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 4 Jun 2022 11:45:42 -0400 Subject: [PATCH 0063/1497] use KeyVector and iterator constructor --- gtsam/hybrid/HybridBayesNet.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gtsam/hybrid/HybridBayesNet.cpp b/gtsam/hybrid/HybridBayesNet.cpp index d3c77d83e3..0403ca0d33 100644 --- a/gtsam/hybrid/HybridBayesNet.cpp +++ b/gtsam/hybrid/HybridBayesNet.cpp @@ -82,14 +82,12 @@ HybridBayesNet HybridBayesNet::prune( // reverse keys to get a natural ordering std::reverse(discreteKeys.begin(), discreteKeys.end()); - // Convert from boost::iterator_range to std::vector. - std::vector frontals, parents; - for (Key key : gaussianMixture->frontals()) { - frontals.push_back(key); - } - for (Key key : gaussianMixture->parents()) { - parents.push_back(key); - } + // Convert from boost::iterator_range to KeyVector + // so we can pass it to constructor. + KeyVector frontals(gaussianMixture->frontals().begin(), + gaussianMixture->frontals().end()), + parents(gaussianMixture->parents().begin(), + gaussianMixture->parents().end()); // Create the new gaussian mixture and add it to the bayes net. auto prunedGaussianMixture = boost::make_shared( From 5c5c05370a14141a9ec60628bdb1327cab98f1de Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 18:38:21 -0400 Subject: [PATCH 0064/1497] Add HybridFactorGraph base class and more methods for adding gaussian factors --- gtsam/hybrid/HybridFactorGraph.h | 148 +++++++++++++++++++++++ gtsam/hybrid/HybridGaussianFactorGraph.h | 61 ++++++++-- 2 files changed, 202 insertions(+), 7 deletions(-) create mode 100644 gtsam/hybrid/HybridFactorGraph.h diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h new file mode 100644 index 0000000000..ce0241d255 --- /dev/null +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -0,0 +1,148 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file HybridFactorGraph.h + * @brief Hybrid factor graph base class that uses type erasure + * @author Varun Agrawal + * @date May 28, 2022 + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +namespace gtsam { + +using SharedFactor = boost::shared_ptr; + +/** + * Hybrid Factor Graph + * ----------------------- + * This is the base hybrid factor graph. + * Everything inside needs to be hybrid factor or hybrid conditional. + */ +class HybridFactorGraph : public FactorGraph { + public: + using Base = FactorGraph; + using This = HybridFactorGraph; ///< this class + using shared_ptr = boost::shared_ptr; ///< shared_ptr to This + + using Values = gtsam::Values; ///< backwards compatibility + using Indices = KeyVector; ///> map from keys to values + + protected: + /// Check if FACTOR type is derived from DiscreteFactor. + template + using IsDiscrete = typename std::enable_if< + std::is_base_of::value>::type; + + /// Check if FACTOR type is derived from HybridFactor. + template + using IsHybrid = typename std::enable_if< + std::is_base_of::value>::type; + + public: + /// @name Constructors + /// @{ + + /// Default constructor + HybridFactorGraph() = default; + + /** + * Implicit copy/downcast constructor to override explicit template container + * constructor. In BayesTree this is used for: + * `cachedSeparatorMarginal_.reset(*separatorMarginal)` + * */ + template + HybridFactorGraph(const FactorGraph& graph) : Base(graph) {} + + /// @} + + // Allow use of selected FactorGraph methods: + using Base::empty; + using Base::reserve; + using Base::size; + using Base::operator[]; + using Base::add; + using Base::push_back; + using Base::resize; + + /** + * Add a discrete factor *pointer* to the internal discrete graph + * @param discreteFactor - boost::shared_ptr to the factor to add + */ + template + IsDiscrete push_discrete( + const boost::shared_ptr& discreteFactor) { + Base::push_back(boost::make_shared(discreteFactor)); + } + + /** + * Add a discrete-continuous (Hybrid) factor *pointer* to the graph + * @param hybridFactor - boost::shared_ptr to the factor to add + */ + template + IsHybrid push_hybrid(const boost::shared_ptr& hybridFactor) { + Base::push_back(hybridFactor); + } + + /// delete emplace_shared. + template + void emplace_shared(Args&&... args) = delete; + + /// Construct a factor and add (shared pointer to it) to factor graph. + template + IsDiscrete emplace_discrete(Args&&... args) { + auto factor = boost::allocate_shared( + Eigen::aligned_allocator(), std::forward(args)...); + push_discrete(factor); + } + + /// Construct a factor and add (shared pointer to it) to factor graph. + template + IsHybrid emplace_hybrid(Args&&... args) { + auto factor = boost::allocate_shared( + Eigen::aligned_allocator(), std::forward(args)...); + push_hybrid(factor); + } + + /** + * @brief Add a single factor shared pointer to the hybrid factor graph. + * Dynamically handles the factor type and assigns it to the correct + * underlying container. + * + * @param sharedFactor The factor to add to this factor graph. + */ + void push_back(const SharedFactor& sharedFactor) { + if (auto p = boost::dynamic_pointer_cast(sharedFactor)) { + push_discrete(p); + } + if (auto p = boost::dynamic_pointer_cast(sharedFactor)) { + push_hybrid(p); + } + } + + /** Constructor from iterator over factors (shared_ptr or plain objects) */ + template + void push_back(ITERATOR firstFactor, ITERATOR lastFactor) { + for (auto&& it = firstFactor; it != lastFactor; it++) { + push_back(*it); + } + } +}; + +} // namespace gtsam \ No newline at end of file diff --git a/gtsam/hybrid/HybridGaussianFactorGraph.h b/gtsam/hybrid/HybridGaussianFactorGraph.h index 0188aa652c..1d49904fed 100644 --- a/gtsam/hybrid/HybridGaussianFactorGraph.h +++ b/gtsam/hybrid/HybridGaussianFactorGraph.h @@ -19,6 +19,8 @@ #pragma once #include +#include +#include #include #include #include @@ -53,10 +55,9 @@ struct EliminationTraits { typedef HybridBayesNet BayesNetType; ///< Type of Bayes net from sequential elimination typedef HybridEliminationTree - EliminationTreeType; ///< Type of elimination tree - typedef HybridBayesTree BayesTreeType; ///< Type of Bayes tree - typedef HybridJunctionTree - JunctionTreeType; ///< Type of Junction tree + EliminationTreeType; ///< Type of elimination tree + typedef HybridBayesTree BayesTreeType; ///< Type of Bayes tree + typedef HybridJunctionTree JunctionTreeType; ///< Type of Junction tree /// The default dense elimination function static std::pair, boost::shared_ptr > @@ -72,10 +73,16 @@ struct EliminationTraits { * Everything inside needs to be hybrid factor or hybrid conditional. */ class GTSAM_EXPORT HybridGaussianFactorGraph - : public FactorGraph, + : public HybridFactorGraph, public EliminateableFactorGraph { + protected: + /// Check if FACTOR type is derived from GaussianFactor. + template + using IsGaussian = typename std::enable_if< + std::is_base_of::value>::type; + public: - using Base = FactorGraph; + using Base = HybridFactorGraph; using This = HybridGaussianFactorGraph; ///< this class using BaseEliminateable = EliminateableFactorGraph; ///< for elimination @@ -100,7 +107,13 @@ class GTSAM_EXPORT HybridGaussianFactorGraph /// @} - using FactorGraph::add; + using Base::empty; + using Base::reserve; + using Base::size; + using Base::operator[]; + using Base::add; + using Base::push_back; + using Base::resize; /// Add a Jacobian factor to the factor graph. void add(JacobianFactor&& factor); @@ -113,6 +126,40 @@ class GTSAM_EXPORT HybridGaussianFactorGraph /// Add a DecisionTreeFactor as a shared ptr. void add(boost::shared_ptr factor); + + /** + * Add a gaussian factor *pointer* to the internal gaussian factor graph + * @param gaussianFactor - boost::shared_ptr to the factor to add + */ + template + IsGaussian push_gaussian( + const boost::shared_ptr& gaussianFactor) { + Base::Base::push_back( + boost::make_shared(gaussianFactor)); + } + + /// Construct a factor and add (shared pointer to it) to factor graph. + template + IsGaussian emplace_gaussian(Args&&... args) { + auto factor = boost::allocate_shared( + Eigen::aligned_allocator(), std::forward(args)...); + push_gaussian(factor); + } + + /** + * @brief Add a single factor shared pointer to the hybrid factor graph. + * Dynamically handles the factor type and assigns it to the correct + * underlying container. + * + * @param sharedFactor The factor to add to this factor graph. + */ + void push_back(const SharedFactor& sharedFactor) { + if (auto p = boost::dynamic_pointer_cast(sharedFactor)) { + push_gaussian(p); + } else { + Base::push_back(sharedFactor); + } + } }; } // namespace gtsam From 44079d13b4357ae958e754b6ed3769c133f0f565 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 18:38:46 -0400 Subject: [PATCH 0065/1497] refactor testGaussianHybridFactorGraph to include comments and valid tests --- .../tests/testGaussianHybridFactorGraph.cpp | 225 ++++++------------ 1 file changed, 70 insertions(+), 155 deletions(-) diff --git a/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp b/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp index 552bb18f59..9e1a2efdd4 100644 --- a/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp +++ b/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp @@ -58,26 +58,30 @@ using gtsam::symbol_shorthand::X; using gtsam::symbol_shorthand::Y; /* ************************************************************************* */ -TEST(HybridGaussianFactorGraph, creation) { - HybridConditional test; +TEST(HybridGaussianFactorGraph, Creation) { + HybridConditional conditional; HybridGaussianFactorGraph hfg; - hfg.add(HybridGaussianFactor(JacobianFactor(0, I_3x3, Z_3x1))); + hfg.add(HybridGaussianFactor(JacobianFactor(X(0), I_3x3, Z_3x1))); + + // Define a gaussian mixture conditional P(x0|x1, c0) and add it to the factor + // graph + GaussianMixture gm({X(0)}, {X(1)}, DiscreteKeys(DiscreteKey{C(0), 2}), + GaussianMixture::Conditionals( + C(0), + boost::make_shared( + X(0), Z_3x1, I_3x3, X(1), I_3x3), + boost::make_shared( + X(0), Vector3::Ones(), I_3x3, X(1), I_3x3))); + hfg.add(gm); - GaussianMixture clgc( - {X(0)}, {X(1)}, DiscreteKeys(DiscreteKey{C(0), 2}), - GaussianMixture::Conditionals( - C(0), - boost::make_shared(X(0), Z_3x1, I_3x3, X(1), - I_3x3), - boost::make_shared(X(0), Vector3::Ones(), I_3x3, - X(1), I_3x3))); - GTSAM_PRINT(clgc); + EXPECT_LONGS_EQUAL(2, hfg.size()); } /* ************************************************************************* */ -TEST(HybridGaussianFactorGraph, eliminate) { +TEST(HybridGaussianFactorGraph, EliminateSequential) { + // Test elimination of a single variable. HybridGaussianFactorGraph hfg; hfg.add(HybridGaussianFactor(JacobianFactor(0, I_3x3, Z_3x1))); @@ -88,11 +92,13 @@ TEST(HybridGaussianFactorGraph, eliminate) { } /* ************************************************************************* */ -TEST(HybridGaussianFactorGraph, eliminateMultifrontal) { +TEST(HybridGaussianFactorGraph, EliminateMultifrontal) { + // Test multifrontal elimination HybridGaussianFactorGraph hfg; DiscreteKey c(C(1), 2); + // Add priors on x0 and c1 hfg.add(JacobianFactor(X(0), I_3x3, Z_3x1)); hfg.add(HybridDiscreteFactor(DecisionTreeFactor(c, {2, 8}))); @@ -110,9 +116,12 @@ TEST(HybridGaussianFactorGraph, eliminateFullSequentialEqualChance) { DiscreteKey c1(C(1), 2); + // Add prior on x0 hfg.add(JacobianFactor(X(0), I_3x3, Z_3x1)); + // Add factor between x0 and x1 hfg.add(JacobianFactor(X(0), I_3x3, X(1), -I_3x3, Z_3x1)); + // Add a gaussian mixture factor ϕ(x1, c1) DecisionTree dt( C(1), boost::make_shared(X(1), I_3x3, Z_3x1), boost::make_shared(X(1), I_3x3, Vector3::Ones())); @@ -123,9 +132,9 @@ TEST(HybridGaussianFactorGraph, eliminateFullSequentialEqualChance) { hfg.eliminateSequential(Ordering::ColamdConstrainedLast(hfg, {C(1)})); auto dc = result->at(2)->asDiscreteConditional(); - DiscreteValues dv; - dv[C(1)] = 0; - EXPECT_DOUBLES_EQUAL(0.6225, dc->operator()(dv), 1e-3); + DiscreteValues mode; + mode[C(1)] = 0; + EXPECT_DOUBLES_EQUAL(0.6225, (*dc)(mode), 1e-3); } /* ************************************************************************* */ @@ -134,26 +143,26 @@ TEST(HybridGaussianFactorGraph, eliminateFullSequentialSimple) { DiscreteKey c1(C(1), 2); + // Add prior on x0 hfg.add(JacobianFactor(X(0), I_3x3, Z_3x1)); + // Add factor between x0 and x1 hfg.add(JacobianFactor(X(0), I_3x3, X(1), -I_3x3, Z_3x1)); DecisionTree dt( C(1), boost::make_shared(X(1), I_3x3, Z_3x1), boost::make_shared(X(1), I_3x3, Vector3::Ones())); - hfg.add(GaussianMixtureFactor({X(1)}, {c1}, dt)); - // hfg.add(GaussianMixtureFactor({X(0)}, {c1}, dt)); + + // Discrete probability table for c1 hfg.add(HybridDiscreteFactor(DecisionTreeFactor(c1, {2, 8}))); + // Joint discrete probability table for c1, c2 hfg.add(HybridDiscreteFactor( DecisionTreeFactor({{C(1), 2}, {C(2), 2}}, "1 2 3 4"))); - // hfg.add(HybridDiscreteFactor(DecisionTreeFactor({{C(2), 2}, {C(3), 2}}, "1 - // 2 3 4"))); hfg.add(HybridDiscreteFactor(DecisionTreeFactor({{C(3), 2}, - // {C(1), 2}}, "1 2 2 1"))); auto result = hfg.eliminateSequential( Ordering::ColamdConstrainedLast(hfg, {C(1), C(2)})); - GTSAM_PRINT(*result); + EXPECT_LONGS_EQUAL(4, result->size()); } /* ************************************************************************* */ @@ -165,28 +174,19 @@ TEST(HybridGaussianFactorGraph, eliminateFullMultifrontalSimple) { hfg.add(JacobianFactor(X(0), I_3x3, Z_3x1)); hfg.add(JacobianFactor(X(0), I_3x3, X(1), -I_3x3, Z_3x1)); - // DecisionTree dt( - // C(1), boost::make_shared(X(1), I_3x3, Z_3x1), - // boost::make_shared(X(1), I_3x3, Vector3::Ones())); - - // hfg.add(GaussianMixtureFactor({X(1)}, {c1}, dt)); hfg.add(GaussianMixtureFactor::FromFactors( {X(1)}, {{C(1), 2}}, {boost::make_shared(X(1), I_3x3, Z_3x1), boost::make_shared(X(1), I_3x3, Vector3::Ones())})); - // hfg.add(GaussianMixtureFactor({X(0)}, {c1}, dt)); hfg.add(DecisionTreeFactor(c1, {2, 8})); hfg.add(DecisionTreeFactor({{C(1), 2}, {C(2), 2}}, "1 2 3 4")); - // hfg.add(HybridDiscreteFactor(DecisionTreeFactor({{C(2), 2}, {C(3), 2}}, "1 - // 2 3 4"))); hfg.add(HybridDiscreteFactor(DecisionTreeFactor({{C(3), 2}, - // {C(1), 2}}, "1 2 2 1"))); auto result = hfg.eliminateMultifrontal( Ordering::ColamdConstrainedLast(hfg, {C(1), C(2)})); - GTSAM_PRINT(*result); - GTSAM_PRINT(*result->marginalFactor(C(2))); + // GTSAM_PRINT(*result); + // GTSAM_PRINT(*result->marginalFactor(C(2))); } /* ************************************************************************* */ @@ -195,30 +195,28 @@ TEST(HybridGaussianFactorGraph, eliminateFullMultifrontalCLG) { DiscreteKey c(C(1), 2); + // Prior on x0 hfg.add(JacobianFactor(X(0), I_3x3, Z_3x1)); + // Factor between x0-x1 hfg.add(JacobianFactor(X(0), I_3x3, X(1), -I_3x3, Z_3x1)); + // Decision tree with different modes on x1 DecisionTree dt( C(1), boost::make_shared(X(1), I_3x3, Z_3x1), boost::make_shared(X(1), I_3x3, Vector3::Ones())); + // Hybrid factor P(x1|c1) hfg.add(GaussianMixtureFactor({X(1)}, {c}, dt)); + // Prior factor on c1 hfg.add(HybridDiscreteFactor(DecisionTreeFactor(c, {2, 8}))); - // hfg.add(HybridDiscreteFactor(DecisionTreeFactor({{C(1), 2}, {C(2), 2}}, "1 - // 2 3 4"))); + // Get a constrained ordering keeping c1 last auto ordering_full = Ordering::ColamdConstrainedLast(hfg, {C(1)}); + // Returns a Hybrid Bayes Tree with distribution P(x0|x1)P(x1|c1)P(c1) HybridBayesTree::shared_ptr hbt = hfg.eliminateMultifrontal(ordering_full); - GTSAM_PRINT(*hbt); - /* - Explanation: the Junction tree will need to reeliminate to get to the marginal - on X(1), which is not possible because it involves eliminating discrete before - continuous. The solution to this, however, is in Murphy02. TLDR is that this - is 1. expensive and 2. inexact. neverless it is doable. And I believe that we - should do this. - */ + EXPECT_LONGS_EQUAL(3, hbt->size()); } /* ************************************************************************* */ @@ -233,10 +231,6 @@ TEST(HybridGaussianFactorGraph, eliminateFullMultifrontalTwoClique) { hfg.add(JacobianFactor(X(1), I_3x3, X(2), -I_3x3, Z_3x1)); { - // DecisionTree dt( - // C(0), boost::make_shared(X(0), I_3x3, Z_3x1), - // boost::make_shared(X(0), I_3x3, Vector3::Ones())); - hfg.add(GaussianMixtureFactor::FromFactors( {X(0)}, {{C(0), 2}}, {boost::make_shared(X(0), I_3x3, Z_3x1), @@ -249,7 +243,6 @@ TEST(HybridGaussianFactorGraph, eliminateFullMultifrontalTwoClique) { hfg.add(GaussianMixtureFactor({X(2)}, {{C(1), 2}}, dt1)); } - // hfg.add(HybridDiscreteFactor(DecisionTreeFactor(c, {2, 8}))); hfg.add(HybridDiscreteFactor( DecisionTreeFactor({{C(1), 2}, {C(2), 2}}, "1 2 3 4"))); @@ -273,26 +266,36 @@ TEST(HybridGaussianFactorGraph, eliminateFullMultifrontalTwoClique) { auto ordering_full = Ordering::ColamdConstrainedLast(hfg, {C(0), C(1), C(2), C(3)}); - GTSAM_PRINT(ordering_full); - HybridBayesTree::shared_ptr hbt; HybridGaussianFactorGraph::shared_ptr remaining; std::tie(hbt, remaining) = hfg.eliminatePartialMultifrontal(ordering_full); - GTSAM_PRINT(*hbt); - - GTSAM_PRINT(*remaining); + // GTSAM_PRINT(*hbt); + // GTSAM_PRINT(*remaining); - hbt->dot(std::cout); /* - Explanation: the Junction tree will need to reeliminate to get to the marginal - on X(1), which is not possible because it involves eliminating discrete before - continuous. The solution to this, however, is in Murphy02. TLDR is that this - is 1. expensive and 2. inexact. neverless it is doable. And I believe that we - should do this. + (Fan) Explanation: the Junction tree will need to reeliminate to get to the + marginal on X(1), which is not possible because it involves eliminating + discrete before continuous. The solution to this, however, is in Murphy02. + TLDR is that this is 1. expensive and 2. inexact. nevertheless it is doable. + And I believe that we should do this. */ } +void dotPrint(const HybridGaussianFactorGraph::shared_ptr &hfg, + const HybridBayesTree::shared_ptr &hbt, + const Ordering &ordering) { + DotWriter dw; + dw.positionHints['c'] = 2; + dw.positionHints['x'] = 1; + std::cout << hfg->dot(DefaultKeyFormatter, dw); + std::cout << "\n"; + hbt->dot(std::cout); + + std::cout << "\n"; + std::cout << hfg->eliminateSequential(ordering)->dot(DefaultKeyFormatter, dw); +} + /* ************************************************************************* */ // TODO(fan): make a graph like Varun's paper one TEST(HybridGaussianFactorGraph, Switching) { @@ -326,9 +329,6 @@ TEST(HybridGaussianFactorGraph, Switching) { for (auto &l : lvls) { l = -l; } - std::copy(lvls.begin(), lvls.end(), - std::ostream_iterator(std::cout, ",")); - std::cout << "\n"; } { std::vector naturalC(N - 1); @@ -342,63 +342,19 @@ TEST(HybridGaussianFactorGraph, Switching) { // std::copy(ordC.begin(), ordC.end(), std::back_inserter(ordering)); std::tie(ndC, lvls) = makeBinaryOrdering(ordC); std::copy(ndC.begin(), ndC.end(), std::back_inserter(ordering)); - std::copy(lvls.begin(), lvls.end(), - std::ostream_iterator(std::cout, ",")); } auto ordering_full = Ordering(ordering); - // auto ordering_full = - // Ordering(); - - // for (int i = 1; i <= 9; i++) { - // ordering_full.push_back(X(i)); - // } - - // for (int i = 1; i < 9; i++) { - // ordering_full.push_back(C(i)); - // } - - // auto ordering_full = - // Ordering(KeyVector{X(1), X(4), X(2), X(6), X(9), X(8), X(3), X(7), - // X(5), - // C(1), C(2), C(3), C(4), C(5), C(6), C(7), C(8)}); - // GTSAM_PRINT(*hfg); - GTSAM_PRINT(ordering_full); + // GTSAM_PRINT(ordering_full); HybridBayesTree::shared_ptr hbt; HybridGaussianFactorGraph::shared_ptr remaining; std::tie(hbt, remaining) = hfg->eliminatePartialMultifrontal(ordering_full); // GTSAM_PRINT(*hbt); - // GTSAM_PRINT(*remaining); - - { - DotWriter dw; - dw.positionHints['c'] = 2; - dw.positionHints['x'] = 1; - std::cout << hfg->dot(DefaultKeyFormatter, dw); - std::cout << "\n"; - hbt->dot(std::cout); - } - - { - DotWriter dw; - // dw.positionHints['c'] = 2; - // dw.positionHints['x'] = 1; - std::cout << "\n"; - std::cout << hfg->eliminateSequential(ordering_full) - ->dot(DefaultKeyFormatter, dw); - } - /* - Explanation: the Junction tree will need to reeliminate to get to the marginal - on X(1), which is not possible because it involves eliminating discrete before - continuous. The solution to this, however, is in Murphy02. TLDR is that this - is 1. expensive and 2. inexact. neverless it is doable. And I believe that we - should do this. - */ - hbt->marginalFactor(C(11))->print("HBT: "); + // hbt->marginalFactor(C(11))->print("HBT: "); } /* ************************************************************************* */ @@ -434,9 +390,6 @@ TEST(HybridGaussianFactorGraph, SwitchingISAM) { for (auto &l : lvls) { l = -l; } - std::copy(lvls.begin(), lvls.end(), - std::ostream_iterator(std::cout, ",")); - std::cout << "\n"; } { std::vector naturalC(N - 1); @@ -450,40 +403,16 @@ TEST(HybridGaussianFactorGraph, SwitchingISAM) { // std::copy(ordC.begin(), ordC.end(), std::back_inserter(ordering)); std::tie(ndC, lvls) = makeBinaryOrdering(ordC); std::copy(ndC.begin(), ndC.end(), std::back_inserter(ordering)); - std::copy(lvls.begin(), lvls.end(), - std::ostream_iterator(std::cout, ",")); } auto ordering_full = Ordering(ordering); // GTSAM_PRINT(*hfg); - GTSAM_PRINT(ordering_full); + // GTSAM_PRINT(ordering_full); HybridBayesTree::shared_ptr hbt; HybridGaussianFactorGraph::shared_ptr remaining; std::tie(hbt, remaining) = hfg->eliminatePartialMultifrontal(ordering_full); - // GTSAM_PRINT(*hbt); - - // GTSAM_PRINT(*remaining); - - { - DotWriter dw; - dw.positionHints['c'] = 2; - dw.positionHints['x'] = 1; - std::cout << hfg->dot(DefaultKeyFormatter, dw); - std::cout << "\n"; - hbt->dot(std::cout); - } - - { - DotWriter dw; - // dw.positionHints['c'] = 2; - // dw.positionHints['x'] = 1; - std::cout << "\n"; - std::cout << hfg->eliminateSequential(ordering_full) - ->dot(DefaultKeyFormatter, dw); - } - auto new_fg = makeSwitchingChain(12); auto isam = HybridGaussianISAM(*hbt); @@ -492,13 +421,14 @@ TEST(HybridGaussianFactorGraph, SwitchingISAM) { factorGraph.push_back(new_fg->at(new_fg->size() - 2)); factorGraph.push_back(new_fg->at(new_fg->size() - 1)); isam.update(factorGraph); - std::cout << isam.dot(); - isam.marginalFactor(C(11))->print(); + // std::cout << isam.dot(); + // isam.marginalFactor(C(11))->print(); } } /* ************************************************************************* */ -TEST(HybridGaussianFactorGraph, SwitchingTwoVar) { +// TODO(Varun) Actually test something! +TEST_DISABLED(HybridGaussianFactorGraph, SwitchingTwoVar) { const int N = 7; auto hfg = makeSwitchingChain(N, X); hfg->push_back(*makeSwitchingChain(N, Y, D)); @@ -517,21 +447,6 @@ TEST(HybridGaussianFactorGraph, SwitchingTwoVar) { ordX.emplace_back(Y(i)); } - // { - // KeyVector ndX; - // std::vector lvls; - // std::tie(ndX, lvls) = makeBinaryOrdering(naturalX); - // std::copy(ndX.begin(), ndX.end(), std::back_inserter(ordering)); - // std::copy(lvls.begin(), lvls.end(), - // std::ostream_iterator(std::cout, ",")); - // std::cout << "\n"; - - // for (size_t i = 0; i < N; i++) { - // ordX.emplace_back(X(ndX[i])); - // ordX.emplace_back(Y(ndX[i])); - // } - // } - for (size_t i = 1; i <= N - 1; i++) { ordX.emplace_back(C(i)); } From 374e3cbc7a882c8e8a2f53aa84535ec1fb5fcbd3 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 18:39:10 -0400 Subject: [PATCH 0066/1497] Improved hybrid bayes net and tests --- gtsam/hybrid/HybridBayesNet.cpp | 27 +++++++ gtsam/hybrid/HybridBayesNet.h | 22 ++++++ gtsam/hybrid/tests/testHybridBayesNet.cpp | 92 +++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 gtsam/hybrid/tests/testHybridBayesNet.cpp diff --git a/gtsam/hybrid/HybridBayesNet.cpp b/gtsam/hybrid/HybridBayesNet.cpp index 1292711d89..b3df73bf20 100644 --- a/gtsam/hybrid/HybridBayesNet.cpp +++ b/gtsam/hybrid/HybridBayesNet.cpp @@ -10,7 +10,34 @@ * @file HybridBayesNet.cpp * @brief A bayes net of Gaussian Conditionals indexed by discrete keys. * @author Fan Jiang + * @author Varun Agrawal * @date January 2022 */ #include + +namespace gtsam { + +/* ************************************************************************* */ +GaussianMixture::shared_ptr HybridBayesNet::atGaussian(size_t i) const { + return boost::dynamic_pointer_cast(factors_.at(i)->inner()); +} + +/* ************************************************************************* */ +DiscreteConditional::shared_ptr HybridBayesNet::atDiscrete(size_t i) const { + return boost::dynamic_pointer_cast( + factors_.at(i)->inner()); +} + +/* ************************************************************************* */ +GaussianBayesNet HybridBayesNet::choose( + const DiscreteValues &assignment) const { + GaussianBayesNet gbn; + for (size_t idx = 0; idx < size(); idx++) { + GaussianMixture gm = *this->atGaussian(idx); + gbn.push_back(gm(assignment)); + } + return gbn; +} + +} // namespace gtsam diff --git a/gtsam/hybrid/HybridBayesNet.h b/gtsam/hybrid/HybridBayesNet.h index 43eead2801..412b208b93 100644 --- a/gtsam/hybrid/HybridBayesNet.h +++ b/gtsam/hybrid/HybridBayesNet.h @@ -19,6 +19,7 @@ #include #include +#include namespace gtsam { @@ -36,6 +37,27 @@ class GTSAM_EXPORT HybridBayesNet : public BayesNet { /** Construct empty bayes net */ HybridBayesNet() = default; + + /// Add a discrete conditional to the Bayes Net. + void add(const DiscreteKey &key, const std::string &table) { + push_back( + HybridConditional(boost::make_shared(key, table))); + } + + /// Get a specific Gaussian mixture by index `i`. + GaussianMixture::shared_ptr atGaussian(size_t i) const; + + /// Get a specific discrete conditional by index `i`. + DiscreteConditional::shared_ptr atDiscrete(size_t i) const; + + /** + * @brief Get the Gaussian Bayes Net which corresponds to a specific discrete + * value assignment. + * + * @param assignment The discrete value assignment for the discrete keys. + * @return GaussianBayesNet + */ + GaussianBayesNet choose(const DiscreteValues &assignment) const; }; } // namespace gtsam diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp new file mode 100644 index 0000000000..34133ab0b3 --- /dev/null +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -0,0 +1,92 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file testHybridBayesNet.cpp + * @brief Unit tests for HybridBayesNet + * @author Varun Agrawal + * @author Fan Jiang + * @author Frank Dellaert + * @date December 2021 + */ + +#include +#include + +// Include for test suite +#include + +using namespace std; +using namespace gtsam; +using noiseModel::Isotropic; +using symbol_shorthand::M; +using symbol_shorthand::X; + +static const DiscreteKey Asia(0, 2); + +/* ****************************************************************************/ +// Test creation +TEST(HybridBayesNet, Creation) { + HybridBayesNet bayesNet; + + bayesNet.add(Asia, "99/1"); + + DiscreteConditional expected(Asia, "99/1"); + + CHECK(bayesNet.atDiscrete(0)); + auto& df = *bayesNet.atDiscrete(0); + EXPECT(df.equals(expected)); +} + +/* ****************************************************************************/ +// Test choosing an assignment of conditionals +TEST(HybridBayesNet, Choose) { + Switching s(4); + + Ordering ordering; + for (auto&& kvp : s.linearizationPoint) { + ordering += kvp.key; + } + + HybridBayesNet::shared_ptr hybridBayesNet; + HybridGaussianFactorGraph::shared_ptr remainingFactorGraph; + std::tie(hybridBayesNet, remainingFactorGraph) = + s.linearizedFactorGraph.eliminatePartialSequential(ordering); + + DiscreteValues assignment; + assignment[M(1)] = 1; + assignment[M(2)] = 1; + assignment[M(3)] = 0; + + GaussianBayesNet gbn = hybridBayesNet->choose(assignment); + + EXPECT_LONGS_EQUAL(4, gbn.size()); + + EXPECT(assert_equal(*(*boost::dynamic_pointer_cast( + hybridBayesNet->atGaussian(0)))(assignment), + *gbn.at(0))); + EXPECT(assert_equal(*(*boost::dynamic_pointer_cast( + hybridBayesNet->atGaussian(1)))(assignment), + *gbn.at(1))); + EXPECT(assert_equal(*(*boost::dynamic_pointer_cast( + hybridBayesNet->atGaussian(2)))(assignment), + *gbn.at(2))); + EXPECT(assert_equal(*(*boost::dynamic_pointer_cast( + hybridBayesNet->atGaussian(3)))(assignment), + *gbn.at(3))); +} + +/* ************************************************************************* */ +int main() { + TestResult tr; + return TestRegistry::runAllTests(tr); +} +/* ************************************************************************* */ \ No newline at end of file From 8d6a225851b5a2751452cedf598c660446b99161 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 18:39:20 -0400 Subject: [PATCH 0067/1497] fix printing --- gtsam/hybrid/GaussianMixtureFactor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/hybrid/GaussianMixtureFactor.h b/gtsam/hybrid/GaussianMixtureFactor.h index 6c90ee6a71..7b7c1899fe 100644 --- a/gtsam/hybrid/GaussianMixtureFactor.h +++ b/gtsam/hybrid/GaussianMixtureFactor.h @@ -108,7 +108,7 @@ class GTSAM_EXPORT GaussianMixtureFactor : public HybridFactor { bool equals(const HybridFactor &lf, double tol = 1e-9) const override; void print( - const std::string &s = "HybridFactor\n", + const std::string &s = "GaussianMixtureFactor\n", const KeyFormatter &formatter = DefaultKeyFormatter) const override; /// @} From 00be610e18ced3a1226a5271a6f1ad275d5c3539 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 18:39:33 -0400 Subject: [PATCH 0068/1497] Add Switching class and make it linear --- gtsam/hybrid/tests/Switching.h | 139 +++++++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 7 deletions(-) diff --git a/gtsam/hybrid/tests/Switching.h b/gtsam/hybrid/tests/Switching.h index c081b8e87e..85c86f64e0 100644 --- a/gtsam/hybrid/tests/Switching.h +++ b/gtsam/hybrid/tests/Switching.h @@ -18,18 +18,136 @@ #include #include +#include #include #include #include #include +#include #pragma once -using gtsam::symbol_shorthand::C; -using gtsam::symbol_shorthand::X; - namespace gtsam { -inline HybridGaussianFactorGraph::shared_ptr makeSwitchingChain( + +using symbol_shorthand::C; +using symbol_shorthand::M; +using symbol_shorthand::X; + +/* ****************************************************************************/ +// Test fixture with switching network. +// TODO(Varun) Currently this is only linear. We need to add nonlinear support +// and then update to +// https://github.com/borglab/gtsam/pull/973/files#diff-58c02b3b197ebf731694946e87762d252e9eaa2f5c6c4ba22d618085b321ca23 +struct Switching { + size_t K; + DiscreteKeys modes; + HybridGaussianFactorGraph linearizedFactorGraph; + Values linearizationPoint; + + using MotionModel = BetweenFactor; + // using MotionMixture = MixtureFactor; + + /// Create with given number of time steps. + Switching(size_t K, double between_sigma = 1.0, double prior_sigma = 0.1) + : K(K) { + // Create DiscreteKeys for binary K modes, modes[0] will not be used. + modes = addDiscreteModes(K); + + // Create hybrid factor graph. + // Add a prior on X(1). + auto prior = boost::make_shared( + X(1), Matrix11::Ones() / prior_sigma, Vector1::Zero()); + linearizedFactorGraph.push_back(prior); + + // Add "motion models". + linearizedFactorGraph = addMotionModels(K); + + // Add measurement factors + for (size_t k = 1; k <= K; k++) { + linearizedFactorGraph.emplace_gaussian( + X(k), Matrix11::Ones() / 0.1, Vector1::Zero()); + } + + // Add "mode chain" + linearizedFactorGraph = addModeChain(linearizedFactorGraph); + + // Create the linearization point. + for (size_t k = 1; k <= K; k++) { + linearizationPoint.insert(X(k), static_cast(k)); + } + } + + /// Create DiscreteKeys for K binary modes. + DiscreteKeys addDiscreteModes(size_t K) { + DiscreteKeys m; + for (size_t k = 0; k <= K; k++) { + m.emplace_back(M(k), 2); + } + return m; + } + + /// Helper function to add motion models for each [k, k+1] interval. + HybridGaussianFactorGraph addMotionModels(size_t K) { + HybridGaussianFactorGraph hgfg; + for (size_t k = 1; k < K; k++) { + auto keys = {X(k), X(k + 1)}; + auto components = motionModels(k); + hgfg.emplace_hybrid(keys, DiscreteKeys{modes[k]}, + components); + } + return hgfg; + } + + // Create motion models for a given time step + static std::vector motionModels( + size_t k, double sigma = 1.0) { + auto noise_model = noiseModel::Isotropic::Sigma(1, sigma); + auto still = boost::make_shared( + X(k), -Matrix11::Ones() / sigma, X(k + 1), + Matrix11::Ones() / sigma, Vector1::Zero()), + moving = boost::make_shared( + X(k), -Matrix11::Ones() / sigma, X(k + 1), + Matrix11::Ones() / sigma, -Vector1::Ones() / sigma); + return {boost::dynamic_pointer_cast(still), + boost::dynamic_pointer_cast(moving)}; + } + + // // Add "mode chain" to NonlinearHybridFactorGraph + // void addModeChain(HybridNonlinearFactorGraph& fg) { + // auto prior = boost::make_shared(modes[1], "1/1"); + // fg.push_discrete(prior); + // for (size_t k = 1; k < K - 1; k++) { + // auto parents = {modes[k]}; + // auto conditional = boost::make_shared( + // modes[k + 1], parents, "1/2 3/2"); + // fg.push_discrete(conditional); + // } + // } + + // Add "mode chain" to GaussianHybridFactorGraph + HybridGaussianFactorGraph addModeChain(HybridGaussianFactorGraph& fg) { + auto prior = boost::make_shared(modes[1], "1/1"); + fg.push_discrete(prior); + for (size_t k = 1; k < K - 1; k++) { + auto parents = {modes[k]}; + auto conditional = boost::make_shared( + modes[k + 1], parents, "1/2 3/2"); + fg.push_discrete(conditional); + } + return fg; + } +}; + +/** + * @brief Create a switching system chain. A switching system is a continuous + * system which depends on a discrete mode at each time step of the chain. + * + * @param n The number of chain elements. + * @param keyFunc The functional to help specify the continuous key. + * @param dKeyFunc The functional to help specify the discrete key. + * @return HybridGaussianFactorGraph::shared_ptr + */ +HybridGaussianFactorGraph::shared_ptr makeSwitchingChain( size_t n, std::function keyFunc = X, std::function dKeyFunc = C) { HybridGaussianFactorGraph hfg; @@ -54,9 +172,16 @@ inline HybridGaussianFactorGraph::shared_ptr makeSwitchingChain( return boost::make_shared(std::move(hfg)); } -inline std::pair> makeBinaryOrdering( - std::vector &input) { +/** + * @brief + * + * @param input The original ordering. + * @return std::pair> + */ +std::pair> makeBinaryOrdering( + std::vector& input) { KeyVector new_order; + std::vector levels(input.size()); std::function::iterator, std::vector::iterator, int)> @@ -79,7 +204,7 @@ inline std::pair> makeBinaryOrdering( bsg(input.begin(), input.end(), 0); std::reverse(new_order.begin(), new_order.end()); - // std::reverse(levels.begin(), levels.end()); + return {new_order, levels}; } From 26e0cef48d04f01ff76d5ec09653a6d41b4f25c8 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 19:56:19 -0400 Subject: [PATCH 0069/1497] fixes --- gtsam/hybrid/HybridBayesNet.h | 3 +++ gtsam/hybrid/HybridFactorGraph.h | 8 -------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/gtsam/hybrid/HybridBayesNet.h b/gtsam/hybrid/HybridBayesNet.h index 412b208b93..7fe19c0ea7 100644 --- a/gtsam/hybrid/HybridBayesNet.h +++ b/gtsam/hybrid/HybridBayesNet.h @@ -38,6 +38,9 @@ class GTSAM_EXPORT HybridBayesNet : public BayesNet { /** Construct empty bayes net */ HybridBayesNet() = default; + /// Add HybridConditional to Bayes Net + using Base::add; + /// Add a discrete conditional to the Bayes Net. void add(const DiscreteKey &key, const std::string &table) { push_back( diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h index ce0241d255..cbbc45590f 100644 --- a/gtsam/hybrid/HybridFactorGraph.h +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -135,14 +135,6 @@ class HybridFactorGraph : public FactorGraph { push_hybrid(p); } } - - /** Constructor from iterator over factors (shared_ptr or plain objects) */ - template - void push_back(ITERATOR firstFactor, ITERATOR lastFactor) { - for (auto&& it = firstFactor; it != lastFactor; it++) { - push_back(*it); - } - } }; } // namespace gtsam \ No newline at end of file From 5bf5d0300697afddac74b898502b5226ff30c085 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 20:13:42 -0400 Subject: [PATCH 0070/1497] local include --- gtsam/hybrid/tests/testHybridBayesNet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index 34133ab0b3..ec6b67d660 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -19,7 +19,8 @@ */ #include -#include + +#include "Switching.h" // Include for test suite #include From 8d359257797d502b76eb6500347515a08602eb15 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 21:04:21 -0400 Subject: [PATCH 0071/1497] make makeBinaryOrdering inline to prevent multiple definition error --- gtsam/hybrid/tests/Switching.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/hybrid/tests/Switching.h b/gtsam/hybrid/tests/Switching.h index 85c86f64e0..76c3da4989 100644 --- a/gtsam/hybrid/tests/Switching.h +++ b/gtsam/hybrid/tests/Switching.h @@ -178,7 +178,7 @@ HybridGaussianFactorGraph::shared_ptr makeSwitchingChain( * @param input The original ordering. * @return std::pair> */ -std::pair> makeBinaryOrdering( +inline std::pair> makeBinaryOrdering( std::vector& input) { KeyVector new_order; From 622ebdd13ba3841317d533dbbd87771fa9bbd910 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jun 2022 22:21:38 -0400 Subject: [PATCH 0072/1497] makeSwitchingChain is also inline --- gtsam/hybrid/tests/Switching.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/hybrid/tests/Switching.h b/gtsam/hybrid/tests/Switching.h index 76c3da4989..545259e481 100644 --- a/gtsam/hybrid/tests/Switching.h +++ b/gtsam/hybrid/tests/Switching.h @@ -147,7 +147,7 @@ struct Switching { * @param dKeyFunc The functional to help specify the discrete key. * @return HybridGaussianFactorGraph::shared_ptr */ -HybridGaussianFactorGraph::shared_ptr makeSwitchingChain( +inline HybridGaussianFactorGraph::shared_ptr makeSwitchingChain( size_t n, std::function keyFunc = X, std::function dKeyFunc = C) { HybridGaussianFactorGraph hfg; From 09d512ae4878b767ac1ac5e674795c4ec83f14e6 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 9 Jun 2022 20:11:30 -0400 Subject: [PATCH 0073/1497] add docstring for makeBinaryOrdering --- gtsam/hybrid/tests/Switching.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtsam/hybrid/tests/Switching.h b/gtsam/hybrid/tests/Switching.h index 545259e481..38a327a580 100644 --- a/gtsam/hybrid/tests/Switching.h +++ b/gtsam/hybrid/tests/Switching.h @@ -173,7 +173,10 @@ inline HybridGaussianFactorGraph::shared_ptr makeSwitchingChain( } /** - * @brief + * @brief Return the ordering as a binary tree such that all parent nodes are + * above their children. + * + * This will result in a nested dissection Bayes tree after elimination. * * @param input The original ordering. * @return std::pair> From 7496f2f43afa11d5431cc09d85694a461db0e1cb Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 10 Jun 2022 04:24:13 -0400 Subject: [PATCH 0074/1497] address review comments --- gtsam/hybrid/HybridGaussianFactorGraph.h | 3 +-- gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gtsam/hybrid/HybridGaussianFactorGraph.h b/gtsam/hybrid/HybridGaussianFactorGraph.h index 1d49904fed..e1cd2dc5f9 100644 --- a/gtsam/hybrid/HybridGaussianFactorGraph.h +++ b/gtsam/hybrid/HybridGaussianFactorGraph.h @@ -134,8 +134,7 @@ class GTSAM_EXPORT HybridGaussianFactorGraph template IsGaussian push_gaussian( const boost::shared_ptr& gaussianFactor) { - Base::Base::push_back( - boost::make_shared(gaussianFactor)); + Base::push_back(boost::make_shared(gaussianFactor)); } /// Construct a factor and add (shared pointer to it) to factor graph. diff --git a/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp b/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp index 9e1a2efdd4..a96aab6b9a 100644 --- a/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp +++ b/gtsam/hybrid/tests/testGaussianHybridFactorGraph.cpp @@ -273,6 +273,7 @@ TEST(HybridGaussianFactorGraph, eliminateFullMultifrontalTwoClique) { // GTSAM_PRINT(*hbt); // GTSAM_PRINT(*remaining); + // hbt->marginalFactor(X(1))->print("HBT: "); /* (Fan) Explanation: the Junction tree will need to reeliminate to get to the marginal on X(1), which is not possible because it involves eliminating From aee494a24f967f652aae6783df95601cf7bab2c2 Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Tue, 14 Jun 2022 17:07:29 -0400 Subject: [PATCH 0075/1497] Expose GNC params to python --- gtsam/nonlinear/GncOptimizer.h | 8 ++++---- gtsam/nonlinear/nonlinear.i | 17 +++++++++++++++++ python/gtsam/preamble/nonlinear.h | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/gtsam/nonlinear/GncOptimizer.h b/gtsam/nonlinear/GncOptimizer.h index cc3fdaf34f..69067a915d 100644 --- a/gtsam/nonlinear/GncOptimizer.h +++ b/gtsam/nonlinear/GncOptimizer.h @@ -246,7 +246,9 @@ class GTSAM_EXPORT GncOptimizer { prev_cost = cost; // display info - if (params_.verbosity >= GncParameters::Verbosity::VALUES) { + if (params_.verbosity >= GncParameters::Verbosity::SUMMARY) { + std::cout << "iter: " << iter << std::endl; + std::cout << "mu: " << mu << std::endl; std::cout << "previous cost: " << prev_cost << std::endl; std::cout << "current cost: " << cost << std::endl; } @@ -255,9 +257,7 @@ class GTSAM_EXPORT GncOptimizer { if (params_.verbosity >= GncParameters::Verbosity::SUMMARY) { std::cout << "final iterations: " << iter << std::endl; std::cout << "final mu: " << mu << std::endl; - std::cout << "final weights: " << weights_ << std::endl; - std::cout << "previous cost: " << prev_cost << std::endl; - std::cout << "current cost: " << cost << std::endl; + std::cout << "final cost: " << cost << std::endl; } return result; } diff --git a/gtsam/nonlinear/nonlinear.i b/gtsam/nonlinear/nonlinear.i index 033e5ced25..21470060c7 100644 --- a/gtsam/nonlinear/nonlinear.i +++ b/gtsam/nonlinear/nonlinear.i @@ -544,11 +544,23 @@ virtual class DoglegParams : gtsam::NonlinearOptimizerParams { }; #include +enum GncLossType { + GM /*Geman McClure*/, + TLS /*Truncated least squares*/ +}; + template virtual class GncParams { GncParams(const PARAMS& baseOptimizerParams); GncParams(); + void setLossType(const GncLossType type); + void setMaxIterations(const size_t maxIter); + void setMuStep(const double step); + void setRelativeCostTol(double value); + void setWeightsTol(double value); void setVerbosityGNC(const This::Verbosity value); + void setKnownInliers(const std::vector& knownIn); + void setKnownOutliers(const std::vector& knownOut); void print(const string& str) const; enum Verbosity { @@ -597,6 +609,11 @@ virtual class GncOptimizer { GncOptimizer(const gtsam::NonlinearFactorGraph& graph, const gtsam::Values& initialValues, const PARAMS& params); + void setInlierCostThresholds(const double inth); + const Vector& getInlierCostThresholds(); + void setInlierCostThresholdsAtProbability(const double alpha); + void setWeights(const Vector w); + const Vector& getWeights(); gtsam::Values optimize(); }; diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index a34e730580..34b864027f 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -9,4 +9,5 @@ * automatic STL binding, such that the raw objects can be accessed in Python. * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. - */ \ No newline at end of file + */ +#include \ No newline at end of file From 91da5209fe5801cc845a05828e676cc045774e2e Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 20 Jun 2022 09:12:42 -0400 Subject: [PATCH 0076/1497] add new lines --- gtsam/hybrid/HybridFactorGraph.h | 2 +- gtsam/hybrid/tests/testHybridBayesNet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h index cbbc45590f..fc730f0c97 100644 --- a/gtsam/hybrid/HybridFactorGraph.h +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -137,4 +137,4 @@ class HybridFactorGraph : public FactorGraph { } }; -} // namespace gtsam \ No newline at end of file +} // namespace gtsam diff --git a/gtsam/hybrid/tests/testHybridBayesNet.cpp b/gtsam/hybrid/tests/testHybridBayesNet.cpp index ec6b67d660..f3db839557 100644 --- a/gtsam/hybrid/tests/testHybridBayesNet.cpp +++ b/gtsam/hybrid/tests/testHybridBayesNet.cpp @@ -90,4 +90,4 @@ int main() { TestResult tr; return TestRegistry::runAllTests(tr); } -/* ************************************************************************* */ \ No newline at end of file +/* ************************************************************************* */ From 8f509dc3264a09a3e4a1fad79cddcc2ac6f79e98 Mon Sep 17 00:00:00 2001 From: Jose Luis Blanco-Claraco Date: Tue, 2 Jun 2020 13:18:46 +0200 Subject: [PATCH 0077/1497] Do not optimize native by default --- cmake/GtsamBuildTypes.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index 9058807adc..33e0c33a00 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -190,8 +190,9 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") endif() if (NOT MSVC) - option(GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" ON) + option(GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" OFF) if(GTSAM_BUILD_WITH_MARCH_NATIVE AND (APPLE AND NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")) + if(GTSAM_BUILD_WITH_MARCH_NATIVE) # Add as public flag so all dependant projects also use it, as required # by Eigen to avid crashes due to SIMD vectorization: list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native") From ea8e69c7353f56ac70396a3340680535c1e95cba Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 7 Jul 2022 11:02:54 -0400 Subject: [PATCH 0078/1497] Use system Eigen by default only if found --- cmake/HandleEigen.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/HandleEigen.cmake b/cmake/HandleEigen.cmake index b21d16885f..c49eb4f8e1 100644 --- a/cmake/HandleEigen.cmake +++ b/cmake/HandleEigen.cmake @@ -1,7 +1,10 @@ ############################################################################### # Option for using system Eigen or GTSAM-bundled Eigen - -option(GTSAM_USE_SYSTEM_EIGEN "Find and use system-installed Eigen. If 'off', use the one bundled with GTSAM" OFF) +# Default: Use system's Eigen if found automatically: +find_package(Eigen3 QUIET) +set(USE_SYSTEM_EIGEN_INITIAL_VALUE ${Eigen3_FOUND}) +option(GTSAM_USE_SYSTEM_EIGEN "Find and use system-installed Eigen. If 'off', use the one bundled with GTSAM" ${USE_SYSTEM_EIGEN_INITIAL_VALUE}) +unset(USE_SYSTEM_EIGEN_INITIAL_VALUE) if(NOT GTSAM_USE_SYSTEM_EIGEN) # This option only makes sense if using the embedded copy of Eigen, it is @@ -11,7 +14,7 @@ endif() # Switch for using system Eigen or GTSAM-bundled Eigen if(GTSAM_USE_SYSTEM_EIGEN) - find_package(Eigen3 REQUIRED) + find_package(Eigen3 REQUIRED) # need to find again as REQUIRED # Use generic Eigen include paths e.g. set(GTSAM_EIGEN_INCLUDE_FOR_INSTALL "${EIGEN3_INCLUDE_DIR}") From 441ec332359f9ca9f136610b2b8eb3fc1308b64f Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 7 Jul 2022 11:09:56 -0400 Subject: [PATCH 0079/1497] fix small issue --- cmake/GtsamBuildTypes.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index 33e0c33a00..e63fbf1dd4 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -192,7 +192,6 @@ endif() if (NOT MSVC) option(GTSAM_BUILD_WITH_MARCH_NATIVE "Enable/Disable building with all instructions supported by native architecture (binary may not be portable!)" OFF) if(GTSAM_BUILD_WITH_MARCH_NATIVE AND (APPLE AND NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")) - if(GTSAM_BUILD_WITH_MARCH_NATIVE) # Add as public flag so all dependant projects also use it, as required # by Eigen to avid crashes due to SIMD vectorization: list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC "-march=native") From c31298d367ba1ae091d2919cfc78f4e3c0213f9d Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 7 Jul 2022 12:31:27 -0400 Subject: [PATCH 0080/1497] Capitalize Identity trait since it is static --- gtsam/base/Group.h | 8 +-- gtsam/base/Lie.h | 2 +- gtsam/base/ProductLieGroup.h | 2 +- gtsam/base/VectorSpace.h | 4 +- gtsam/base/tests/testGroup.cpp | 2 +- gtsam/basis/ParameterMatrix.h | 4 +- gtsam/basis/tests/testParameterMatrix.cpp | 2 +- gtsam/geometry/Cyclic.h | 2 +- gtsam/geometry/PinholeCamera.h | 2 +- gtsam/geometry/PinholePose.h | 2 +- gtsam/geometry/Pose2.h | 2 +- gtsam/geometry/Pose3.h | 2 +- gtsam/geometry/Rot2.h | 4 +- gtsam/geometry/Rot3.h | 2 +- gtsam/geometry/SOn.h | 4 +- gtsam/geometry/Similarity2.cpp | 2 +- gtsam/geometry/Similarity2.h | 2 +- gtsam/geometry/Similarity3.cpp | 2 +- gtsam/geometry/Similarity3.h | 2 +- gtsam/geometry/SphericalCamera.h | 6 +-- gtsam/geometry/StereoPoint2.h | 2 +- gtsam/geometry/geometry.i | 20 +++---- gtsam/geometry/tests/testPose2.cpp | 2 +- gtsam/geometry/tests/testPose3.cpp | 12 ++--- gtsam/geometry/tests/testSimilarity3.cpp | 6 +-- gtsam/navigation/ImuBias.h | 2 +- gtsam/navigation/navigation.i | 2 +- gtsam/nonlinear/tests/testExpression.cpp | 4 +- gtsam/slam/tests/testOrientedPlane3Factor.cpp | 4 +- .../tests/testSmartProjectionRigFactor.cpp | 54 +++++++++---------- .../dynamics/tests/testVelocityConstraint.cpp | 4 +- .../examples/GncPoseAveragingExample.cpp | 2 +- .../examples/ISAM2_SmartFactorStereo_IMU.cpp | 6 +-- gtsam_unstable/geometry/Pose3Upright.h | 2 +- gtsam_unstable/gtsam_unstable.i | 2 +- .../tests/testLocalOrientedPlane3Factor.cpp | 12 ++--- .../slam/tests/testPartialPriorFactor.cpp | 2 +- .../slam/tests/testPoseToPointFactor.cpp | 8 +-- ...martProjectionPoseFactorRollingShutter.cpp | 34 ++++++------ .../tests/testSmartStereoFactor_iSAM2.cpp | 8 +-- .../testSmartStereoProjectionFactorPP.cpp | 14 ++--- tests/testExpressionFactor.cpp | 2 +- tests/testManifold.cpp | 2 +- timing/timeShonanFactor.cpp | 6 +-- 44 files changed, 135 insertions(+), 135 deletions(-) diff --git a/gtsam/base/Group.h b/gtsam/base/Group.h index 39541416ee..89fa8248c1 100644 --- a/gtsam/base/Group.h +++ b/gtsam/base/Group.h @@ -95,7 +95,7 @@ template struct MultiplicativeGroupTraits { typedef group_tag structure_category; typedef multiplicative_group_tag group_flavor; - static Class Identity() { return Class::identity(); } + static Class Identity() { return Class::Identity(); } static Class Compose(const Class &g, const Class & h) { return g * h;} static Class Between(const Class &g, const Class & h) { return g.inverse() * h;} static Class Inverse(const Class &g) { return g.inverse();} @@ -111,7 +111,7 @@ template struct AdditiveGroupTraits { typedef group_tag structure_category; typedef additive_group_tag group_flavor; - static Class Identity() { return Class::identity(); } + static Class Identity() { return Class::Identity(); } static Class Compose(const Class &g, const Class & h) { return g + h;} static Class Between(const Class &g, const Class & h) { return h - g;} static Class Inverse(const Class &g) { return -g;} @@ -147,7 +147,7 @@ class DirectProduct: public std::pair { DirectProduct(const G& g, const H& h):std::pair(g,h) {} // identity - static DirectProduct identity() { return DirectProduct(); } + static DirectProduct Identity() { return DirectProduct(); } DirectProduct operator*(const DirectProduct& other) const { return DirectProduct(traits::Compose(this->first, other.first), @@ -181,7 +181,7 @@ class DirectSum: public std::pair { DirectSum(const G& g, const H& h):std::pair(g,h) {} // identity - static DirectSum identity() { return DirectSum(); } + static DirectSum Identity() { return DirectSum(); } DirectSum operator+(const DirectSum& other) const { return DirectSum(g()+other.g(), h()+other.h()); diff --git a/gtsam/base/Lie.h b/gtsam/base/Lie.h index cb8e7d017e..c4eba5deb8 100644 --- a/gtsam/base/Lie.h +++ b/gtsam/base/Lie.h @@ -177,7 +177,7 @@ struct LieGroupTraits: GetDimensionImpl { /// @name Group /// @{ typedef multiplicative_group_tag group_flavor; - static Class Identity() { return Class::identity();} + static Class Identity() { return Class::Identity();} /// @} /// @name Manifold diff --git a/gtsam/base/ProductLieGroup.h b/gtsam/base/ProductLieGroup.h index a2dcf738e0..6689c11d60 100644 --- a/gtsam/base/ProductLieGroup.h +++ b/gtsam/base/ProductLieGroup.h @@ -48,7 +48,7 @@ class ProductLieGroup: public std::pair { /// @name Group /// @{ typedef multiplicative_group_tag group_flavor; - static ProductLieGroup identity() {return ProductLieGroup();} + static ProductLieGroup Identity() {return ProductLieGroup();} ProductLieGroup operator*(const ProductLieGroup& other) const { return ProductLieGroup(traits::Compose(this->first,other.first), diff --git a/gtsam/base/VectorSpace.h b/gtsam/base/VectorSpace.h index 43644b5c46..f7809f5968 100644 --- a/gtsam/base/VectorSpace.h +++ b/gtsam/base/VectorSpace.h @@ -169,7 +169,7 @@ struct HasVectorSpacePrereqs { Vector v; BOOST_CONCEPT_USAGE(HasVectorSpacePrereqs) { - p = Class::identity(); // identity + p = Class::Identity(); // identity q = p + p; // addition q = p - p; // subtraction v = p.vector(); // conversion to vector @@ -192,7 +192,7 @@ struct VectorSpaceTraits: VectorSpaceImpl { /// @name Group /// @{ typedef additive_group_tag group_flavor; - static Class Identity() { return Class::identity();} + static Class Identity() { return Class::Identity();} /// @} /// @name Manifold diff --git a/gtsam/base/tests/testGroup.cpp b/gtsam/base/tests/testGroup.cpp index 976dee6976..7e8cb7821c 100644 --- a/gtsam/base/tests/testGroup.cpp +++ b/gtsam/base/tests/testGroup.cpp @@ -29,7 +29,7 @@ class Symmetric: private Eigen::PermutationMatrix { Eigen::PermutationMatrix(P) { } public: - static Symmetric identity() { return Symmetric(); } + static Symmetric Identity() { return Symmetric(); } Symmetric() { Eigen::PermutationMatrix::setIdentity(); } diff --git a/gtsam/basis/ParameterMatrix.h b/gtsam/basis/ParameterMatrix.h index eddcbfeaec..3f830ec516 100644 --- a/gtsam/basis/ParameterMatrix.h +++ b/gtsam/basis/ParameterMatrix.h @@ -189,9 +189,9 @@ class ParameterMatrix { * NOTE: The size at compile time is unknown so this identity is zero * length and thus not valid. */ - inline static ParameterMatrix identity() { + inline static ParameterMatrix Identity() { // throw std::runtime_error( - // "ParameterMatrix::identity(): Don't use this function"); + // "ParameterMatrix::Identity(): Don't use this function"); return ParameterMatrix(0); } diff --git a/gtsam/basis/tests/testParameterMatrix.cpp b/gtsam/basis/tests/testParameterMatrix.cpp index ec62e8eeab..ae2e8e1116 100644 --- a/gtsam/basis/tests/testParameterMatrix.cpp +++ b/gtsam/basis/tests/testParameterMatrix.cpp @@ -133,7 +133,7 @@ TEST(ParameterMatrix, VectorSpace) { // vector EXPECT(assert_equal(Vector::Ones(M * N), params.vector())); // identity - EXPECT(assert_equal(ParameterMatrix::identity(), + EXPECT(assert_equal(ParameterMatrix::Identity(), ParameterMatrix(Matrix::Zero(M, 0)))); } diff --git a/gtsam/geometry/Cyclic.h b/gtsam/geometry/Cyclic.h index 065cd01407..a503a6072b 100644 --- a/gtsam/geometry/Cyclic.h +++ b/gtsam/geometry/Cyclic.h @@ -38,7 +38,7 @@ class Cyclic { /// Default constructor yields identity Cyclic():i_(0) { } - static Cyclic identity() { return Cyclic();} + static Cyclic Identity() { return Cyclic();} /// Cast to size_t operator size_t() const { diff --git a/gtsam/geometry/PinholeCamera.h b/gtsam/geometry/PinholeCamera.h index c20e908191..e5a8eec7a1 100644 --- a/gtsam/geometry/PinholeCamera.h +++ b/gtsam/geometry/PinholeCamera.h @@ -213,7 +213,7 @@ class PinholeCamera: public PinholeBaseK { } /// for Canonical - static PinholeCamera identity() { + static PinholeCamera Identity() { return PinholeCamera(); // assumes that the default constructor is valid } diff --git a/gtsam/geometry/PinholePose.h b/gtsam/geometry/PinholePose.h index 7b92be5d50..ce393e45fb 100644 --- a/gtsam/geometry/PinholePose.h +++ b/gtsam/geometry/PinholePose.h @@ -412,7 +412,7 @@ class PinholePose: public PinholeBaseK { } /// for Canonical - static PinholePose identity() { + static PinholePose Identity() { return PinholePose(); // assumes that the default constructor is valid } diff --git a/gtsam/geometry/Pose2.h b/gtsam/geometry/Pose2.h index 466c5a42ad..008e6525d6 100644 --- a/gtsam/geometry/Pose2.h +++ b/gtsam/geometry/Pose2.h @@ -119,7 +119,7 @@ class Pose2: public LieGroup { /// @{ /// identity for group operation - inline static Pose2 identity() { return Pose2(); } + inline static Pose2 Identity() { return Pose2(); } /// inverse GTSAM_EXPORT Pose2 inverse() const; diff --git a/gtsam/geometry/Pose3.h b/gtsam/geometry/Pose3.h index 33fb55250f..6dec7f74fc 100644 --- a/gtsam/geometry/Pose3.h +++ b/gtsam/geometry/Pose3.h @@ -103,7 +103,7 @@ class GTSAM_EXPORT Pose3: public LieGroup { /// @{ /// identity for group operation - static Pose3 identity() { + static Pose3 Identity() { return Pose3(); } diff --git a/gtsam/geometry/Rot2.h b/gtsam/geometry/Rot2.h index 2690ca2481..be8d11cdab 100644 --- a/gtsam/geometry/Rot2.h +++ b/gtsam/geometry/Rot2.h @@ -107,8 +107,8 @@ namespace gtsam { /// @name Group /// @{ - /** identity */ - inline static Rot2 identity() { return Rot2(); } + /** Identity */ + inline static Rot2 Identity() { return Rot2(); } /** The inverse rotation - negative angle */ Rot2 inverse() const { return Rot2(c_, -s_);} diff --git a/gtsam/geometry/Rot3.h b/gtsam/geometry/Rot3.h index 01ca7778c6..800ce4cdf9 100644 --- a/gtsam/geometry/Rot3.h +++ b/gtsam/geometry/Rot3.h @@ -297,7 +297,7 @@ class GTSAM_EXPORT Rot3 : public LieGroup { /// @{ /// identity rotation for group operation - inline static Rot3 identity() { + inline static Rot3 Identity() { return Rot3(); } diff --git a/gtsam/geometry/SOn.h b/gtsam/geometry/SOn.h index af0e7a3cfb..7d1e6db7af 100644 --- a/gtsam/geometry/SOn.h +++ b/gtsam/geometry/SOn.h @@ -178,13 +178,13 @@ class SO : public LieGroup, internal::DimensionSO(N)> { /// SO identity for N >= 2 template > - static SO identity() { + static SO Identity() { return SO(); } /// SO identity for N == Eigen::Dynamic template > - static SO identity(size_t n = 0) { + static SO Identity(size_t n = 0) { return SO(n); } diff --git a/gtsam/geometry/Similarity2.cpp b/gtsam/geometry/Similarity2.cpp index 4ed3351f8b..4b8cfd5818 100644 --- a/gtsam/geometry/Similarity2.cpp +++ b/gtsam/geometry/Similarity2.cpp @@ -134,7 +134,7 @@ void Similarity2::print(const std::string& s) const { << std::endl; } -Similarity2 Similarity2::identity() { return Similarity2(); } +Similarity2 Similarity2::Identity() { return Similarity2(); } Similarity2 Similarity2::operator*(const Similarity2& S) const { return Similarity2(R_ * S.R_, ((1.0 / S.s_) * t_) + R_ * S.t_, s_ * S.s_); diff --git a/gtsam/geometry/Similarity2.h b/gtsam/geometry/Similarity2.h index 05f10d1493..e72cda484c 100644 --- a/gtsam/geometry/Similarity2.h +++ b/gtsam/geometry/Similarity2.h @@ -83,7 +83,7 @@ class GTSAM_EXPORT Similarity2 : public LieGroup { /// @{ /// Return an identity transform - static Similarity2 identity(); + static Similarity2 Identity(); /// Composition Similarity2 operator*(const Similarity2& S) const; diff --git a/gtsam/geometry/Similarity3.cpp b/gtsam/geometry/Similarity3.cpp index 7fde974c55..1461617965 100644 --- a/gtsam/geometry/Similarity3.cpp +++ b/gtsam/geometry/Similarity3.cpp @@ -122,7 +122,7 @@ void Similarity3::print(const std::string& s) const { std::cout << "t: " << translation().transpose() << " s: " << scale() << std::endl; } -Similarity3 Similarity3::identity() { +Similarity3 Similarity3::Identity() { return Similarity3(); } Similarity3 Similarity3::operator*(const Similarity3& S) const { diff --git a/gtsam/geometry/Similarity3.h b/gtsam/geometry/Similarity3.h index 845d4c810d..76d2bf5361 100644 --- a/gtsam/geometry/Similarity3.h +++ b/gtsam/geometry/Similarity3.h @@ -84,7 +84,7 @@ class GTSAM_EXPORT Similarity3 : public LieGroup { /// @{ /// Return an identity transform - static Similarity3 identity(); + static Similarity3 Identity(); /// Composition Similarity3 operator*(const Similarity3& S) const; diff --git a/gtsam/geometry/SphericalCamera.h b/gtsam/geometry/SphericalCamera.h index 4880423d32..adcbe46a5f 100644 --- a/gtsam/geometry/SphericalCamera.h +++ b/gtsam/geometry/SphericalCamera.h @@ -88,7 +88,7 @@ class GTSAM_EXPORT SphericalCamera { /// Default constructor SphericalCamera() - : pose_(Pose3::identity()), emptyCal_(boost::make_shared()) {} + : pose_(Pose3()), emptyCal_(boost::make_shared()) {} /// Constructor with pose explicit SphericalCamera(const Pose3& pose) @@ -198,9 +198,9 @@ class GTSAM_EXPORT SphericalCamera { } /// for Canonical - static SphericalCamera identity() { + static SphericalCamera Identity() { return SphericalCamera( - Pose3::identity()); // assumes that the default constructor is valid + Pose3::Identity()); // assumes that the default constructor is valid } /// for Linear Triangulation diff --git a/gtsam/geometry/StereoPoint2.h b/gtsam/geometry/StereoPoint2.h index 9eef01577d..8c9197fd28 100644 --- a/gtsam/geometry/StereoPoint2.h +++ b/gtsam/geometry/StereoPoint2.h @@ -71,7 +71,7 @@ class GTSAM_EXPORT StereoPoint2 { /// @{ /// identity - inline static StereoPoint2 identity() { + inline static StereoPoint2 Identity() { return StereoPoint2(); } diff --git a/gtsam/geometry/geometry.i b/gtsam/geometry/geometry.i index 92d9ec0a39..a293c6327e 100644 --- a/gtsam/geometry/geometry.i +++ b/gtsam/geometry/geometry.i @@ -16,7 +16,7 @@ class Point2 { bool equals(const gtsam::Point2& point, double tol) const; // Group - static gtsam::Point2 identity(); + static gtsam::Point2 Identity(); // Standard Interface double x() const; @@ -73,7 +73,7 @@ class StereoPoint2 { bool equals(const gtsam::StereoPoint2& point, double tol) const; // Group - static gtsam::StereoPoint2 identity(); + static gtsam::StereoPoint2 Identity(); gtsam::StereoPoint2 inverse() const; gtsam::StereoPoint2 compose(const gtsam::StereoPoint2& p2) const; gtsam::StereoPoint2 between(const gtsam::StereoPoint2& p2) const; @@ -115,7 +115,7 @@ class Point3 { bool equals(const gtsam::Point3& p, double tol) const; // Group - static gtsam::Point3 identity(); + static gtsam::Point3 Identity(); // Standard Interface Vector vector() const; @@ -149,7 +149,7 @@ class Rot2 { bool equals(const gtsam::Rot2& rot, double tol) const; // Group - static gtsam::Rot2 identity(); + static gtsam::Rot2 Identity(); gtsam::Rot2 inverse(); gtsam::Rot2 compose(const gtsam::Rot2& p2) const; gtsam::Rot2 between(const gtsam::Rot2& p2) const; @@ -198,7 +198,7 @@ class SO3 { bool equals(const gtsam::SO3& other, double tol) const; // Group - static gtsam::SO3 identity(); + static gtsam::SO3 Identity(); gtsam::SO3 inverse() const; gtsam::SO3 between(const gtsam::SO3& R) const; gtsam::SO3 compose(const gtsam::SO3& R) const; @@ -228,7 +228,7 @@ class SO4 { bool equals(const gtsam::SO4& other, double tol) const; // Group - static gtsam::SO4 identity(); + static gtsam::SO4 Identity(); gtsam::SO4 inverse() const; gtsam::SO4 between(const gtsam::SO4& Q) const; gtsam::SO4 compose(const gtsam::SO4& Q) const; @@ -258,7 +258,7 @@ class SOn { bool equals(const gtsam::SOn& other, double tol) const; // Group - static gtsam::SOn identity(); + static gtsam::SOn Identity(); gtsam::SOn inverse() const; gtsam::SOn between(const gtsam::SOn& Q) const; gtsam::SOn compose(const gtsam::SOn& Q) const; @@ -322,7 +322,7 @@ class Rot3 { bool equals(const gtsam::Rot3& rot, double tol) const; // Group - static gtsam::Rot3 identity(); + static gtsam::Rot3 Identity(); gtsam::Rot3 inverse() const; gtsam::Rot3 compose(const gtsam::Rot3& p2) const; gtsam::Rot3 between(const gtsam::Rot3& p2) const; @@ -380,7 +380,7 @@ class Pose2 { bool equals(const gtsam::Pose2& pose, double tol) const; // Group - static gtsam::Pose2 identity(); + static gtsam::Pose2 Identity(); gtsam::Pose2 inverse() const; gtsam::Pose2 compose(const gtsam::Pose2& p2) const; gtsam::Pose2 between(const gtsam::Pose2& p2) const; @@ -444,7 +444,7 @@ class Pose3 { bool equals(const gtsam::Pose3& pose, double tol) const; // Group - static gtsam::Pose3 identity(); + static gtsam::Pose3 Identity(); gtsam::Pose3 inverse() const; gtsam::Pose3 inverse(Eigen::Ref H) const; gtsam::Pose3 compose(const gtsam::Pose3& pose) const; diff --git a/gtsam/geometry/tests/testPose2.cpp b/gtsam/geometry/tests/testPose2.cpp index de779cc750..88c00a2e97 100644 --- a/gtsam/geometry/tests/testPose2.cpp +++ b/gtsam/geometry/tests/testPose2.cpp @@ -902,7 +902,7 @@ TEST(Pose2 , TransformCovariance3) { /* ************************************************************************* */ TEST(Pose2, Print) { - Pose2 pose(Rot2::identity(), Point2(1, 2)); + Pose2 pose(Rot2::Identity(), Point2(1, 2)); // Generate the expected output string s = "Planar Pose"; diff --git a/gtsam/geometry/tests/testPose3.cpp b/gtsam/geometry/tests/testPose3.cpp index e1d3d5ea22..78a4af799e 100644 --- a/gtsam/geometry/tests/testPose3.cpp +++ b/gtsam/geometry/tests/testPose3.cpp @@ -1133,7 +1133,7 @@ Pose3 testing_interpolate(const Pose3& t1, const Pose3& t2, double gamma) { retu TEST(Pose3, interpolateJacobians) { { - Pose3 X = Pose3::identity(); + Pose3 X = Pose3::Identity(); Pose3 Y(Rot3::Rz(M_PI_2), Point3(1, 0, 0)); double t = 0.5; Pose3 expectedPoseInterp(Rot3::Rz(M_PI_4), Point3(0.5, -0.207107, 0)); // note: different from test above: this is full Pose3 interpolation @@ -1147,10 +1147,10 @@ TEST(Pose3, interpolateJacobians) { EXPECT(assert_equal(expectedJacobianY,actualJacobianY,1e-6)); } { - Pose3 X = Pose3::identity(); - Pose3 Y(Rot3::identity(), Point3(1, 0, 0)); + Pose3 X = Pose3::Identity(); + Pose3 Y(Rot3::Identity(), Point3(1, 0, 0)); double t = 0.3; - Pose3 expectedPoseInterp(Rot3::identity(), Point3(0.3, 0, 0)); + Pose3 expectedPoseInterp(Rot3::Identity(), Point3(0.3, 0, 0)); Matrix actualJacobianX, actualJacobianY; EXPECT(assert_equal(expectedPoseInterp, interpolate(X, Y, t, actualJacobianX, actualJacobianY), 1e-5)); @@ -1161,7 +1161,7 @@ TEST(Pose3, interpolateJacobians) { EXPECT(assert_equal(expectedJacobianY,actualJacobianY,1e-6)); } { - Pose3 X = Pose3::identity(); + Pose3 X = Pose3::Identity(); Pose3 Y(Rot3::Rz(M_PI_2), Point3(0, 0, 0)); double t = 0.5; Pose3 expectedPoseInterp(Rot3::Rz(M_PI_4), Point3(0, 0, 0)); @@ -1204,7 +1204,7 @@ TEST(Pose3, Create) { /* ************************************************************************* */ TEST(Pose3, Print) { - Pose3 pose(Rot3::identity(), Point3(1, 2, 3)); + Pose3 pose(Rot3::Identity(), Point3(1, 2, 3)); // Generate the expected output std::string expected = "R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\nt: 1 2 3\n"; diff --git a/gtsam/geometry/tests/testSimilarity3.cpp b/gtsam/geometry/tests/testSimilarity3.cpp index 7a134f6efd..fad24f7431 100644 --- a/gtsam/geometry/tests/testSimilarity3.cpp +++ b/gtsam/geometry/tests/testSimilarity3.cpp @@ -203,11 +203,11 @@ TEST(Similarity3, ExpLogMap) { Vector7 zeros; zeros << 0, 0, 0, 0, 0, 0, 0; - Vector7 logIdentity = Similarity3::Logmap(Similarity3::identity()); + Vector7 logIdentity = Similarity3::Logmap(Similarity3::Identity()); EXPECT(assert_equal(zeros, logIdentity)); Similarity3 expZero = Similarity3::Expmap(zeros); - Similarity3 ident = Similarity3::identity(); + Similarity3 ident = Similarity3::Identity(); EXPECT(assert_equal(expZero, ident)); // Compare to matrix exponential, using expm in Lie.h @@ -391,7 +391,7 @@ TEST(Similarity3, Optimization) { NonlinearFactorGraph graph; graph.addPrior(key, prior, model); - // Create initial estimate with identity transform + // Create initial estimate with Identity transform Values initial; initial.insert(key, Similarity3()); diff --git a/gtsam/navigation/ImuBias.h b/gtsam/navigation/ImuBias.h index 9346a4a777..936ae77829 100644 --- a/gtsam/navigation/ImuBias.h +++ b/gtsam/navigation/ImuBias.h @@ -105,7 +105,7 @@ class GTSAM_EXPORT ConstantBias { /// @{ /** identity for group operation */ - static ConstantBias identity() { + static ConstantBias Identity() { return ConstantBias(); } diff --git a/gtsam/navigation/navigation.i b/gtsam/navigation/navigation.i index 6ede1645f3..2477f1288b 100644 --- a/gtsam/navigation/navigation.i +++ b/gtsam/navigation/navigation.i @@ -17,7 +17,7 @@ class ConstantBias { bool equals(const gtsam::imuBias::ConstantBias& expected, double tol) const; // Group - static gtsam::imuBias::ConstantBias identity(); + static gtsam::imuBias::ConstantBias Identity(); // Operator Overloads gtsam::imuBias::ConstantBias operator-() const; diff --git a/gtsam/nonlinear/tests/testExpression.cpp b/gtsam/nonlinear/tests/testExpression.cpp index 92f4998a20..9987cca3f9 100644 --- a/gtsam/nonlinear/tests/testExpression.cpp +++ b/gtsam/nonlinear/tests/testExpression.cpp @@ -122,7 +122,7 @@ class Class : public Point3 { enum {dimension = 3}; using Point3::Point3; const Vector3& vector() const { return *this; } - inline static Class identity() { return Class(0,0,0); } + inline static Class Identity() { return Class(0,0,0); } double norm(OptionalJacobian<1,3> H = boost::none) const { return norm3(*this, H); } @@ -285,7 +285,7 @@ TEST(Expression, compose2) { // Test compose with one arguments referring to constant rotation. TEST(Expression, compose3) { // Create expression - Rot3_ R1(Rot3::identity()), R2(3); + Rot3_ R1(Rot3::Identity()), R2(3); Rot3_ R3 = R1 * R2; // Check keys diff --git a/gtsam/slam/tests/testOrientedPlane3Factor.cpp b/gtsam/slam/tests/testOrientedPlane3Factor.cpp index 35c7504081..502c62c11c 100644 --- a/gtsam/slam/tests/testOrientedPlane3Factor.cpp +++ b/gtsam/slam/tests/testOrientedPlane3Factor.cpp @@ -217,7 +217,7 @@ TEST(OrientedPlane3Factor, Issue561Simplified) { // Setup prior factors // Note: If x0 is too far away from the origin (e.g. x=100) this test can fail. - Pose3 x0(Rot3::identity(), Vector3(10, -1, 1)); + Pose3 x0(Rot3::Identity(), Vector3(10, -1, 1)); auto x0_noise = noiseModel::Isotropic::Sigma(6, 0.01); graph.addPrior(X(0), x0, x0_noise); @@ -241,7 +241,7 @@ TEST(OrientedPlane3Factor, Issue561Simplified) { // Initial values // Just offset the initial pose by 1m. This is what we are trying to optimize. Values initialEstimate; - Pose3 x0_initial = x0.compose(Pose3(Rot3::identity(), Vector3(1,0,0))); + Pose3 x0_initial = x0.compose(Pose3(Rot3::Identity(), Vector3(1,0,0))); initialEstimate.insert(P(1), p1); initialEstimate.insert(P(2), p2); initialEstimate.insert(X(0), x0_initial); diff --git a/gtsam/slam/tests/testSmartProjectionRigFactor.cpp b/gtsam/slam/tests/testSmartProjectionRigFactor.cpp index b4876b27ea..b142b20091 100644 --- a/gtsam/slam/tests/testSmartProjectionRigFactor.cpp +++ b/gtsam/slam/tests/testSmartProjectionRigFactor.cpp @@ -69,7 +69,7 @@ SmartProjectionParams params( TEST(SmartProjectionRigFactor, Constructor) { using namespace vanillaRig; boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); SmartRigFactor::shared_ptr factor1( new SmartRigFactor(model, cameraRig, params)); } @@ -89,7 +89,7 @@ TEST(SmartProjectionRigFactor, Constructor2) { TEST(SmartProjectionRigFactor, Constructor3) { using namespace vanillaRig; boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); SmartRigFactor::shared_ptr factor1( new SmartRigFactor(model, cameraRig, params)); factor1->add(measurement1, x1, cameraId1); @@ -99,7 +99,7 @@ TEST(SmartProjectionRigFactor, Constructor3) { TEST(SmartProjectionRigFactor, Constructor4) { using namespace vanillaRig; boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); SmartProjectionParams params2( gtsam::HESSIAN, gtsam::ZERO_ON_DEGENERACY); // only config that works with rig factors @@ -112,7 +112,7 @@ TEST(SmartProjectionRigFactor, Constructor4) { TEST(SmartProjectionRigFactor, Equals) { using namespace vanillaRig; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); SmartRigFactor::shared_ptr factor1( new SmartRigFactor(model, cameraRig, params)); @@ -140,7 +140,7 @@ TEST(SmartProjectionRigFactor, noiseless) { Point2 level_uv_right = level_camera_right.project(landmark1); boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); SmartRigFactor factor(model, cameraRig, params); factor.add(level_uv, x1); // both taken from the same camera @@ -197,7 +197,7 @@ TEST(SmartProjectionRigFactor, noisy) { using namespace vanillaRig; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); // Project two landmarks into two cameras Point2 pixelError(0.2, 0.2); @@ -323,7 +323,7 @@ TEST(SmartProjectionRigFactor, smartFactorWithMultipleCameras) { Pose3(Rot3::Ypr(-M_PI / 2, 0., -M_PI / 2), Point3(1, 1, 1)); Pose3 body_T_sensor2 = Pose3(Rot3::Ypr(-M_PI / 5, 0., -M_PI / 2), Point3(0, 0, 1)); - Pose3 body_T_sensor3 = Pose3::identity(); + Pose3 body_T_sensor3 = Pose3(); boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig cameraRig->push_back(Camera(body_T_sensor1, sharedK)); @@ -407,7 +407,7 @@ TEST(SmartProjectionRigFactor, 3poses_smart_projection_factor) { Point2Vector measurements_cam1, measurements_cam2, measurements_cam3; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK2)); + cameraRig->push_back(Camera(Pose3(), sharedK2)); // Project three landmarks into three cameras projectToMultipleCameras(cam1, cam2, cam3, landmark1, measurements_cam1); @@ -495,7 +495,7 @@ TEST(SmartProjectionRigFactor, Factors) { FastVector cameraIds{0, 0}; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); SmartRigFactor::shared_ptr smartFactor1 = boost::make_shared( model, cameraRig, params); @@ -578,7 +578,7 @@ TEST(SmartProjectionRigFactor, 3poses_iterative_smart_projection_factor) { // create smart factor boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); FastVector cameraIds{0, 0, 0}; SmartRigFactor::shared_ptr smartFactor1( new SmartRigFactor(model, cameraRig, params)); @@ -646,7 +646,7 @@ TEST(SmartProjectionRigFactor, landmarkDistance) { params.setEnableEPI(false); boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); FastVector cameraIds{0, 0, 0}; SmartRigFactor::shared_ptr smartFactor1( @@ -717,7 +717,7 @@ TEST(SmartProjectionRigFactor, dynamicOutlierRejection) { params.setDynamicOutlierRejectionThreshold(dynamicOutlierRejectionThreshold); boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); FastVector cameraIds{0, 0, 0}; SmartRigFactor::shared_ptr smartFactor1( @@ -783,7 +783,7 @@ TEST(SmartProjectionRigFactor, CheckHessian) { params.setDegeneracyMode(gtsam::ZERO_ON_DEGENERACY); boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); FastVector cameraIds{0, 0, 0}; SmartRigFactor::shared_ptr smartFactor1( @@ -859,7 +859,7 @@ TEST(SmartProjectionRigFactor, Hessian) { measurements_cam1.push_back(cam2_uv1); boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK2)); + cameraRig->push_back(Camera(Pose3(), sharedK2)); FastVector cameraIds{0, 0}; SmartProjectionParams params( @@ -889,7 +889,7 @@ TEST(SmartProjectionRigFactor, Hessian) { TEST(SmartProjectionRigFactor, ConstructorWithCal3Bundler) { using namespace bundlerPose; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedBundlerK)); + cameraRig->push_back(Camera(Pose3(), sharedBundlerK)); SmartProjectionParams params; params.setDegeneracyMode(gtsam::ZERO_ON_DEGENERACY); @@ -917,7 +917,7 @@ TEST(SmartProjectionRigFactor, Cal3Bundler) { KeyVector views{x1, x2, x3}; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedBundlerK)); + cameraRig->push_back(Camera(Pose3(), sharedBundlerK)); FastVector cameraIds{0, 0, 0}; SmartRigFactor::shared_ptr smartFactor1( @@ -988,7 +988,7 @@ TEST(SmartProjectionRigFactor, KeyVector keys{x1, x2, x3, x1}; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); FastVector cameraIds{0, 0, 0, 0}; SmartRigFactor::shared_ptr smartFactor1( @@ -1116,7 +1116,7 @@ TEST(SmartProjectionRigFactor, optimization_3poses_measurementsFromSamePose) { // create inputs KeyVector keys{x1, x2, x3}; boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3(), sharedK)); FastVector cameraIds{0, 0, 0}; FastVector cameraIdsRedundant{0, 0, 0, 0}; @@ -1195,11 +1195,11 @@ TEST(SmartProjectionRigFactor, timing) { // Default cameras for simple derivatives static Cal3_S2::shared_ptr sharedKSimple(new Cal3_S2(100, 100, 0, 0, 0)); - Rot3 R = Rot3::identity(); + Rot3 R = Rot3::Identity(); Pose3 pose1 = Pose3(R, Point3(0, 0, 0)); Pose3 pose2 = Pose3(R, Point3(1, 0, 0)); Camera cam1(pose1, sharedKSimple), cam2(pose2, sharedKSimple); - Pose3 body_P_sensorId = Pose3::identity(); + Pose3 body_P_sensorId = Pose3(); boost::shared_ptr cameraRig(new Cameras()); // single camera in the rig cameraRig->push_back(Camera(body_P_sensorId, sharedKSimple)); @@ -1267,7 +1267,7 @@ TEST(SmartProjectionFactorP, optimization_3poses_sphericalCamera) { keys.push_back(x3); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), emptyK)); + cameraRig->push_back(Camera(Pose3(), emptyK)); SmartProjectionParams params( gtsam::HESSIAN, @@ -1330,10 +1330,10 @@ TEST(SmartProjectionFactorP, optimization_3poses_sphericalCamera) { /* *************************************************************************/ TEST(SmartProjectionFactorP, timing_sphericalCamera) { // create common data - Rot3 R = Rot3::identity(); + Rot3 R = Rot3::Identity(); Pose3 pose1 = Pose3(R, Point3(0, 0, 0)); Pose3 pose2 = Pose3(R, Point3(1, 0, 0)); - Pose3 body_P_sensorId = Pose3::identity(); + Pose3 body_P_sensorId = Pose3(); Point3 landmark1(0, 0, 10); // create spherical data @@ -1423,7 +1423,7 @@ TEST(SmartProjectionFactorP, 2poses_rankTol) { boost::shared_ptr>> cameraRig( new CameraSet>()); // single camera in the rig - cameraRig->push_back(PinholePose(Pose3::identity(), sharedK)); + cameraRig->push_back(PinholePose(Pose3(), sharedK)); SmartRigFactor::shared_ptr smartFactor1( new SmartRigFactor(model, cameraRig, params)); @@ -1461,7 +1461,7 @@ TEST(SmartProjectionFactorP, 2poses_rankTol) { boost::shared_ptr>> cameraRig( new CameraSet>()); // single camera in the rig - cameraRig->push_back(PinholePose(Pose3::identity(), canonicalK)); + cameraRig->push_back(PinholePose(Pose3(), canonicalK)); SmartRigFactor::shared_ptr smartFactor1( new SmartRigFactor(model, cameraRig, params)); @@ -1498,7 +1498,7 @@ TEST(SmartProjectionFactorP, 2poses_rankTol) { boost::shared_ptr>> cameraRig( new CameraSet>()); // single camera in the rig - cameraRig->push_back(PinholePose(Pose3::identity(), canonicalK)); + cameraRig->push_back(PinholePose(Pose3(), canonicalK)); SmartRigFactor::shared_ptr smartFactor1( new SmartRigFactor(model, cameraRig, params)); @@ -1537,7 +1537,7 @@ TEST(SmartProjectionFactorP, 2poses_sphericalCamera_rankTol) { boost::shared_ptr> cameraRig( new CameraSet()); // single camera in the rig - cameraRig->push_back(SphericalCamera(Pose3::identity(), emptyK)); + cameraRig->push_back(SphericalCamera(Pose3(), emptyK)); // TRIANGULATION TEST WITH DEFAULT RANK TOL { // rankTol = 1 or 0.1 gives a degenerate point, which is undesirable for a diff --git a/gtsam_unstable/dynamics/tests/testVelocityConstraint.cpp b/gtsam_unstable/dynamics/tests/testVelocityConstraint.cpp index 6d82061770..b60b2f3ae9 100644 --- a/gtsam_unstable/dynamics/tests/testVelocityConstraint.cpp +++ b/gtsam_unstable/dynamics/tests/testVelocityConstraint.cpp @@ -15,9 +15,9 @@ const Key x1 = 1, x2 = 2; const double dt = 1.0; PoseRTV origin, - pose1(Point3(0.5, 0.0, 0.0), Rot3::identity(), Velocity3(1.0, 0.0, 0.0)), + pose1(Point3(0.5, 0.0, 0.0), Rot3(), Velocity3(1.0, 0.0, 0.0)), pose1a(Point3(0.5, 0.0, 0.0)), - pose2(Point3(1.5, 0.0, 0.0), Rot3::identity(), Velocity3(1.0, 0.0, 0.0)); + pose2(Point3(1.5, 0.0, 0.0), Rot3(), Velocity3(1.0, 0.0, 0.0)); /* ************************************************************************* */ TEST( testVelocityConstraint, trapezoidal ) { diff --git a/gtsam_unstable/examples/GncPoseAveragingExample.cpp b/gtsam_unstable/examples/GncPoseAveragingExample.cpp index ad96934c8b..730d342f07 100644 --- a/gtsam_unstable/examples/GncPoseAveragingExample.cpp +++ b/gtsam_unstable/examples/GncPoseAveragingExample.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv){ normal_distribution normalInliers(0.0, 0.05); Values initial; - initial.insert(0, Pose3::identity()); // identity pose as initialization + initial.insert(0, Pose3()); // identity pose as initialization // create ground truth pose Vector6 poseGtVector; diff --git a/gtsam_unstable/examples/ISAM2_SmartFactorStereo_IMU.cpp b/gtsam_unstable/examples/ISAM2_SmartFactorStereo_IMU.cpp index c0a102d111..16eda23d4a 100644 --- a/gtsam_unstable/examples/ISAM2_SmartFactorStereo_IMU.cpp +++ b/gtsam_unstable/examples/ISAM2_SmartFactorStereo_IMU.cpp @@ -129,8 +129,8 @@ int main(int argc, char* argv[]) { // Pose prior - at identity auto priorPoseNoise = noiseModel::Diagonal::Sigmas( (Vector(6) << Vector3::Constant(0.1), Vector3::Constant(0.1)).finished()); - graph.addPrior(X(1), Pose3::identity(), priorPoseNoise); - initialEstimate.insert(X(0), Pose3::identity()); + graph.addPrior(X(1), Pose3::Identity(), priorPoseNoise); + initialEstimate.insert(X(0), Pose3::Identity()); // Bias prior graph.addPrior(B(1), imu.priorImuBias, @@ -157,7 +157,7 @@ int main(int argc, char* argv[]) { if (frame != lastFrame || in.eof()) { cout << "Running iSAM for frame: " << lastFrame << "\n"; - initialEstimate.insert(X(lastFrame), Pose3::identity()); + initialEstimate.insert(X(lastFrame), Pose3::Identity()); initialEstimate.insert(V(lastFrame), Vector3(0, 0, 0)); initialEstimate.insert(B(lastFrame), imu.prevBias); diff --git a/gtsam_unstable/geometry/Pose3Upright.h b/gtsam_unstable/geometry/Pose3Upright.h index d833c9cf46..037a6cc9da 100644 --- a/gtsam_unstable/geometry/Pose3Upright.h +++ b/gtsam_unstable/geometry/Pose3Upright.h @@ -95,7 +95,7 @@ class GTSAM_UNSTABLE_EXPORT Pose3Upright { /// @{ /// identity for group operation - static Pose3Upright identity() { return Pose3Upright(); } + static Pose3Upright Identity() { return Pose3Upright(); } /// inverse transformation with derivatives Pose3Upright inverse(boost::optional H1=boost::none) const; diff --git a/gtsam_unstable/gtsam_unstable.i b/gtsam_unstable/gtsam_unstable.i index 08cd45e186..c6dbd4ab62 100644 --- a/gtsam_unstable/gtsam_unstable.i +++ b/gtsam_unstable/gtsam_unstable.i @@ -130,7 +130,7 @@ class Pose3Upright { gtsam::Pose3Upright retract(Vector v) const; Vector localCoordinates(const gtsam::Pose3Upright& p2) const; - static gtsam::Pose3Upright identity(); + static gtsam::Pose3Upright Identity(); gtsam::Pose3Upright inverse() const; gtsam::Pose3Upright compose(const gtsam::Pose3Upright& p2) const; gtsam::Pose3Upright between(const gtsam::Pose3Upright& p2) const; diff --git a/gtsam_unstable/slam/tests/testLocalOrientedPlane3Factor.cpp b/gtsam_unstable/slam/tests/testLocalOrientedPlane3Factor.cpp index b97d56c7ea..c2b526ecde 100644 --- a/gtsam_unstable/slam/tests/testLocalOrientedPlane3Factor.cpp +++ b/gtsam_unstable/slam/tests/testLocalOrientedPlane3Factor.cpp @@ -44,8 +44,8 @@ TEST(LocalOrientedPlane3Factor, lm_translation_error) { // Init pose and prior. Pose Prior is needed since a single plane measurement // does not fully constrain the pose - Pose3 init_pose = Pose3::identity(); - Pose3 anchor_pose = Pose3::identity(); + Pose3 init_pose = Pose3::Identity(); + Pose3 anchor_pose = Pose3::Identity(); graph.addPrior(X(0), init_pose, noiseModel::Isotropic::Sigma(6, 0.001)); graph.addPrior(X(1), anchor_pose, noiseModel::Isotropic::Sigma(6, 0.001)); @@ -89,7 +89,7 @@ TEST (LocalOrientedPlane3Factor, lm_rotation_error) { // Init pose and prior. Pose Prior is needed since a single plane measurement // does not fully constrain the pose - Pose3 init_pose = Pose3::identity(); + Pose3 init_pose = Pose3::Identity(); graph.addPrior(X(0), init_pose, noiseModel::Isotropic::Sigma(6, 0.001)); // Add two landmark measurements, differing in angle @@ -180,8 +180,8 @@ TEST(LocalOrientedPlane3Factor, Issue561Simplified) { NonlinearFactorGraph graph; // Setup prior factors - Pose3 x0(Rot3::identity(), Vector3(100, 30, 10)); // the "sensor pose" - Pose3 x1(Rot3::identity(), Vector3(90, 40, 5) ); // the "anchor pose" + Pose3 x0(Rot3::Identity(), Vector3(100, 30, 10)); // the "sensor pose" + Pose3 x1(Rot3::Identity(), Vector3(90, 40, 5) ); // the "anchor pose" auto x0_noise = noiseModel::Isotropic::Sigma(6, 0.01); auto x1_noise = noiseModel::Isotropic::Sigma(6, 0.01); @@ -213,7 +213,7 @@ TEST(LocalOrientedPlane3Factor, Issue561Simplified) { // Initial values // Just offset the initial pose by 1m. This is what we are trying to optimize. Values initialEstimate; - Pose3 x0_initial = x0.compose(Pose3(Rot3::identity(), Vector3(1, 0, 0))); + Pose3 x0_initial = x0.compose(Pose3(Rot3::Identity(), Vector3(1, 0, 0))); initialEstimate.insert(P(1), p1_in_x1); initialEstimate.insert(P(2), p2_in_x1); initialEstimate.insert(X(0), x0_initial); diff --git a/gtsam_unstable/slam/tests/testPartialPriorFactor.cpp b/gtsam_unstable/slam/tests/testPartialPriorFactor.cpp index 7ba8a0d04b..615ed13aae 100644 --- a/gtsam_unstable/slam/tests/testPartialPriorFactor.cpp +++ b/gtsam_unstable/slam/tests/testPartialPriorFactor.cpp @@ -173,7 +173,7 @@ TEST(PartialPriorFactor, Constructors3) { /* ************************************************************************* */ TEST(PartialPriorFactor, JacobianAtIdentity3) { Key poseKey(1); - Pose3 measurement = Pose3::identity(); + Pose3 measurement = Pose3::Identity(); SharedNoiseModel model = NM::Isotropic::Sigma(1, 0.25); TestPartialPriorFactor3 factor(poseKey, kIndexTy, measurement.translation().y(), model); diff --git a/gtsam_unstable/slam/tests/testPoseToPointFactor.cpp b/gtsam_unstable/slam/tests/testPoseToPointFactor.cpp index 5aaaaec531..7345e23081 100644 --- a/gtsam_unstable/slam/tests/testPoseToPointFactor.cpp +++ b/gtsam_unstable/slam/tests/testPoseToPointFactor.cpp @@ -16,7 +16,7 @@ using namespace gtsam::noiseModel; /* ************************************************************************* */ // Verify zero error when there is no noise TEST(PoseToPointFactor, errorNoiseless_2D) { - Pose2 pose = Pose2::identity(); + Pose2 pose = Pose2::Identity(); Point2 point(1.0, 2.0); Point2 noise(0.0, 0.0); Point2 measured = point + noise; @@ -33,7 +33,7 @@ TEST(PoseToPointFactor, errorNoiseless_2D) { /* ************************************************************************* */ // Verify expected error in test scenario TEST(PoseToPointFactor, errorNoise_2D) { - Pose2 pose = Pose2::identity(); + Pose2 pose = Pose2::Identity(); Point2 point(1.0, 2.0); Point2 noise(-1.0, 0.5); Point2 measured = point + noise; @@ -86,7 +86,7 @@ TEST(PoseToPointFactor, jacobian_2D) { /* ************************************************************************* */ // Verify zero error when there is no noise TEST(PoseToPointFactor, errorNoiseless_3D) { - Pose3 pose = Pose3::identity(); + Pose3 pose = Pose3::Identity(); Point3 point(1.0, 2.0, 3.0); Point3 noise(0.0, 0.0, 0.0); Point3 measured = point + noise; @@ -103,7 +103,7 @@ TEST(PoseToPointFactor, errorNoiseless_3D) { /* ************************************************************************* */ // Verify expected error in test scenario TEST(PoseToPointFactor, errorNoise_3D) { - Pose3 pose = Pose3::identity(); + Pose3 pose = Pose3::Identity(); Point3 point(1.0, 2.0, 3.0); Point3 noise(-1.0, 0.5, 0.3); Point3 measured = point + noise; diff --git a/gtsam_unstable/slam/tests/testSmartProjectionPoseFactorRollingShutter.cpp b/gtsam_unstable/slam/tests/testSmartProjectionPoseFactorRollingShutter.cpp index b5962d777b..b88a27c6ca 100644 --- a/gtsam_unstable/slam/tests/testSmartProjectionPoseFactorRollingShutter.cpp +++ b/gtsam_unstable/slam/tests/testSmartProjectionPoseFactorRollingShutter.cpp @@ -88,7 +88,7 @@ typedef SmartProjectionPoseFactorRollingShutter> TEST(SmartProjectionPoseFactorRollingShutter, Constructor) { using namespace vanillaPoseRS; boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr factor1( new SmartFactorRS(model, cameraRig, params)); } @@ -97,7 +97,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, Constructor) { TEST(SmartProjectionPoseFactorRollingShutter, Constructor2) { using namespace vanillaPoseRS; boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); params.setRankTolerance(rankTol); SmartFactorRS factor1(model, cameraRig, params); } @@ -106,7 +106,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, Constructor2) { TEST(SmartProjectionPoseFactorRollingShutter, add) { using namespace vanillaPoseRS; boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr factor1( new SmartFactorRS(model, cameraRig, params)); factor1->add(measurement1, x1, x2, interp_factor); @@ -230,7 +230,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, noiselessErrorAndJacobians) { // Project two landmarks into two cameras Point2 level_uv = cam1.project(landmark1); Point2 level_uv_right = cam2.project(landmark1); - Pose3 body_P_sensorId = Pose3::identity(); + Pose3 body_P_sensorId = Pose3::Identity(); boost::shared_ptr cameraRig(new Cameras()); cameraRig->push_back(Camera(body_P_sensorId, sharedK)); @@ -405,7 +405,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, optimization_3poses) { interp_factors.push_back(interp_factor3); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr smartFactor1( new SmartFactorRS(model, cameraRig, params)); @@ -480,7 +480,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, optimization_3poses_multiCam) { boost::shared_ptr cameraRig(new Cameras()); cameraRig->push_back(Camera(body_P_sensor, sharedK)); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr smartFactor1( new SmartFactorRS(model, cameraRig, params)); @@ -633,11 +633,11 @@ TEST(SmartProjectionPoseFactorRollingShutter, hessian_simple_2poses) { // Default cameras for simple derivatives static Cal3_S2::shared_ptr sharedKSimple(new Cal3_S2(100, 100, 0, 0, 0)); - Rot3 R = Rot3::identity(); + Rot3 R = Rot3::Identity(); Pose3 pose1 = Pose3(R, Point3(0, 0, 0)); Pose3 pose2 = Pose3(R, Point3(1, 0, 0)); Camera cam1(pose1, sharedKSimple), cam2(pose2, sharedKSimple); - Pose3 body_P_sensorId = Pose3::identity(); + Pose3 body_P_sensorId = Pose3::Identity(); // one landmarks 1m in front of camera Point3 landmark1(0, 0, 10); @@ -747,7 +747,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, optimization_3poses_EPI) { params.setEnableEPI(true); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS smartFactor1(model, cameraRig, params); smartFactor1.add(measurements_lmk1, key_pairs, interp_factors); @@ -816,7 +816,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, params.setEnableEPI(false); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS smartFactor1(model, cameraRig, params); smartFactor1.add(measurements_lmk1, key_pairs, interp_factors); @@ -894,7 +894,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, params.setEnableEPI(false); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr smartFactor1( new SmartFactorRS(model, cameraRig, params)); @@ -961,7 +961,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, interp_factors.push_back(interp_factor3); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr smartFactor1( new SmartFactorRS(model, cameraRig, params)); @@ -1102,7 +1102,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, interp_factors.push_back(interp_factor1); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr smartFactor1( new SmartFactorRS(model, cameraRig, params)); @@ -1261,7 +1261,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, interp_factors.at(0)); // we readd the first interp factor boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), sharedK)); + cameraRig->push_back(Camera(Pose3::Identity(), sharedK)); SmartFactorRS::shared_ptr smartFactor1( new SmartFactorRS(model, cameraRig, params)); @@ -1331,11 +1331,11 @@ TEST(SmartProjectionPoseFactorRollingShutter, timing) { gtsam::HESSIAN, gtsam::ZERO_ON_DEGENERACY); // only config that works with RS factors - Rot3 R = Rot3::identity(); + Rot3 R = Rot3::Identity(); Pose3 pose1 = Pose3(R, Point3(0, 0, 0)); Pose3 pose2 = Pose3(R, Point3(1, 0, 0)); Camera cam1(pose1, sharedKSimple), cam2(pose2, sharedKSimple); - Pose3 body_P_sensorId = Pose3::identity(); + Pose3 body_P_sensorId = Pose3::Identity(); // one landmarks 1m in front of camera Point3 landmark1(0, 0, 10); @@ -1431,7 +1431,7 @@ TEST(SmartProjectionPoseFactorRollingShutter, params.setRankTolerance(0.1); boost::shared_ptr cameraRig(new Cameras()); - cameraRig->push_back(Camera(Pose3::identity(), emptyK)); + cameraRig->push_back(Camera(Pose3::Identity(), emptyK)); SmartFactorRS_spherical::shared_ptr smartFactor1( new SmartFactorRS_spherical(model, cameraRig, params)); diff --git a/gtsam_unstable/slam/tests/testSmartStereoFactor_iSAM2.cpp b/gtsam_unstable/slam/tests/testSmartStereoFactor_iSAM2.cpp index 107defb4c9..98b18371fc 100644 --- a/gtsam_unstable/slam/tests/testSmartStereoFactor_iSAM2.cpp +++ b/gtsam_unstable/slam/tests/testSmartStereoFactor_iSAM2.cpp @@ -198,10 +198,10 @@ TEST(testISAM2SmartFactor, Stereo_Batch) { // prior, for the first keyframe: if (kf_id == 0) { - batch_graph.addPrior(X(kf_id), Pose3::identity(), priorPoseNoise); + batch_graph.addPrior(X(kf_id), Pose3::Identity(), priorPoseNoise); } - batch_values.insert(X(kf_id), Pose3::identity()); + batch_values.insert(X(kf_id), Pose3::Identity()); } LevenbergMarquardtParams parameters; @@ -267,7 +267,7 @@ TEST(testISAM2SmartFactor, Stereo_iSAM2) { // Storage of smart factors: std::map smartFactors; - Pose3 lastKeyframePose = Pose3::identity(); + Pose3 lastKeyframePose = Pose3::Identity(); // Run one timestep at once: for (const auto &entries : dataset) { @@ -307,7 +307,7 @@ TEST(testISAM2SmartFactor, Stereo_iSAM2) { // prior, for the first keyframe: if (kf_id == 0) { - newFactors.addPrior(X(kf_id), Pose3::identity(), priorPoseNoise); + newFactors.addPrior(X(kf_id), Pose3::Identity(), priorPoseNoise); } // 2) Run iSAM2: diff --git a/gtsam_unstable/slam/tests/testSmartStereoProjectionFactorPP.cpp b/gtsam_unstable/slam/tests/testSmartStereoProjectionFactorPP.cpp index c71c19038d..1dbd256664 100644 --- a/gtsam_unstable/slam/tests/testSmartStereoProjectionFactorPP.cpp +++ b/gtsam_unstable/slam/tests/testSmartStereoProjectionFactorPP.cpp @@ -181,8 +181,8 @@ TEST_UNSAFE( SmartStereoProjectionFactorPP, noiseless_error_identityExtrinsics ) Values values; values.insert(x1, w_Pose_cam1); values.insert(x2, w_Pose_cam2); - values.insert(body_P_cam1_key, Pose3::identity()); - values.insert(body_P_cam2_key, Pose3::identity()); + values.insert(body_P_cam1_key, Pose3::Identity()); + values.insert(body_P_cam2_key, Pose3::Identity()); SmartStereoProjectionFactorPP factor1(model); factor1.add(cam1_uv, x1, body_P_cam1_key, K2); @@ -426,7 +426,7 @@ TEST( SmartStereoProjectionFactorPP, 3poses_optimization_multipleExtrinsics ) { // Values Pose3 body_Pose_cam1 = Pose3(Rot3::Ypr(-M_PI, 1., 0.1),Point3(0, 1, 0)); Pose3 body_Pose_cam2 = Pose3(Rot3::Ypr(-M_PI / 4, 0.1, 1.0),Point3(1, 1, 1)); - Pose3 body_Pose_cam3 = Pose3::identity(); + Pose3 body_Pose_cam3 = Pose3::Identity(); Pose3 w_Pose_body1 = w_Pose_cam1.compose(body_Pose_cam1.inverse()); Pose3 w_Pose_body2 = w_Pose_cam2.compose(body_Pose_cam2.inverse()); Pose3 w_Pose_body3 = w_Pose_cam3.compose(body_Pose_cam3.inverse()); @@ -1147,7 +1147,7 @@ TEST( SmartStereoProjectionFactorPP, landmarkDistance ) { graph.push_back(smartFactor3); graph.addPrior(x1, pose1, noisePrior); graph.addPrior(x2, pose2, noisePrior); - graph.addPrior(body_P_cam_key, Pose3::identity(), noisePrior); + graph.addPrior(body_P_cam_key, Pose3::Identity(), noisePrior); // Pose3 noise_pose = Pose3(Rot3::Ypr(-M_PI/10, 0., -M_PI/10), Point3(0.5,0.1,0.3)); // noise from regular projection factor test below Pose3 noise_pose = Pose3(Rot3::Ypr(-M_PI / 100, 0., -M_PI / 100), @@ -1156,7 +1156,7 @@ TEST( SmartStereoProjectionFactorPP, landmarkDistance ) { values.insert(x1, pose1); values.insert(x2, pose2); values.insert(x3, pose3 * noise_pose); - values.insert(body_P_cam_key, Pose3::identity()); + values.insert(body_P_cam_key, Pose3::Identity()); // All smart factors are disabled and pose should remain where it is Values result; @@ -1245,7 +1245,7 @@ TEST( SmartStereoProjectionFactorPP, dynamicOutlierRejection ) { values.insert(x1, pose1); values.insert(x2, pose2); values.insert(x3, pose3); - values.insert(body_P_cam_key, Pose3::identity()); + values.insert(body_P_cam_key, Pose3::Identity()); EXPECT_DOUBLES_EQUAL(0, smartFactor1->error(values), 1e-9); EXPECT_DOUBLES_EQUAL(0, smartFactor2->error(values), 1e-9); @@ -1267,7 +1267,7 @@ TEST( SmartStereoProjectionFactorPP, dynamicOutlierRejection ) { Values result; LevenbergMarquardtOptimizer optimizer(graph, values, lm_params); result = optimizer.optimize(); - EXPECT(assert_equal(Pose3::identity(), result.at(body_P_cam_key))); + EXPECT(assert_equal(Pose3::Identity(), result.at(body_P_cam_key))); } /* ************************************************************************* */ diff --git a/tests/testExpressionFactor.cpp b/tests/testExpressionFactor.cpp index 6d23144aab..5b27eea4db 100644 --- a/tests/testExpressionFactor.cpp +++ b/tests/testExpressionFactor.cpp @@ -382,7 +382,7 @@ TEST(ExpressionFactor, compose2) { TEST(ExpressionFactor, compose3) { // Create expression - Rot3_ R1(Rot3::identity()), R2(3); + Rot3_ R1(Rot3::Identity()), R2(3); Rot3_ R3 = R1 * R2; // Create factor diff --git a/tests/testManifold.cpp b/tests/testManifold.cpp index ac3a09e369..a05c4b621a 100644 --- a/tests/testManifold.cpp +++ b/tests/testManifold.cpp @@ -139,7 +139,7 @@ TEST(Manifold, DefaultChart) { Vector v3(3); v3 << 1, 1, 1; - Rot3 I = Rot3::identity(); + Rot3 I = Rot3::Identity(); Rot3 R = I.retract(v3); //DefaultChart chart5; EXPECT(assert_equal(v3, traits::Local(I, R))); diff --git a/timing/timeShonanFactor.cpp b/timing/timeShonanFactor.cpp index 207d54a4dc..60dd6f47a7 100644 --- a/timing/timeShonanFactor.cpp +++ b/timing/timeShonanFactor.cpp @@ -62,9 +62,9 @@ int main(int argc, char* argv[]) { // Build graph NonlinearFactorGraph graph; - // graph.add(NonlinearEquality(0, SOn::identity(4))); + // graph.add(NonlinearEquality(0, SOn::Identity(4))); auto priorModel = noiseModel::Isotropic::Sigma(6, 10000); - graph.add(PriorFactor(0, SOn::identity(4), priorModel)); + graph.add(PriorFactor(0, SOn::Identity(4), priorModel)); auto G = boost::make_shared(SOn::VectorizedGenerators(4)); for (const auto &m : measurements) { const auto &keys = m.keys(); @@ -92,7 +92,7 @@ int main(int argc, char* argv[]) { for (size_t i = 0; i < 100; i++) { gttic_(optimize); Values initial; - initial.insert(0, SOn::identity(4)); + initial.insert(0, SOn::Identity(4)); for (size_t j = 1; j < poses.size(); j++) { initial.insert(j, SOn::Random(rng, 4)); } From 4333f9a186f26aa7e181a7c0aced34fb42b5d681 Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Thu, 7 Jul 2022 13:21:54 -0400 Subject: [PATCH 0081/1497] Revert changes to verbosity --- gtsam/nonlinear/GncOptimizer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gtsam/nonlinear/GncOptimizer.h b/gtsam/nonlinear/GncOptimizer.h index 69067a915d..cc3fdaf34f 100644 --- a/gtsam/nonlinear/GncOptimizer.h +++ b/gtsam/nonlinear/GncOptimizer.h @@ -246,9 +246,7 @@ class GTSAM_EXPORT GncOptimizer { prev_cost = cost; // display info - if (params_.verbosity >= GncParameters::Verbosity::SUMMARY) { - std::cout << "iter: " << iter << std::endl; - std::cout << "mu: " << mu << std::endl; + if (params_.verbosity >= GncParameters::Verbosity::VALUES) { std::cout << "previous cost: " << prev_cost << std::endl; std::cout << "current cost: " << cost << std::endl; } @@ -257,7 +255,9 @@ class GTSAM_EXPORT GncOptimizer { if (params_.verbosity >= GncParameters::Verbosity::SUMMARY) { std::cout << "final iterations: " << iter << std::endl; std::cout << "final mu: " << mu << std::endl; - std::cout << "final cost: " << cost << std::endl; + std::cout << "final weights: " << weights_ << std::endl; + std::cout << "previous cost: " << prev_cost << std::endl; + std::cout << "current cost: " << cost << std::endl; } return result; } From 26dd94bdaf554c18c2f9027a6bb04d2a4448a744 Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Fri, 8 Jul 2022 12:33:47 -0400 Subject: [PATCH 0082/1497] Expose remaining attributes, add tests --- gtsam/nonlinear/nonlinear.i | 12 +++- python/gtsam/tests/test_NonlinearOptimizer.py | 60 ++++++++++++++++++- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/gtsam/nonlinear/nonlinear.i b/gtsam/nonlinear/nonlinear.i index 21470060c7..913be1aed1 100644 --- a/gtsam/nonlinear/nonlinear.i +++ b/gtsam/nonlinear/nonlinear.i @@ -553,6 +553,16 @@ template virtual class GncParams { GncParams(const PARAMS& baseOptimizerParams); GncParams(); + BaseOptimizerParameters baseOptimizerParams; + GncLossType lossType; + size_t maxIterations; + double muStep; + double relativeCostTol; + double weightsTol; + Verbosity verbosity; + std::vector knownInliers; + std::vector knownOutliers; + void setLossType(const GncLossType type); void setMaxIterations(const size_t maxIter); void setMuStep(const double step); @@ -561,7 +571,7 @@ virtual class GncParams { void setVerbosityGNC(const This::Verbosity value); void setKnownInliers(const std::vector& knownIn); void setKnownOutliers(const std::vector& knownOut); - void print(const string& str) const; + void print(const string& str = "") const; enum Verbosity { SILENT, diff --git a/python/gtsam/tests/test_NonlinearOptimizer.py b/python/gtsam/tests/test_NonlinearOptimizer.py index 37afd9e1c0..47d41edb24 100644 --- a/python/gtsam/tests/test_NonlinearOptimizer.py +++ b/python/gtsam/tests/test_NonlinearOptimizer.py @@ -16,9 +16,10 @@ import gtsam from gtsam import (DoglegOptimizer, DoglegParams, DummyPreconditionerParameters, - GaussNewtonOptimizer, GaussNewtonParams, GncLMParams, GncLMOptimizer, - LevenbergMarquardtOptimizer, LevenbergMarquardtParams, NonlinearFactorGraph, - Ordering, PCGSolverParameters, Point2, PriorFactorPoint2, Values) + GaussNewtonOptimizer, GaussNewtonParams, GncLMParams, GncLossType, + GncLMOptimizer, LevenbergMarquardtOptimizer, LevenbergMarquardtParams, + NonlinearFactorGraph, Ordering, PCGSolverParameters, Point2, + PriorFactorPoint2, Values) from gtsam.utils.test_case import GtsamTestCase KEY1 = 1 @@ -83,6 +84,59 @@ def test_graduated_non_convexity(self): actual = GncLMOptimizer(self.fg, self.initial_values, gncParams).optimize() self.assertAlmostEqual(0, self.fg.error(actual)) + def test_gnc_params(self): + base_params = LevenbergMarquardtParams() + # Test base params + for base_max_iters in (50, 100): + base_params.setMaxIterations(base_max_iters) + params = GncLMParams(base_params) + self.assertEqual(params.baseOptimizerParams.getMaxIterations(), base_max_iters) + # Test printing + str(params) + # Test each parameter + for loss_type in (GncLossType.TLS, GncLossType.GM): + params.setLossType(loss_type) # Default is TLS + self.assertEqual(params.lossType, loss_type) + for max_iter in (1, 10, 100): + params.setMaxIterations(max_iter) + self.assertEqual(params.maxIterations, max_iter) + for mu_step in (1.1, 1.2, 1.5): + params.setMuStep(mu_step) + self.assertEqual(params.muStep, mu_step) + for rel_cost_tol in (1e-5, 1e-6, 1e-7): + params.setRelativeCostTol(rel_cost_tol) + self.assertEqual(params.relativeCostTol, rel_cost_tol) + for weights_tol in (1e-4, 1e-3, 1e-2): + params.setWeightsTol(weights_tol) + self.assertEqual(params.weightsTol, weights_tol) + for i in (0, 1, 2): + verb = GncLMParams.Verbosity(i) + params.setVerbosityGNC(verb) + self.assertEqual(params.verbosity, verb) + for inl in ([], [10], [0, 100]): + params.setKnownInliers(inl) + self.assertEqual(params.knownInliers, inl) + params.knownInliers = [] + for out in ([], [1], [0, 10]): + params.setKnownInliers(out) + self.assertEqual(params.knownInliers, out) + params.knownInliers = [] + # Test optimizer params + optimizer = GncLMOptimizer(self.fg, self.initial_values, params) + for ict_factor in (0.9, 1.1): + new_ict = ict_factor * optimizer.getInlierCostThresholds() + optimizer.setInlierCostThresholds(new_ict) + self.assertAlmostEqual(optimizer.getInlierCostThresholds(), new_ict) + for w_factor in (0.8, 0.9): + new_weights = w_factor * optimizer.getWeights() + optimizer.setWeights(new_weights) + self.assertAlmostEqual(optimizer.getWeights(), new_weights) + optimizer.setInlierCostThresholdsAtProbability(0.9) + w1 = optimizer.getInlierCostThresholds() + optimizer.setInlierCostThresholdsAtProbability(0.8) + w2 = optimizer.getInlierCostThresholds() + self.assertLess(w2, w1) + def test_iteration_hook(self): # set up iteration hook to track some testable values iteration_count = 0 From 9dd1f8ffaf0112a8ff053ad347157c1382010e47 Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Fri, 8 Jul 2022 16:48:52 -0400 Subject: [PATCH 0083/1497] Adress review comments --- gtsam/nonlinear/GncParams.h | 2 +- gtsam/nonlinear/nonlinear.i | 2 +- python/gtsam/tests/test_NonlinearOptimizer.py | 14 +++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gtsam/nonlinear/GncParams.h b/gtsam/nonlinear/GncParams.h index 086f08acc7..600a909766 100644 --- a/gtsam/nonlinear/GncParams.h +++ b/gtsam/nonlinear/GncParams.h @@ -161,7 +161,7 @@ class GTSAM_EXPORT GncParams { std::cout << "knownInliers: " << knownInliers[i] << "\n"; for (size_t i = 0; i < knownOutliers.size(); i++) std::cout << "knownOutliers: " << knownOutliers[i] << "\n"; - baseOptimizerParams.print(str); + baseOptimizerParams.print("Base optimizer params: "); } }; diff --git a/gtsam/nonlinear/nonlinear.i b/gtsam/nonlinear/nonlinear.i index 913be1aed1..b6d0f31be4 100644 --- a/gtsam/nonlinear/nonlinear.i +++ b/gtsam/nonlinear/nonlinear.i @@ -571,7 +571,7 @@ virtual class GncParams { void setVerbosityGNC(const This::Verbosity value); void setKnownInliers(const std::vector& knownIn); void setKnownOutliers(const std::vector& knownOut); - void print(const string& str = "") const; + void print(const string& str = "GncParams: ") const; enum Verbosity { SILENT, diff --git a/python/gtsam/tests/test_NonlinearOptimizer.py b/python/gtsam/tests/test_NonlinearOptimizer.py index 47d41edb24..3db2bb1961 100644 --- a/python/gtsam/tests/test_NonlinearOptimizer.py +++ b/python/gtsam/tests/test_NonlinearOptimizer.py @@ -91,8 +91,19 @@ def test_gnc_params(self): base_params.setMaxIterations(base_max_iters) params = GncLMParams(base_params) self.assertEqual(params.baseOptimizerParams.getMaxIterations(), base_max_iters) + # Test printing - str(params) + params_str = str(params) + for s in ( + "lossType", + "maxIterations", + "muStep", + "relativeCostTol", + "weightsTol", + "verbosity", + ): + self.assertTrue(s in params_str) + # Test each parameter for loss_type in (GncLossType.TLS, GncLossType.GM): params.setLossType(loss_type) # Default is TLS @@ -121,6 +132,7 @@ def test_gnc_params(self): params.setKnownInliers(out) self.assertEqual(params.knownInliers, out) params.knownInliers = [] + # Test optimizer params optimizer = GncLMOptimizer(self.fg, self.initial_values, params) for ict_factor in (0.9, 1.1): From b4fdda4740c39a78306f9189bab2c80ffedf8ffd Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Fri, 8 Jul 2022 16:49:04 -0400 Subject: [PATCH 0084/1497] Run yapf --- python/gtsam/tests/test_NonlinearOptimizer.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python/gtsam/tests/test_NonlinearOptimizer.py b/python/gtsam/tests/test_NonlinearOptimizer.py index 3db2bb1961..a47c5ad620 100644 --- a/python/gtsam/tests/test_NonlinearOptimizer.py +++ b/python/gtsam/tests/test_NonlinearOptimizer.py @@ -15,11 +15,12 @@ import unittest import gtsam -from gtsam import (DoglegOptimizer, DoglegParams, DummyPreconditionerParameters, - GaussNewtonOptimizer, GaussNewtonParams, GncLMParams, GncLossType, - GncLMOptimizer, LevenbergMarquardtOptimizer, LevenbergMarquardtParams, - NonlinearFactorGraph, Ordering, PCGSolverParameters, Point2, - PriorFactorPoint2, Values) +from gtsam import ( + DoglegOptimizer, DoglegParams, DummyPreconditionerParameters, GaussNewtonOptimizer, + GaussNewtonParams, GncLMParams, GncLossType, GncLMOptimizer, LevenbergMarquardtOptimizer, + LevenbergMarquardtParams, NonlinearFactorGraph, Ordering, PCGSolverParameters, Point2, + PriorFactorPoint2, Values +) from gtsam.utils.test_case import GtsamTestCase KEY1 = 1 @@ -28,7 +29,6 @@ class TestScenario(GtsamTestCase): """Do trivial test with three optimizer variants.""" - def setUp(self): """Set up the optimization problem and ordering""" # create graph @@ -154,11 +154,13 @@ def test_iteration_hook(self): iteration_count = 0 final_error = 0 final_values = None + def iteration_hook(iter, error_before, error_after): nonlocal iteration_count, final_error, final_values iteration_count = iter final_error = error_after final_values = optimizer.values() + # optimize params = LevenbergMarquardtParams.CeresDefaults() params.setOrdering(self.ordering) @@ -170,5 +172,6 @@ def iteration_hook(iter, error_before, error_after): self.assertEqual(self.fg.error(actual), final_error) self.assertEqual(optimizer.iterations(), iteration_count) + if __name__ == "__main__": unittest.main() From 01ea31633654a137ed1cc7f74ffac5c2bec37648 Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Wed, 13 Jul 2022 08:33:09 -0400 Subject: [PATCH 0085/1497] Make vector opaque --- python/gtsam/preamble/nonlinear.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index 34b864027f..b50059a2ed 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -10,4 +10,6 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ -#include \ No newline at end of file +#include + +PYBIND11_MAKE_OPAQUE(std::vector); From e381a7c9d21d7e63d315ace33612cfe46cbd28e9 Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Wed, 13 Jul 2022 23:27:00 -0400 Subject: [PATCH 0086/1497] Revert pybind stl include --- python/gtsam/preamble/nonlinear.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index b50059a2ed..d07a75f6fb 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -10,6 +10,3 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ -#include - -PYBIND11_MAKE_OPAQUE(std::vector); From 809923a6f2e5b6713124f8a0f5f8981a8e8f7d05 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Fri, 15 Jul 2022 23:32:03 -0400 Subject: [PATCH 0087/1497] Start GTSFM's DSF port to C++ --- gtsam/sfm/DsfTrackGenerator.h | 180 +++++++++++++++++++++++++++++ gtsam/sfm/sfm.i | 47 ++++++++ python/CMakeLists.txt | 11 +- python/gtsam/preamble/sfm.h | 5 + python/gtsam/specializations/sfm.h | 6 + 5 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 gtsam/sfm/DsfTrackGenerator.h diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h new file mode 100644 index 0000000000..5a3e6661eb --- /dev/null +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -0,0 +1,180 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file DsfTrackGenerator.h + * @date May 2022 + * @author John Lambert + * @brief Identifies connected components in the keypoint matched graph. + */ + +#pragma once +#include +#include + +#include + +#include +#include +#include +#include +#include + +namespace gtsam { + +typedef DSFMap DSFMapIndexPair; +typedef std::pair ImagePair; +typedef Eigen::MatrixX2i CorrespondenceIndices; // N x 2 array + + +using KeypointCoordinates = Eigen::MatrixX2d; + +struct Keypoints +{ + KeypointCoordinates coordinates; + // typedef'd for Eigen::VectorXd + boost::optional scales; + boost::optional responses; + + Keypoints(const gtsam::KeypointCoordinates& coordinates): coordinates(coordinates) {}; // boost::none +}; + + + + + +// TODO: THIS CLASSNAME IS DUPLICATED in SfmTrack.h, conflicts +// @param camera index +// @param 2d measurement +// Implemented as named tuple, instead of std::pair +struct NamedSfmMeasurement +{ + size_t i; + Point2 uv; + + NamedSfmMeasurement(size_t i, Point2 uv) : i(i), uv(uv) {} +}; + + +class SfmTrack2d +{ + private: + std::vector measurements_; + + public: + void addMeasurement(const NamedSfmMeasurement &m) { + measurements_.emplace_back(m); + } + std::vector measurements() {return measurements_; } + + // @brief Validates the track by checking that no two measurements are from the same camera. + // + // returns boolean result of the validation. + bool validate_unique_cameras() + { + std::vector track_cam_idxs; + for (auto & measurement: measurements_) + { + track_cam_idxs.emplace_back(measurement.i); + } + auto i = std::adjacent_find(track_cam_idxs.begin(), track_cam_idxs.end()); + bool all_cameras_unique = (i == track_cam_idxs.end()); + return all_cameras_unique; + } +}; + +using MatchIndicesMap = std::map; +using KeypointsList = std::vector; +using KeypointsVector = std::vector; // TODO: prefer KeypointsSet? + + +class DsfTrackGenerator +{ + + public: + DsfTrackGenerator() {} + + // Creates a list of tracks from 2d point correspondences. + // + // Creates a disjoint-set forest (DSF) and 2d tracks from pairwise matches. We create a singleton for union-find + // set elements from camera index of a detection and the index of that detection in that camera's keypoint list, + // i.e. (i,k). + std::vector generate_tracks_from_pairwise_matches( + const MatchIndicesMap matches_dict, + const KeypointsList keypoints_list) + { + std::vector track_2d_list; + + // TODO: put these checks into the Keypoints class. + // check to ensure dimensions of coordinates are correct + //dims_valid = all([kps.coordinates.ndim == 2 for kps in keypoints_list]) + //if not dims_valid: + // raise Exception("Dimensions for Keypoint coordinates incorrect. Array needs to be 2D") + + std::cout << "[SfmTrack2d] Starting Union-Find..." << std::endl; + // Generate the DSF to form tracks + DSFMapIndexPair dsf; + + // for DSF finally + // measurement_idxs represented by k's + for (const auto& [pair_idxs, corr_idxs]: matches_dict) { + size_t i1 = pair_idxs.first; + size_t i2 = pair_idxs.second; + for (size_t k = 0; k < corr_idxs.rows(); k++) + { + size_t k1 = corr_idxs(k,0); + size_t k2 = corr_idxs(k,1); + dsf.merge(IndexPair(i1, k1), IndexPair(i2, k2)); + } + } + + std::cout << "[SfmTrack2d] Union-Find Complete" << std::endl; + const std::map > key_sets = dsf.sets(); + + size_t erroneous_track_count = 0; + // create a landmark map: a list of tracks + // Each track will be represented as a list of (camera_idx, measurements) + for (const auto& [set_id, index_pair_set]: key_sets) { + // Initialize track from measurements + SfmTrack2d track_2d; + + for (const auto& index_pair: index_pair_set) + { + // camera_idx is represented by i + // measurement_idx is represented by k + size_t i = index_pair.i(); + size_t k = index_pair.j(); + // add measurement in this track + track_2d.addMeasurement(NamedSfmMeasurement(i, keypoints_list[i].coordinates.row(k))); + } + + // Skip erroneous track that had repeated measurements within the same image + // This is an expected result from an incorrect correspondence slipping through + if (track_2d.validate_unique_cameras()) + { + track_2d_list.emplace_back(track_2d); + } else { + erroneous_track_count += 1; + } + } + + double erroneous_track_pct = key_sets.size() > 0 ? erroneous_track_count / key_sets.size() * 100 : std::nan("1"); + // TODO: restrict decimal places to 2 decimals. + std::cout << "DSF Union-Find: " << erroneous_track_pct; + std::cout << "% of tracks discarded from multiple obs. in a single image." << std::endl; + + // TODO: return the Transitivity failure percentage here. + return track_2d_list; + } +}; + +} // namespace gtsam + diff --git a/gtsam/sfm/sfm.i b/gtsam/sfm/sfm.i index 83bd07b13f..84988f06cc 100644 --- a/gtsam/sfm/sfm.i +++ b/gtsam/sfm/sfm.i @@ -4,6 +4,53 @@ namespace gtsam { +#include +class GtsfmData +{ + GtsfmData(const int numberImages); + void write_points(std::vector& images, const std::string save_dir); + void write_images(std::vector& images, const std::string save_dir); +}; + +#include + +class MatchIndicesMap { + MatchIndicesMap(); + MatchIndicesMap(const gtsam::MatchIndicesMap& other); + + size_t size() const; + bool empty() const; + void clear(); + gtsam::CorrespondenceIndices at(const pair& keypair) const; +}; + + +class KeypointsList { + KeypointsList(); + KeypointsList(const gtsam::KeypointsList& other); + void push_back(const gtsam::Keypoints& keypoints); + size_t size() const; + bool empty() const; + void clear(); + gtsam::Keypoints at(const size_t& index) const; +}; + + +class Keypoints +{ + Keypoints(const gtsam::KeypointCoordinates& coordinates); + gtsam::KeypointCoordinates coordinates; +}; // check if this should be a method + + +class DsfTrackGenerator { + DsfTrackGenerator(); + std::vector generate_tracks_from_pairwise_matches( + const gtsam::MatchIndicesMap matches_dict, + const gtsam::KeypointsList keypoints_list); +}; + + #include #include #include diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index c14f02ddab..91cb75edd8 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -51,7 +51,9 @@ set(ignore gtsam::BinaryMeasurementsUnit3 gtsam::BinaryMeasurementsRot3 gtsam::DiscreteKey - gtsam::KeyPairDoubleMap) + gtsam::KeyPairDoubleMap + gtsam::MatchIndicesMap + gtsam::KeypointsList) set(interface_headers ${PROJECT_SOURCE_DIR}/gtsam/gtsam.i @@ -145,8 +147,11 @@ if(GTSAM_UNSTABLE_BUILD_PYTHON) gtsam::CameraSetCal3Bundler gtsam::CameraSetCal3Unified gtsam::CameraSetCal3Fisheye - gtsam::KeyPairDoubleMap) - + gtsam::KeyPairDoubleMap + gtsam::MatchIndicesMap + gtsam::KeypointsList) + + pybind_wrap(${GTSAM_PYTHON_UNSTABLE_TARGET} # target ${PROJECT_SOURCE_DIR}/gtsam_unstable/gtsam_unstable.i # interface_header "gtsam_unstable.cpp" # generated_cpp diff --git a/python/gtsam/preamble/sfm.h b/python/gtsam/preamble/sfm.h index 8ff0ea82ee..a51e963dd8 100644 --- a/python/gtsam/preamble/sfm.h +++ b/python/gtsam/preamble/sfm.h @@ -24,3 +24,8 @@ PYBIND11_MAKE_OPAQUE( std::vector>); PYBIND11_MAKE_OPAQUE( std::vector>); +PYBIND11_MAKE_OPAQUE( + std::vector); + + +PYBIND11_MAKE_OPAQUE(gtsam::MatchIndicesMap); \ No newline at end of file diff --git a/python/gtsam/specializations/sfm.h b/python/gtsam/specializations/sfm.h index 311b2c59b4..297aee262b 100644 --- a/python/gtsam/specializations/sfm.h +++ b/python/gtsam/specializations/sfm.h @@ -18,6 +18,12 @@ py::bind_vector > >( py::bind_vector > >( m_, "BinaryMeasurementsRot3"); py::bind_map(m_, "KeyPairDoubleMap"); +py::bind_map(m_, "MatchIndicesMap"); + +py::bind_vector< + std::vector >( + m_, "KeypointsList"); + py::bind_vector< std::vector >( From 6e13456db45380bcb99e68e1139e8a9b26b9b4f4 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Fri, 15 Jul 2022 23:35:00 -0400 Subject: [PATCH 0088/1497] Add Python unit test --- gtsam/sfm/DsfTrackGenerator.h | 2 +- python/gtsam/tests/test_DsfTrackGenerator.py | 34 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 python/gtsam/tests/test_DsfTrackGenerator.py diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index 5a3e6661eb..e26d60769f 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -11,7 +11,7 @@ /** * @file DsfTrackGenerator.h - * @date May 2022 + * @date July 2022 * @author John Lambert * @brief Identifies connected components in the keypoint matched graph. */ diff --git a/python/gtsam/tests/test_DsfTrackGenerator.py b/python/gtsam/tests/test_DsfTrackGenerator.py new file mode 100644 index 0000000000..88b12ce3c1 --- /dev/null +++ b/python/gtsam/tests/test_DsfTrackGenerator.py @@ -0,0 +1,34 @@ +""" + +Authors: John Lambert +""" + +import unittest + +import numpy as np + +import gtsam +from gtsam import DsfTrackGenerator, Keypoints, KeypointsList, MatchIndicesMap +from gtsam.utils.test_case import GtsamTestCase + + +class TestDsfTrackGenerator(GtsamTestCase): + """Tests for DsfTrackGenerator.""" + + def test_track_generation(self) -> None: + """ """ + kps_i0 = Keypoints(coordinates=np.array([[0,0],[1,1]])) + kps_i1 = Keypoints(coordinates=np.array([[2,2],[3,3],[4,4]])) + kps_i2 = Keypoints(coordinates=np.array([[5,5],[6,6]])) + + keypoints_list = KeypointsList() + keypoints_list.append(kps_i0) + keypoints_list.append(kps_i1) + keypoints_list.append(kps_i2) + + matches_dict = MatchIndicesMap() + matches_dict[(0,0)] = np.array([[0,0],[1,1]]) + matches_dict[(1,1)] = np.array([[2,2],[3,3],[4,4]]) + import pdb; pdb.set_trace() + + tracks = DsfTrackGenerator.generate_tracks_from_pairwise_matches(matches_dict, keypoints_list) From 629b9cd9555e6e4fd1cd24ace80b90710e1dcb91 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Sat, 16 Jul 2022 00:26:57 -0400 Subject: [PATCH 0089/1497] clean up docstrings --- gtsam/sfm/DsfTrackGenerator.h | 40 ++++++++------------ python/gtsam/tests/test_DsfTrackGenerator.py | 13 ++++--- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index e26d60769f..095faa72b3 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -48,13 +48,9 @@ struct Keypoints }; - - - -// TODO: THIS CLASSNAME IS DUPLICATED in SfmTrack.h, conflicts // @param camera index // @param 2d measurement -// Implemented as named tuple, instead of std::pair +// Implemented as named tuple, instead of std::pair (like SfmMeasurement in SfmTrack.h) struct NamedSfmMeasurement { size_t i; @@ -93,7 +89,7 @@ class SfmTrack2d using MatchIndicesMap = std::map; using KeypointsList = std::vector; -using KeypointsVector = std::vector; // TODO: prefer KeypointsSet? +using KeypointsVector = std::vector; // TODO(johnwlambert): prefer KeypointsSet? class DsfTrackGenerator @@ -113,25 +109,20 @@ class DsfTrackGenerator { std::vector track_2d_list; - // TODO: put these checks into the Keypoints class. - // check to ensure dimensions of coordinates are correct - //dims_valid = all([kps.coordinates.ndim == 2 for kps in keypoints_list]) - //if not dims_valid: - // raise Exception("Dimensions for Keypoint coordinates incorrect. Array needs to be 2D") - std::cout << "[SfmTrack2d] Starting Union-Find..." << std::endl; - // Generate the DSF to form tracks + // Generate the DSF to form tracks. DSFMapIndexPair dsf; - // for DSF finally - // measurement_idxs represented by k's for (const auto& [pair_idxs, corr_idxs]: matches_dict) { + // Image pair is (i1,i2). size_t i1 = pair_idxs.first; size_t i2 = pair_idxs.second; for (size_t k = 0; k < corr_idxs.rows(); k++) { + // Measurement indices are found in a single matrix row, as (k1,k2). size_t k1 = corr_idxs(k,0); size_t k2 = corr_idxs(k,1); + // Unique keys for the DSF are (i,k), representing keypoint index in an image. dsf.merge(IndexPair(i1, k1), IndexPair(i2, k2)); } } @@ -140,24 +131,23 @@ class DsfTrackGenerator const std::map > key_sets = dsf.sets(); size_t erroneous_track_count = 0; - // create a landmark map: a list of tracks - // Each track will be represented as a list of (camera_idx, measurements) + // Create a list of tracks. + // Each track will be represented as a list of (camera_idx, measurements). for (const auto& [set_id, index_pair_set]: key_sets) { - // Initialize track from measurements + // Initialize track from measurements. SfmTrack2d track_2d; for (const auto& index_pair: index_pair_set) { - // camera_idx is represented by i - // measurement_idx is represented by k + // Camera index is represented by i, and measurement index is represented by k. size_t i = index_pair.i(); size_t k = index_pair.j(); - // add measurement in this track + // Add measurement to this track. track_2d.addMeasurement(NamedSfmMeasurement(i, keypoints_list[i].coordinates.row(k))); } - // Skip erroneous track that had repeated measurements within the same image - // This is an expected result from an incorrect correspondence slipping through + // Skip erroneous track that had repeated measurements within the same image. + // This is an expected result from an incorrect correspondence slipping through. if (track_2d.validate_unique_cameras()) { track_2d_list.emplace_back(track_2d); @@ -167,11 +157,11 @@ class DsfTrackGenerator } double erroneous_track_pct = key_sets.size() > 0 ? erroneous_track_count / key_sets.size() * 100 : std::nan("1"); - // TODO: restrict decimal places to 2 decimals. + // TODO(johnwlambert): restrict decimal places to 2 decimals. std::cout << "DSF Union-Find: " << erroneous_track_pct; std::cout << "% of tracks discarded from multiple obs. in a single image." << std::endl; - // TODO: return the Transitivity failure percentage here. + // TODO(johnwlambert): return the Transitivity failure percentage here. return track_2d_list; } }; diff --git a/python/gtsam/tests/test_DsfTrackGenerator.py b/python/gtsam/tests/test_DsfTrackGenerator.py index 88b12ce3c1..5546453a66 100644 --- a/python/gtsam/tests/test_DsfTrackGenerator.py +++ b/python/gtsam/tests/test_DsfTrackGenerator.py @@ -16,19 +16,20 @@ class TestDsfTrackGenerator(GtsamTestCase): """Tests for DsfTrackGenerator.""" def test_track_generation(self) -> None: - """ """ - kps_i0 = Keypoints(coordinates=np.array([[0,0],[1,1]])) - kps_i1 = Keypoints(coordinates=np.array([[2,2],[3,3],[4,4]])) - kps_i2 = Keypoints(coordinates=np.array([[5,5],[6,6]])) + """Ensures that DSF generates two tracks from measurements in 3 images (H=200,W=400).""" + kps_i0 = Keypoints(coordinates=np.array([[10.,20],[30,40]])) + kps_i1 = Keypoints(coordinates=np.array([[50.,60],[70,80],[90,100]])) + kps_i2 = Keypoints(coordinates=np.array([[110.,120],[130,140]])) keypoints_list = KeypointsList() keypoints_list.append(kps_i0) keypoints_list.append(kps_i1) keypoints_list.append(kps_i2) + # For each image pair (i1,i2), we provide a (K,2) matrix of corresponding image indices (k1,k2). matches_dict = MatchIndicesMap() - matches_dict[(0,0)] = np.array([[0,0],[1,1]]) - matches_dict[(1,1)] = np.array([[2,2],[3,3],[4,4]]) + matches_dict[(0,1)] = np.array([[0,0],[1,1]]) + matches_dict[(1,2)] = np.array([[2,0],[1,1]]) import pdb; pdb.set_trace() tracks = DsfTrackGenerator.generate_tracks_from_pairwise_matches(matches_dict, keypoints_list) From 2434d3a41eac380ed3cd6d60e1d3671fb90bbcb6 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Sat, 16 Jul 2022 01:23:54 -0400 Subject: [PATCH 0090/1497] Fix unwrapped SfmTrack2d, and instantiate generator before calling its method --- gtsam/sfm/DsfTrackGenerator.h | 4 ++-- gtsam/sfm/sfm.i | 14 +++++++++++--- python/gtsam/tests/test_DsfTrackGenerator.py | 16 ++++++++-------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index 095faa72b3..619ca40ca8 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -104,8 +104,8 @@ class DsfTrackGenerator // set elements from camera index of a detection and the index of that detection in that camera's keypoint list, // i.e. (i,k). std::vector generate_tracks_from_pairwise_matches( - const MatchIndicesMap matches_dict, - const KeypointsList keypoints_list) + const MatchIndicesMap& matches_dict, + const KeypointsList& keypoints_list) { std::vector track_2d_list; diff --git a/gtsam/sfm/sfm.i b/gtsam/sfm/sfm.i index 84988f06cc..89fc2b2812 100644 --- a/gtsam/sfm/sfm.i +++ b/gtsam/sfm/sfm.i @@ -43,11 +43,19 @@ class Keypoints }; // check if this should be a method +class SfmTrack2d +{ + void addMeasurement(const gtsam::NamedSfmMeasurement &m); + std::vector measurements(); + bool validate_unique_cameras(); +}; + + class DsfTrackGenerator { DsfTrackGenerator(); - std::vector generate_tracks_from_pairwise_matches( - const gtsam::MatchIndicesMap matches_dict, - const gtsam::KeypointsList keypoints_list); + std::vector generate_tracks_from_pairwise_matches( + const gtsam::MatchIndicesMap& matches_dict, + const gtsam::KeypointsList& keypoints_list); }; diff --git a/python/gtsam/tests/test_DsfTrackGenerator.py b/python/gtsam/tests/test_DsfTrackGenerator.py index 5546453a66..51665df7ad 100644 --- a/python/gtsam/tests/test_DsfTrackGenerator.py +++ b/python/gtsam/tests/test_DsfTrackGenerator.py @@ -1,4 +1,4 @@ -""" +"""Unit tests for track generation using a Disjoint Set Forest data structure. Authors: John Lambert """ @@ -17,9 +17,9 @@ class TestDsfTrackGenerator(GtsamTestCase): def test_track_generation(self) -> None: """Ensures that DSF generates two tracks from measurements in 3 images (H=200,W=400).""" - kps_i0 = Keypoints(coordinates=np.array([[10.,20],[30,40]])) - kps_i1 = Keypoints(coordinates=np.array([[50.,60],[70,80],[90,100]])) - kps_i2 = Keypoints(coordinates=np.array([[110.,120],[130,140]])) + kps_i0 = Keypoints(coordinates=np.array([[10.0, 20], [30, 40]])) + kps_i1 = Keypoints(coordinates=np.array([[50.0, 60], [70, 80], [90, 100]])) + kps_i2 = Keypoints(coordinates=np.array([[110.0, 120], [130, 140]])) keypoints_list = KeypointsList() keypoints_list.append(kps_i0) @@ -28,8 +28,8 @@ def test_track_generation(self) -> None: # For each image pair (i1,i2), we provide a (K,2) matrix of corresponding image indices (k1,k2). matches_dict = MatchIndicesMap() - matches_dict[(0,1)] = np.array([[0,0],[1,1]]) - matches_dict[(1,2)] = np.array([[2,0],[1,1]]) - import pdb; pdb.set_trace() + matches_dict[(0, 1)] = np.array([[0, 0], [1, 1]]) + matches_dict[(1, 2)] = np.array([[2, 0], [1, 1]]) - tracks = DsfTrackGenerator.generate_tracks_from_pairwise_matches(matches_dict, keypoints_list) + tracks = DsfTrackGenerator().generate_tracks_from_pairwise_matches(matches_dict, keypoints_list) + print(tracks[0]) From 6e45be3d98ecc9bbd52ebd7be256e021cf01d7a3 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Sat, 16 Jul 2022 16:09:21 -0400 Subject: [PATCH 0091/1497] fix all wrapper issues --- gtsam/sfm/DsfTrackGenerator.h | 16 ++++++++------ gtsam/sfm/sfm.i | 15 ++++++------- python/gtsam/tests/test_DsfTrackGenerator.py | 23 +++++++++++++++++++- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index 619ca40ca8..6483bae97b 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -34,9 +35,10 @@ typedef DSFMap DSFMapIndexPair; typedef std::pair ImagePair; typedef Eigen::MatrixX2i CorrespondenceIndices; // N x 2 array - +//struct Keypoints; using KeypointCoordinates = Eigen::MatrixX2d; + struct Keypoints { KeypointCoordinates coordinates; @@ -47,6 +49,10 @@ struct Keypoints Keypoints(const gtsam::KeypointCoordinates& coordinates): coordinates(coordinates) {}; // boost::none }; +using KeypointsList = std::vector; +using KeypointsVector = std::vector; // TODO(johnwlambert): prefer KeypointsSet? +using MatchIndicesMap = std::map; + // @param camera index // @param 2d measurement @@ -54,9 +60,9 @@ struct Keypoints struct NamedSfmMeasurement { size_t i; - Point2 uv; + gtsam::Point2 uv; - NamedSfmMeasurement(size_t i, Point2 uv) : i(i), uv(uv) {} + NamedSfmMeasurement(size_t i, gtsam::Point2 uv) : i(i), uv(uv) {} }; @@ -87,10 +93,6 @@ class SfmTrack2d } }; -using MatchIndicesMap = std::map; -using KeypointsList = std::vector; -using KeypointsVector = std::vector; // TODO(johnwlambert): prefer KeypointsSet? - class DsfTrackGenerator { diff --git a/gtsam/sfm/sfm.i b/gtsam/sfm/sfm.i index 89fc2b2812..0374d99b3f 100644 --- a/gtsam/sfm/sfm.i +++ b/gtsam/sfm/sfm.i @@ -4,14 +4,6 @@ namespace gtsam { -#include -class GtsfmData -{ - GtsfmData(const int numberImages); - void write_points(std::vector& images, const std::string save_dir); - void write_images(std::vector& images, const std::string save_dir); -}; - #include class MatchIndicesMap { @@ -43,6 +35,13 @@ class Keypoints }; // check if this should be a method +class NamedSfmMeasurement +{ + size_t i; + gtsam::Point2 uv; + NamedSfmMeasurement(size_t i, gtsam::Point2 uv); +}; + class SfmTrack2d { void addMeasurement(const gtsam::NamedSfmMeasurement &m); diff --git a/python/gtsam/tests/test_DsfTrackGenerator.py b/python/gtsam/tests/test_DsfTrackGenerator.py index 51665df7ad..953167dca5 100644 --- a/python/gtsam/tests/test_DsfTrackGenerator.py +++ b/python/gtsam/tests/test_DsfTrackGenerator.py @@ -32,4 +32,25 @@ def test_track_generation(self) -> None: matches_dict[(1, 2)] = np.array([[2, 0], [1, 1]]) tracks = DsfTrackGenerator().generate_tracks_from_pairwise_matches(matches_dict, keypoints_list) - print(tracks[0]) + + assert len(tracks) == 3 + + # Verify track 0. + assert np.allclose(tracks[0].measurements()[0].uv, np.array([10.0, 20.0])) + assert np.allclose(tracks[0].measurements()[1].uv, np.array([50.0, 60.0])) + assert tracks[0].measurements()[0].i, 0 + assert tracks[0].measurements()[1].i, 1 + + # Verify track 1. + assert np.allclose(tracks[1].measurements()[0].uv, np.array([30.0, 40.0])) + assert np.allclose(tracks[1].measurements()[1].uv, np.array([70.0, 80.0])) + assert np.allclose(tracks[1].measurements()[2].uv, np.array([130.0, 140.0])) + assert tracks[1].measurements()[0].i, 0 + assert tracks[1].measurements()[1].i, 1 + assert tracks[1].measurements()[2].i, 2 + + # Verify track 2. + assert np.allclose(tracks[2].measurements()[0].uv, np.array([90.0, 100.0])) + assert np.allclose(tracks[2].measurements()[1].uv, np.array([110.0, 120.0])) + assert tracks[2].measurements()[0].i, 1 + assert tracks[2].measurements()[1].i, 2 From 361e3f601c79c3a467a17392db3e40fb1e9db443 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Sat, 16 Jul 2022 22:29:01 -0400 Subject: [PATCH 0092/1497] Remove C++17 decompositions, and address comments --- gtsam/sfm/DsfTrackGenerator.h | 42 +++++++++++++++----- gtsam/sfm/sfm.i | 2 +- python/gtsam/tests/test_DsfTrackGenerator.py | 18 +++++---- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index 6483bae97b..c67215a91f 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -13,7 +13,7 @@ * @file DsfTrackGenerator.h * @date July 2022 * @author John Lambert - * @brief Identifies connected components in the keypoint matched graph. + * @brief Identifies connected components in the keypoint matches graph. */ #pragma once @@ -66,6 +66,11 @@ struct NamedSfmMeasurement }; +/** + * @brief Track containing 2D measurements associated with a single 3D point. + * Note: Equivalent to gtsam.SfmTrack, but without the 3d measurement. + * This class holds data temporarily before 3D point is initialized. + */ class SfmTrack2d { private: @@ -80,7 +85,7 @@ class SfmTrack2d // @brief Validates the track by checking that no two measurements are from the same camera. // // returns boolean result of the validation. - bool validate_unique_cameras() + bool has_unique_cameras() { std::vector track_cam_idxs; for (auto & measurement: measurements_) @@ -93,18 +98,25 @@ class SfmTrack2d } }; - +/** + * @brief Generates point tracks from connected components in the keypoint matches graph. + */ class DsfTrackGenerator { public: + /** Default constructor. */ DsfTrackGenerator() {} // Creates a list of tracks from 2d point correspondences. // - // Creates a disjoint-set forest (DSF) and 2d tracks from pairwise matches. We create a singleton for union-find - // set elements from camera index of a detection and the index of that detection in that camera's keypoint list, + // Creates a disjoint-set forest (DSF) and 2d tracks from pairwise matches. + // We create a singleton for union-find set elements from camera index of a + // detection and the index of that detection in that camera's keypoint list, // i.e. (i,k). + // @param Map from (i1,i2) image pair indices to (K,2) matrix, for K + // correspondence indices, from each image. + // @param Length-N list of keypoints, for N images/cameras. std::vector generate_tracks_from_pairwise_matches( const MatchIndicesMap& matches_dict, const KeypointsList& keypoints_list) @@ -115,7 +127,10 @@ class DsfTrackGenerator // Generate the DSF to form tracks. DSFMapIndexPair dsf; - for (const auto& [pair_idxs, corr_idxs]: matches_dict) { + for (const auto& kv: matches_dict) { + const auto pair_idxs = kv.first; + const auto corr_idxs = kv.second; + // Image pair is (i1,i2). size_t i1 = pair_idxs.first; size_t i2 = pair_idxs.second; @@ -132,10 +147,16 @@ class DsfTrackGenerator std::cout << "[SfmTrack2d] Union-Find Complete" << std::endl; const std::map > key_sets = dsf.sets(); + // Return immediately if no sets were found. + if (key_sets.empty()) return track_2d_list; + size_t erroneous_track_count = 0; // Create a list of tracks. // Each track will be represented as a list of (camera_idx, measurements). - for (const auto& [set_id, index_pair_set]: key_sets) { + for (const auto& kv: key_sets) { + const auto set_id = kv.first; + const auto index_pair_set = kv.second; + // Initialize track from measurements. SfmTrack2d track_2d; @@ -150,15 +171,16 @@ class DsfTrackGenerator // Skip erroneous track that had repeated measurements within the same image. // This is an expected result from an incorrect correspondence slipping through. - if (track_2d.validate_unique_cameras()) + if (track_2d.has_unique_cameras()) { track_2d_list.emplace_back(track_2d); } else { - erroneous_track_count += 1; + erroneous_track_count++; } } - double erroneous_track_pct = key_sets.size() > 0 ? erroneous_track_count / key_sets.size() * 100 : std::nan("1"); + double erroneous_track_pct = static_cast(erroneous_track_count) + / static_cast(key_sets.size()) * 100; // TODO(johnwlambert): restrict decimal places to 2 decimals. std::cout << "DSF Union-Find: " << erroneous_track_pct; std::cout << "% of tracks discarded from multiple obs. in a single image." << std::endl; diff --git a/gtsam/sfm/sfm.i b/gtsam/sfm/sfm.i index 0374d99b3f..2a683a032c 100644 --- a/gtsam/sfm/sfm.i +++ b/gtsam/sfm/sfm.i @@ -46,7 +46,7 @@ class SfmTrack2d { void addMeasurement(const gtsam::NamedSfmMeasurement &m); std::vector measurements(); - bool validate_unique_cameras(); + bool has_unique_cameras(); }; diff --git a/python/gtsam/tests/test_DsfTrackGenerator.py b/python/gtsam/tests/test_DsfTrackGenerator.py index 953167dca5..cb643bdb93 100644 --- a/python/gtsam/tests/test_DsfTrackGenerator.py +++ b/python/gtsam/tests/test_DsfTrackGenerator.py @@ -16,7 +16,7 @@ class TestDsfTrackGenerator(GtsamTestCase): """Tests for DsfTrackGenerator.""" def test_track_generation(self) -> None: - """Ensures that DSF generates two tracks from measurements in 3 images (H=200,W=400).""" + """Ensures that DSF generates three tracks from measurements in 3 images (H=200,W=400).""" kps_i0 = Keypoints(coordinates=np.array([[10.0, 20], [30, 40]])) kps_i1 = Keypoints(coordinates=np.array([[50.0, 60], [70, 80], [90, 100]])) kps_i2 = Keypoints(coordinates=np.array([[110.0, 120], [130, 140]])) @@ -32,25 +32,27 @@ def test_track_generation(self) -> None: matches_dict[(1, 2)] = np.array([[2, 0], [1, 1]]) tracks = DsfTrackGenerator().generate_tracks_from_pairwise_matches(matches_dict, keypoints_list) + import pdb + pdb.set_trace() assert len(tracks) == 3 # Verify track 0. assert np.allclose(tracks[0].measurements()[0].uv, np.array([10.0, 20.0])) assert np.allclose(tracks[0].measurements()[1].uv, np.array([50.0, 60.0])) - assert tracks[0].measurements()[0].i, 0 - assert tracks[0].measurements()[1].i, 1 + assert tracks[0].measurements()[0].i == 0 + assert tracks[0].measurements()[1].i == 1 # Verify track 1. assert np.allclose(tracks[1].measurements()[0].uv, np.array([30.0, 40.0])) assert np.allclose(tracks[1].measurements()[1].uv, np.array([70.0, 80.0])) assert np.allclose(tracks[1].measurements()[2].uv, np.array([130.0, 140.0])) - assert tracks[1].measurements()[0].i, 0 - assert tracks[1].measurements()[1].i, 1 - assert tracks[1].measurements()[2].i, 2 + assert tracks[1].measurements()[0].i == 0 + assert tracks[1].measurements()[1].i == 1 + assert tracks[1].measurements()[2].i == 2 # Verify track 2. assert np.allclose(tracks[2].measurements()[0].uv, np.array([90.0, 100.0])) assert np.allclose(tracks[2].measurements()[1].uv, np.array([110.0, 120.0])) - assert tracks[2].measurements()[0].i, 1 - assert tracks[2].measurements()[1].i, 2 + assert tracks[2].measurements()[0].i == 1 + assert tracks[2].measurements()[1].i == 2 From 51fb3750e8b82691d0686bddbb1f61934a23238f Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Sun, 17 Jul 2022 00:31:42 -0400 Subject: [PATCH 0093/1497] remove stray breakpoint --- python/gtsam/tests/test_DsfTrackGenerator.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/python/gtsam/tests/test_DsfTrackGenerator.py b/python/gtsam/tests/test_DsfTrackGenerator.py index cb643bdb93..b9ac223973 100644 --- a/python/gtsam/tests/test_DsfTrackGenerator.py +++ b/python/gtsam/tests/test_DsfTrackGenerator.py @@ -32,9 +32,6 @@ def test_track_generation(self) -> None: matches_dict[(1, 2)] = np.array([[2, 0], [1, 1]]) tracks = DsfTrackGenerator().generate_tracks_from_pairwise_matches(matches_dict, keypoints_list) - import pdb - - pdb.set_trace() assert len(tracks) == 3 # Verify track 0. From b60c5e3ab54f303e35e99535d0744d652698efa2 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sun, 17 Jul 2022 16:05:59 -0400 Subject: [PATCH 0094/1497] undo CustomFactor changes --- gtsam/nonlinear/CustomFactor.cpp | 10 ++-------- gtsam/nonlinear/CustomFactor.h | 5 ++--- python/gtsam/tests/test_custom_factor.py | 14 +++++++------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/gtsam/nonlinear/CustomFactor.cpp b/gtsam/nonlinear/CustomFactor.cpp index b8368c4973..4f86bc757d 100644 --- a/gtsam/nonlinear/CustomFactor.cpp +++ b/gtsam/nonlinear/CustomFactor.cpp @@ -44,20 +44,14 @@ Vector CustomFactor::unwhitenedError( * return error * ``` */ - std::pair errorAndJacobian = - this->error_function_(*this, x, H.get_ptr()); + return this->error_function_(*this, x, H.get_ptr()); - Vector error = errorAndJacobian.first; - (*H) = errorAndJacobian.second; - - return error; } else { /* * In this case, we pass the a `nullptr` to pybind, and it will translate to `None` in Python. * Users can check for `None` in their callback to determine if the Jacobian is requested. */ - auto errorAndJacobian = this->error_function_(*this, x, nullptr); - return errorAndJacobian.first; + return this->error_function_(*this, x, nullptr); } } else { return Vector::Zero(this->dim()); diff --git a/gtsam/nonlinear/CustomFactor.h b/gtsam/nonlinear/CustomFactor.h index 6261636b5f..615b5418e8 100644 --- a/gtsam/nonlinear/CustomFactor.h +++ b/gtsam/nonlinear/CustomFactor.h @@ -35,8 +35,7 @@ class CustomFactor; * This is safe because this is passing a const pointer, and pybind11 will maintain the `std::vector` memory layout. * Thus the pointer will never be invalidated. */ -using CustomErrorFunction = std::function( - const CustomFactor &, const Values &, JacobianVector *)>; +using CustomErrorFunction = std::function; /** * @brief Custom factor that takes a std::function as the error @@ -78,7 +77,7 @@ class CustomFactor: public NoiseModelFactor { * Calls the errorFunction closure, which is a std::function object * One can check if a derivative is needed in the errorFunction by checking the length of Jacobian array */ - Vector unwhitenedError(const Values &x, boost::optional&> H = boost::none) const override; + Vector unwhitenedError(const Values &x, boost::optional &> H = boost::none) const override; /** print */ void print(const std::string &s, diff --git a/python/gtsam/tests/test_custom_factor.py b/python/gtsam/tests/test_custom_factor.py index 03e6917f09..a3bb003846 100644 --- a/python/gtsam/tests/test_custom_factor.py +++ b/python/gtsam/tests/test_custom_factor.py @@ -33,7 +33,7 @@ def test_new_keylist(self): def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): """Minimal error function stub""" - return np.array([1, 0, 0]), H + return np.array([1, 0, 0]) noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0], error_func) @@ -46,7 +46,7 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]) -> np.n """Minimal error function with no Jacobian""" key0 = this.keys()[0] error = -v.atPose2(key0).localCoordinates(expected_pose) - return error, H + return error noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0], error_func) @@ -80,7 +80,7 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): result = gT1.between(gT2) H[0] = -result.inverse().AdjointMap() H[1] = np.eye(3) - return error, H + return error noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0, 1], error_func) @@ -103,9 +103,9 @@ def test_printing(self): gT1 = Pose2(1, 2, np.pi / 2) gT2 = Pose2(-1, 4, np.pi) - def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): + def error_func(this: CustomFactor, v: gtsam.Values, _: List[np.ndarray]): """Minimal error function stub""" - return np.array([1, 0, 0]), H + return np.array([1, 0, 0]) noise_model = gtsam.noiseModel.Unit.Create(3) from gtsam.symbol_shorthand import X @@ -143,7 +143,7 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): result = gT1.between(gT2) H[0] = -result.inverse().AdjointMap() H[1] = np.eye(3) - return error, H + return error noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0, 1], error_func) @@ -181,7 +181,7 @@ def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): result = gT1.between(gT2) H[0] = -result.inverse().AdjointMap() H[1] = np.eye(3) - return error, H + return error noise_model = gtsam.noiseModel.Unit.Create(3) cf = CustomFactor(noise_model, [0, 1], error_func) From fc35096a1d833dd1d4bf08fc475f86b10c7d49a8 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Tue, 19 Jul 2022 00:34:20 -0400 Subject: [PATCH 0095/1497] Update style to have bracket on same lines, and autoformat --- gtsam/sfm/DsfTrackGenerator.h | 190 ++++++++++++++++------------------ 1 file changed, 92 insertions(+), 98 deletions(-) diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index c67215a91f..9da588c553 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -17,7 +17,6 @@ */ #pragma once -#include #include #include @@ -39,8 +38,7 @@ typedef Eigen::MatrixX2i CorrespondenceIndices; // N x 2 array using KeypointCoordinates = Eigen::MatrixX2d; -struct Keypoints -{ +struct Keypoints { KeypointCoordinates coordinates; // typedef'd for Eigen::VectorXd boost::optional scales; @@ -57,8 +55,7 @@ using MatchIndicesMap = std::map; // @param camera index // @param 2d measurement // Implemented as named tuple, instead of std::pair (like SfmMeasurement in SfmTrack.h) -struct NamedSfmMeasurement -{ +struct NamedSfmMeasurement { size_t i; gtsam::Point2 uv; @@ -71,16 +68,15 @@ struct NamedSfmMeasurement * Note: Equivalent to gtsam.SfmTrack, but without the 3d measurement. * This class holds data temporarily before 3D point is initialized. */ -class SfmTrack2d -{ - private: - std::vector measurements_; - - public: - void addMeasurement(const NamedSfmMeasurement &m) { - measurements_.emplace_back(m); - } - std::vector measurements() {return measurements_; } +class SfmTrack2d { + private: + std::vector measurements_; + + public: + void addMeasurement(const NamedSfmMeasurement &m) { + measurements_.emplace_back(m); + } + std::vector measurements() {return measurements_; } // @brief Validates the track by checking that no two measurements are from the same camera. // @@ -88,7 +84,7 @@ class SfmTrack2d bool has_unique_cameras() { std::vector track_cam_idxs; - for (auto & measurement: measurements_) + for (auto & measurement : measurements_) { track_cam_idxs.emplace_back(measurement.i); } @@ -101,93 +97,91 @@ class SfmTrack2d /** * @brief Generates point tracks from connected components in the keypoint matches graph. */ -class DsfTrackGenerator -{ - - public: - /** Default constructor. */ - DsfTrackGenerator() {} - - // Creates a list of tracks from 2d point correspondences. - // - // Creates a disjoint-set forest (DSF) and 2d tracks from pairwise matches. - // We create a singleton for union-find set elements from camera index of a - // detection and the index of that detection in that camera's keypoint list, - // i.e. (i,k). - // @param Map from (i1,i2) image pair indices to (K,2) matrix, for K - // correspondence indices, from each image. - // @param Length-N list of keypoints, for N images/cameras. - std::vector generate_tracks_from_pairwise_matches( - const MatchIndicesMap& matches_dict, - const KeypointsList& keypoints_list) - { - std::vector track_2d_list; - - std::cout << "[SfmTrack2d] Starting Union-Find..." << std::endl; - // Generate the DSF to form tracks. - DSFMapIndexPair dsf; - - for (const auto& kv: matches_dict) { - const auto pair_idxs = kv.first; - const auto corr_idxs = kv.second; - - // Image pair is (i1,i2). - size_t i1 = pair_idxs.first; - size_t i2 = pair_idxs.second; - for (size_t k = 0; k < corr_idxs.rows(); k++) - { - // Measurement indices are found in a single matrix row, as (k1,k2). - size_t k1 = corr_idxs(k,0); - size_t k2 = corr_idxs(k,1); - // Unique keys for the DSF are (i,k), representing keypoint index in an image. - dsf.merge(IndexPair(i1, k1), IndexPair(i2, k2)); - } +class DsfTrackGenerator { + + public: + /** Default constructor. */ + DsfTrackGenerator() {} + + // Creates a list of tracks from 2d point correspondences. + // + // Creates a disjoint-set forest (DSF) and 2d tracks from pairwise matches. + // We create a singleton for union-find set elements from camera index of a + // detection and the index of that detection in that camera's keypoint list, + // i.e. (i,k). + // @param Map from (i1,i2) image pair indices to (K,2) matrix, for K + // correspondence indices, from each image. + // @param Length-N list of keypoints, for N images/cameras. + std::vector generate_tracks_from_pairwise_matches( + const MatchIndicesMap& matches_dict, + const KeypointsList& keypoints_list) { + std::vector track_2d_list; + + std::cout << "[SfmTrack2d] Starting Union-Find..." << std::endl; + // Generate the DSF to form tracks. + DSFMapIndexPair dsf; + + for (const auto& kv : matches_dict) { + const auto pair_idxs = kv.first; + const auto corr_idxs = kv.second; + + // Image pair is (i1,i2). + size_t i1 = pair_idxs.first; + size_t i2 = pair_idxs.second; + for (size_t k = 0; k < corr_idxs.rows(); k++) + { + // Measurement indices are found in a single matrix row, as (k1,k2). + size_t k1 = corr_idxs(k, 0); + size_t k2 = corr_idxs(k, 1); + // Unique keys for the DSF are (i,k), representing keypoint index in an image. + dsf.merge(IndexPair(i1, k1), IndexPair(i2, k2)); } + } - std::cout << "[SfmTrack2d] Union-Find Complete" << std::endl; - const std::map > key_sets = dsf.sets(); - - // Return immediately if no sets were found. - if (key_sets.empty()) return track_2d_list; - - size_t erroneous_track_count = 0; - // Create a list of tracks. - // Each track will be represented as a list of (camera_idx, measurements). - for (const auto& kv: key_sets) { - const auto set_id = kv.first; - const auto index_pair_set = kv.second; - - // Initialize track from measurements. - SfmTrack2d track_2d; - - for (const auto& index_pair: index_pair_set) - { - // Camera index is represented by i, and measurement index is represented by k. - size_t i = index_pair.i(); - size_t k = index_pair.j(); - // Add measurement to this track. - track_2d.addMeasurement(NamedSfmMeasurement(i, keypoints_list[i].coordinates.row(k))); - } - - // Skip erroneous track that had repeated measurements within the same image. - // This is an expected result from an incorrect correspondence slipping through. - if (track_2d.has_unique_cameras()) - { - track_2d_list.emplace_back(track_2d); - } else { - erroneous_track_count++; - } + std::cout << "[SfmTrack2d] Union-Find Complete" << std::endl; + const std::map > key_sets = dsf.sets(); + + // Return immediately if no sets were found. + if (key_sets.empty()) return track_2d_list; + + size_t erroneous_track_count = 0; + // Create a list of tracks. + // Each track will be represented as a list of (camera_idx, measurements). + for (const auto& kv : key_sets) { + const auto set_id = kv.first; + const auto index_pair_set = kv.second; + + // Initialize track from measurements. + SfmTrack2d track_2d; + + for (const auto& index_pair : index_pair_set) + { + // Camera index is represented by i, and measurement index is represented by k. + size_t i = index_pair.i(); + size_t k = index_pair.j(); + // Add measurement to this track. + track_2d.addMeasurement(NamedSfmMeasurement(i, keypoints_list[i].coordinates.row(k))); } - double erroneous_track_pct = static_cast(erroneous_track_count) - / static_cast(key_sets.size()) * 100; - // TODO(johnwlambert): restrict decimal places to 2 decimals. - std::cout << "DSF Union-Find: " << erroneous_track_pct; - std::cout << "% of tracks discarded from multiple obs. in a single image." << std::endl; - - // TODO(johnwlambert): return the Transitivity failure percentage here. - return track_2d_list; + // Skip erroneous track that had repeated measurements within the same image. + // This is an expected result from an incorrect correspondence slipping through. + if (track_2d.has_unique_cameras()) + { + track_2d_list.emplace_back(track_2d); + } else { + erroneous_track_count++; + } } + + double erroneous_track_pct = static_cast(erroneous_track_count) + / static_cast(key_sets.size()) * 100; + // TODO(johnwlambert): restrict decimal places to 2 decimals. + std::cout << "DSF Union-Find: " << erroneous_track_pct; + std::cout << "% of tracks discarded from multiple obs. in a single image." << std::endl; + + // TODO(johnwlambert): return the Transitivity failure percentage here. + return track_2d_list; + } }; } // namespace gtsam From d6415deac4329c37c4995270feac0cd3085753f8 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 19 Jul 2022 12:13:20 -0400 Subject: [PATCH 0096/1497] minor updates to sfm.h preamble --- python/gtsam/preamble/sfm.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/python/gtsam/preamble/sfm.h b/python/gtsam/preamble/sfm.h index bce2a750d7..5ba48f1c81 100644 --- a/python/gtsam/preamble/sfm.h +++ b/python/gtsam/preamble/sfm.h @@ -11,12 +11,5 @@ * mutations on Python side will not be reflected on C++. */ -// Including can cause some serious hard-to-debug bugs!!! -// #include -#include - -PYBIND11_MAKE_OPAQUE( - std::vector); - -PYBIND11_MAKE_OPAQUE( - std::vector); +PYBIND11_MAKE_OPAQUE(std::vector); +PYBIND11_MAKE_OPAQUE(std::vector); From 3d3703441c60f49abe93314add486d35efeee623 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 19 Jul 2022 14:08:31 -0400 Subject: [PATCH 0097/1497] wrap custom factor in a separate file --- gtsam/nonlinear/custom.i | 38 +++++++++++++++++++++++++++ matlab/CMakeLists.txt | 1 + python/CMakeLists.txt | 1 + python/gtsam/preamble/custom.h | 12 +++++++++ python/gtsam/preamble/nonlinear.h | 1 + python/gtsam/specializations/custom.h | 12 +++++++++ 6 files changed, 65 insertions(+) create mode 100644 gtsam/nonlinear/custom.i create mode 100644 python/gtsam/preamble/custom.h create mode 100644 python/gtsam/specializations/custom.h diff --git a/gtsam/nonlinear/custom.i b/gtsam/nonlinear/custom.i new file mode 100644 index 0000000000..0d195a91b6 --- /dev/null +++ b/gtsam/nonlinear/custom.i @@ -0,0 +1,38 @@ +//************************************************************************* +// Custom Factor wrapping +//************************************************************************* + +namespace gtsam { + +#include +virtual class CustomFactor : gtsam::NoiseModelFactor { + /* + * Note CustomFactor will not be wrapped for MATLAB, as there is no supporting + * machinery there. This is achieved by adding `gtsam::CustomFactor` to the + * ignore list in `matlab/CMakeLists.txt`. + */ + CustomFactor(); + /* + * Example: + * ``` + * def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): + * + * if not H is None: + * + * H[0] = J1 # 2-d numpy array for a Jacobian block + * H[1] = J2 + * ... + * return error # 1-d numpy array + * + * cf = CustomFactor(noise_model, keys, error_func) + * ``` + */ + CustomFactor(const gtsam::SharedNoiseModel& noiseModel, + const gtsam::KeyVector& keys, + const gtsam::CustomErrorFunction& errorFunction); + + void print(string s = "", + gtsam::KeyFormatter keyFormatter = gtsam::DefaultKeyFormatter); +}; + +} \ No newline at end of file diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index a657c6be7e..b83bf1f0fe 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -73,6 +73,7 @@ set(interface_files ${GTSAM_SOURCE_DIR}/gtsam/geometry/geometry.i ${GTSAM_SOURCE_DIR}/gtsam/linear/linear.i ${GTSAM_SOURCE_DIR}/gtsam/nonlinear/nonlinear.i + ${GTSAM_SOURCE_DIR}/gtsam/nonlinear/custom.i ${GTSAM_SOURCE_DIR}/gtsam/symbolic/symbolic.i ${GTSAM_SOURCE_DIR}/gtsam/sam/sam.i ${GTSAM_SOURCE_DIR}/gtsam/slam/slam.i diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index c14f02ddab..f798002964 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -61,6 +61,7 @@ set(interface_headers ${PROJECT_SOURCE_DIR}/gtsam/geometry/geometry.i ${PROJECT_SOURCE_DIR}/gtsam/linear/linear.i ${PROJECT_SOURCE_DIR}/gtsam/nonlinear/nonlinear.i + ${PROJECT_SOURCE_DIR}/gtsam/nonlinear/custom.i ${PROJECT_SOURCE_DIR}/gtsam/symbolic/symbolic.i ${PROJECT_SOURCE_DIR}/gtsam/sam/sam.i ${PROJECT_SOURCE_DIR}/gtsam/slam/slam.i diff --git a/python/gtsam/preamble/custom.h b/python/gtsam/preamble/custom.h new file mode 100644 index 0000000000..d07a75f6fb --- /dev/null +++ b/python/gtsam/preamble/custom.h @@ -0,0 +1,12 @@ +/* Please refer to: + * https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html + * These are required to save one copy operation on Python calls. + * + * NOTES + * ================= + * + * `PYBIND11_MAKE_OPAQUE` will mark the type as "opaque" for the pybind11 + * automatic STL binding, such that the raw objects can be accessed in Python. + * Without this they will be automatically converted to a Python object, and all + * mutations on Python side will not be reflected on C++. + */ diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index d07a75f6fb..661215e599 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -10,3 +10,4 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ +#include diff --git a/python/gtsam/specializations/custom.h b/python/gtsam/specializations/custom.h new file mode 100644 index 0000000000..d46ccdc668 --- /dev/null +++ b/python/gtsam/specializations/custom.h @@ -0,0 +1,12 @@ +/* Please refer to: + * https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html + * These are required to save one copy operation on Python calls. + * + * NOTES + * ================= + * + * `py::bind_vector` and similar machinery gives the std container a Python-like + * interface, but without the `` copying mechanism. Combined + * with `PYBIND11_MAKE_OPAQUE` this allows the types to be modified with Python, + * and saves one copy operation. + */ \ No newline at end of file From 31d174d640001c50d531ec5078017a8441d98624 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 19 Jul 2022 14:09:39 -0400 Subject: [PATCH 0098/1497] add gtsam namespace --- gtsam/nonlinear/CustomFactor.h | 2 -- gtsam/nonlinear/nonlinear.i | 43 +++++----------------------------- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/gtsam/nonlinear/CustomFactor.h b/gtsam/nonlinear/CustomFactor.h index 615b5418e8..8580a49496 100644 --- a/gtsam/nonlinear/CustomFactor.h +++ b/gtsam/nonlinear/CustomFactor.h @@ -19,8 +19,6 @@ #include -using namespace gtsam; - namespace gtsam { using JacobianVector = std::vector; diff --git a/gtsam/nonlinear/nonlinear.i b/gtsam/nonlinear/nonlinear.i index b6d0f31be4..c793332368 100644 --- a/gtsam/nonlinear/nonlinear.i +++ b/gtsam/nonlinear/nonlinear.i @@ -99,11 +99,11 @@ class NonlinearFactorGraph { string dot( const gtsam::Values& values, const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter, - const GraphvizFormatting& writer = GraphvizFormatting()); + const gtsam::GraphvizFormatting& writer = gtsam::GraphvizFormatting()); void saveGraph( const string& s, const gtsam::Values& values, const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter, - const GraphvizFormatting& writer = GraphvizFormatting()) const; + const gtsam::GraphvizFormatting& writer = gtsam::GraphvizFormatting()) const; // enabling serialization functionality void serialize() const; @@ -135,37 +135,6 @@ virtual class NoiseModelFactor : gtsam::NonlinearFactor { Vector whitenedError(const gtsam::Values& x) const; }; -#include -virtual class CustomFactor : gtsam::NoiseModelFactor { - /* - * Note CustomFactor will not be wrapped for MATLAB, as there is no supporting - * machinery there. This is achieved by adding `gtsam::CustomFactor` to the - * ignore list in `matlab/CMakeLists.txt`. - */ - CustomFactor(); - /* - * Example: - * ``` - * def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]): - * - * if not H is None: - * - * H[0] = J1 # 2-d numpy array for a Jacobian block - * H[1] = J2 - * ... - * return error # 1-d numpy array - * - * cf = CustomFactor(noise_model, keys, error_func) - * ``` - */ - CustomFactor(const gtsam::SharedNoiseModel& noiseModel, - const gtsam::KeyVector& keys, - const gtsam::CustomErrorFunction& errorFunction); - - void print(string s = "", - gtsam::KeyFormatter keyFormatter = gtsam::DefaultKeyFormatter); -}; - #include class Values { Values(); @@ -554,7 +523,7 @@ virtual class GncParams { GncParams(const PARAMS& baseOptimizerParams); GncParams(); BaseOptimizerParameters baseOptimizerParams; - GncLossType lossType; + gtsam::GncLossType lossType; size_t maxIterations; double muStep; double relativeCostTol; @@ -563,12 +532,12 @@ virtual class GncParams { std::vector knownInliers; std::vector knownOutliers; - void setLossType(const GncLossType type); + void setLossType(const gtsam::GncLossType type); void setMaxIterations(const size_t maxIter); void setMuStep(const double step); void setRelativeCostTol(double value); void setWeightsTol(double value); - void setVerbosityGNC(const This::Verbosity value); + void setVerbosityGNC(const gtsam::This::Verbosity value); void setKnownInliers(const std::vector& knownIn); void setKnownOutliers(const std::vector& knownOut); void print(const string& str = "GncParams: ") const; @@ -900,7 +869,7 @@ template , gtsam::imuBias::ConstantBias}> virtual class NonlinearEquality2 : gtsam::NoiseModelFactor { - NonlinearEquality2(Key key1, Key key2, double mu = 1e4); + NonlinearEquality2(gtsam::Key key1, gtsam::Key key2, double mu = 1e4); gtsam::Vector evaluateError(const T& x1, const T& x2); }; From 71767a4c2bf694a4665eaed1d54b7c9b5598ed3b Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Tue, 19 Jul 2022 14:57:15 -0400 Subject: [PATCH 0099/1497] serialization debugging (from stash) --- gtsam/nonlinear/NonlinearFactor.h | 13 +++++++- .../tests/testSerializationNonlinear.cpp | 33 +++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index b69371f162..cafb747b80 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -264,9 +264,13 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int /*version*/) { + std::cout << "noise model base open " << std::endl; ar & boost::serialization::make_nvp("NonlinearFactor", boost::serialization::base_object(*this)); + std::cout << "noise model itself begin" << std::endl; ar & BOOST_SERIALIZATION_NVP(noiseModel_); + std::cout << "noise model itself end" << std::endl; + std::cout << "noise model base close " << std::endl; } }; // \class NoiseModelFactor @@ -462,8 +466,10 @@ class NoiseModelFactorN : public NoiseModelFactor { friend class boost::serialization::access; template void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + std::cout << "checkpoint N open" << std::endl; ar& boost::serialization::make_nvp( "NoiseModelFactor", boost::serialization::base_object(*this)); + std::cout << "checkpoint N close" << std::endl; } }; // \class NoiseModelFactorN @@ -496,8 +502,13 @@ class NoiseModelFactor1 : public NoiseModelFactorN { friend class boost::serialization::access; template void serialize(ARCHIVE& ar, const unsigned int /*version*/) { + std::cout << "checkpoint a open " << std::endl; + // ar& boost::serialization::make_nvp( + // "NoiseModelFactor", boost::serialization::base_object(*this)); ar& boost::serialization::make_nvp( - "NoiseModelFactor", boost::serialization::base_object(*this)); + "NoiseModelFactorN", + boost::serialization::base_object>(*this)); + std::cout << "checkpoint a close" << std::endl; } }; // \class NoiseModelFactor1 diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index 63e2ae1dd9..5622da07de 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -88,6 +88,7 @@ static Cal3DS2 cal2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); static Cal3Bundler cal3(1.0, 2.0, 3.0); TEST (Serialization, TemplatedValues) { + std::cout << "templatedValues open" << std::endl; EXPECT(equalsObj(pt3)); GenericValue chv1(pt3); EXPECT(equalsObj(chv1)); @@ -105,6 +106,7 @@ TEST (Serialization, TemplatedValues) { EXPECT(equalsObj(values)); EXPECT(equalsXML(values)); EXPECT(equalsBinary(values)); + std::cout << "templatedValues close" << std::endl; } /** @@ -115,14 +117,21 @@ TEST (Serialization, TemplatedValues) { * (2) serialized string depends on boost version */ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { + std::cout << "checkpoint: __FILE__, __LINE__" << std::endl; PriorFactor factor( 12345, Pose3(Rot3::RzRyRx(Vector3(1., 2., 3.)), Point3(4., 5., 6.)), noiseModel::Unit::Create(6)); + std::cout << "Serialized: \n" + << serializeToString(factor) << "\nend serialization" << std::endl; + + std::cout << "checkpoint: __FILE__, __LINE__" << std::endl; + // String + std::cout << "checkpoint: __FILE__, __LINE__" << std::endl; std::string serialized_str = "22 serialization::archive 15 1 0\n" - "0 0 0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" + "0 0 0 0 0 0 0 0 0 1 0 12345 0 1 7 21 gtsam_noiseModel_Unit 1 0\n" "1 1 0\n" "2 1 0\n" "3 0 0 0 0 6 0 1 0 0 0 6 1.00000000000000000e+00 1.00000000000000000e+00 " @@ -135,20 +144,39 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { "-5.87266449276209815e-02 -4.26917621276207360e-01 " "9.02381585483330806e-01 -9.09297426825681709e-01 " "-3.50175488374014632e-01 -2.24845095366152908e-01 0 0 " - "4.00000000000000000e+00 5.00000000000000000e+00 6.00000000000000000e+00"; + "4.00000000000000000e+00 5.00000000000000000e+00 " + "6.00000000000000000e+00\n"; + + // // serialized_str = serializeToString(factor); + // { + std::cout << "roundtrip start" << std::endl; + PriorFactor factor_deserialized_str_2 = PriorFactor(); + roundtrip(factor, factor_deserialized_str_2); + EXPECT(assert_equal(factor, factor_deserialized_str_2)); + std::cout << "roundtrip end" << std::endl; + // } + PriorFactor factor_deserialized_str = PriorFactor(); + std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; deserializeFromString(serialized_str, factor_deserialized_str); + std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; EXPECT(assert_equal(factor, factor_deserialized_str)); + std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; // XML + std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; PriorFactor factor_deserialized_xml = PriorFactor(); + std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; deserializeFromXMLFile(GTSAM_SOURCE_TREE_DATASET_DIR "/../../gtsam/nonlinear/tests/priorFactor.xml", factor_deserialized_xml); + std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; EXPECT(assert_equal(factor, factor_deserialized_xml)); + std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; } TEST(Serialization, ISAM2) { + std::cout << "ISAM2 open" << std::endl; gtsam::ISAM2Params parameters; gtsam::ISAM2 solver(parameters); @@ -201,6 +229,7 @@ TEST(Serialization, ISAM2) { EXPECT(false); } EXPECT(assert_equal(p1, p2)); + std::cout << "ISAM close" << std::endl; } /* ************************************************************************* */ From 90723d933edf9bd68135444f1bc70ad678da1aaa Mon Sep 17 00:00:00 2001 From: Amado Antonini Date: Tue, 19 Jul 2022 19:32:21 -0400 Subject: [PATCH 0100/1497] Remove pybind/stl.h again --- python/gtsam/preamble/nonlinear.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index 661215e599..a34e730580 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -9,5 +9,4 @@ * automatic STL binding, such that the raw objects can be accessed in Python. * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. - */ -#include + */ \ No newline at end of file From 00cf13bd4bed640b10ded2896ce0678b5dcc1e5c Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Tue, 19 Jul 2022 17:19:04 -0400 Subject: [PATCH 0101/1497] update serialized string --- gtsam/nonlinear/tests/testSerializationNonlinear.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index 5622da07de..95906183c9 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -131,7 +131,7 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { std::cout << "checkpoint: __FILE__, __LINE__" << std::endl; std::string serialized_str = "22 serialization::archive 15 1 0\n" - "0 0 0 0 0 0 0 0 0 1 0 12345 0 1 7 21 gtsam_noiseModel_Unit 1 0\n" + "0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" "1 1 0\n" "2 1 0\n" "3 0 0 0 0 6 0 1 0 0 0 6 1.00000000000000000e+00 1.00000000000000000e+00 " From ea6e32de82ae29f95de90cffb5943da4b48b193a Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Tue, 19 Jul 2022 17:19:47 -0400 Subject: [PATCH 0102/1497] bugfix on serialization --- gtsam/nonlinear/NonlinearFactor.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index cafb747b80..7dc5ea0b0c 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -503,11 +503,8 @@ class NoiseModelFactor1 : public NoiseModelFactorN { template void serialize(ARCHIVE& ar, const unsigned int /*version*/) { std::cout << "checkpoint a open " << std::endl; - // ar& boost::serialization::make_nvp( - // "NoiseModelFactor", boost::serialization::base_object(*this)); ar& boost::serialization::make_nvp( - "NoiseModelFactorN", - boost::serialization::base_object>(*this)); + "NoiseModelFactor", boost::serialization::base_object(*this)); std::cout << "checkpoint a close" << std::endl; } }; // \class NoiseModelFactor1 From 83276853b58c64bb222c93ff73005acbb82c7079 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Tue, 19 Jul 2022 21:41:45 -0400 Subject: [PATCH 0103/1497] remove debug statements --- gtsam/nonlinear/NonlinearFactor.h | 8 ----- .../tests/testSerializationNonlinear.cpp | 35 ++++--------------- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 7dc5ea0b0c..b69371f162 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -264,13 +264,9 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { friend class boost::serialization::access; template void serialize(ARCHIVE & ar, const unsigned int /*version*/) { - std::cout << "noise model base open " << std::endl; ar & boost::serialization::make_nvp("NonlinearFactor", boost::serialization::base_object(*this)); - std::cout << "noise model itself begin" << std::endl; ar & BOOST_SERIALIZATION_NVP(noiseModel_); - std::cout << "noise model itself end" << std::endl; - std::cout << "noise model base close " << std::endl; } }; // \class NoiseModelFactor @@ -466,10 +462,8 @@ class NoiseModelFactorN : public NoiseModelFactor { friend class boost::serialization::access; template void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - std::cout << "checkpoint N open" << std::endl; ar& boost::serialization::make_nvp( "NoiseModelFactor", boost::serialization::base_object(*this)); - std::cout << "checkpoint N close" << std::endl; } }; // \class NoiseModelFactorN @@ -502,10 +496,8 @@ class NoiseModelFactor1 : public NoiseModelFactorN { friend class boost::serialization::access; template void serialize(ARCHIVE& ar, const unsigned int /*version*/) { - std::cout << "checkpoint a open " << std::endl; ar& boost::serialization::make_nvp( "NoiseModelFactor", boost::serialization::base_object(*this)); - std::cout << "checkpoint a close" << std::endl; } }; // \class NoiseModelFactor1 diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index 95906183c9..860cd225bd 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -88,7 +88,6 @@ static Cal3DS2 cal2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); static Cal3Bundler cal3(1.0, 2.0, 3.0); TEST (Serialization, TemplatedValues) { - std::cout << "templatedValues open" << std::endl; EXPECT(equalsObj(pt3)); GenericValue chv1(pt3); EXPECT(equalsObj(chv1)); @@ -106,7 +105,6 @@ TEST (Serialization, TemplatedValues) { EXPECT(equalsObj(values)); EXPECT(equalsXML(values)); EXPECT(equalsBinary(values)); - std::cout << "templatedValues close" << std::endl; } /** @@ -117,18 +115,16 @@ TEST (Serialization, TemplatedValues) { * (2) serialized string depends on boost version */ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { - std::cout << "checkpoint: __FILE__, __LINE__" << std::endl; PriorFactor factor( 12345, Pose3(Rot3::RzRyRx(Vector3(1., 2., 3.)), Point3(4., 5., 6.)), noiseModel::Unit::Create(6)); - std::cout << "Serialized: \n" - << serializeToString(factor) << "\nend serialization" << std::endl; + // roundtrip (sanity check) + PriorFactor factor_deserialized_str_2 = PriorFactor(); + roundtrip(factor, factor_deserialized_str_2); + EXPECT(assert_equal(factor, factor_deserialized_str_2)); - std::cout << "checkpoint: __FILE__, __LINE__" << std::endl; - - // String - std::cout << "checkpoint: __FILE__, __LINE__" << std::endl; + // Deserialize string std::string serialized_str = "22 serialization::archive 15 1 0\n" "0 0 0 0 0 0 0 1 0 12345 0 1 6 21 gtsam_noiseModel_Unit 1 0\n" @@ -147,37 +143,19 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { "4.00000000000000000e+00 5.00000000000000000e+00 " "6.00000000000000000e+00\n"; - // // serialized_str = serializeToString(factor); - // { - std::cout << "roundtrip start" << std::endl; - PriorFactor factor_deserialized_str_2 = PriorFactor(); - roundtrip(factor, factor_deserialized_str_2); - EXPECT(assert_equal(factor, factor_deserialized_str_2)); - std::cout << "roundtrip end" << std::endl; - // } - PriorFactor factor_deserialized_str = PriorFactor(); - std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; deserializeFromString(serialized_str, factor_deserialized_str); - std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; EXPECT(assert_equal(factor, factor_deserialized_str)); - std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; - // XML - std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; + // Deserialize XML PriorFactor factor_deserialized_xml = PriorFactor(); - std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; deserializeFromXMLFile(GTSAM_SOURCE_TREE_DATASET_DIR "/../../gtsam/nonlinear/tests/priorFactor.xml", factor_deserialized_xml); - std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; EXPECT(assert_equal(factor, factor_deserialized_xml)); - std::cout << "checkpoint: " << __FILE__ << ", " << __LINE__ << std::endl; } TEST(Serialization, ISAM2) { - std::cout << "ISAM2 open" << std::endl; - gtsam::ISAM2Params parameters; gtsam::ISAM2 solver(parameters); gtsam::NonlinearFactorGraph graph; @@ -229,7 +207,6 @@ TEST(Serialization, ISAM2) { EXPECT(false); } EXPECT(assert_equal(p1, p2)); - std::cout << "ISAM close" << std::endl; } /* ************************************************************************* */ From fa196aa638de2b19004d07dd6aa4f69221cd1c10 Mon Sep 17 00:00:00 2001 From: Gerry Chen Date: Wed, 20 Jul 2022 00:15:58 -0400 Subject: [PATCH 0104/1497] turn off backwards compatibility test with quaternions or TBB since serialization structure is different --- gtsam/nonlinear/tests/testSerializationNonlinear.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp index 860cd225bd..f402656c12 100644 --- a/gtsam/nonlinear/tests/testSerializationNonlinear.cpp +++ b/gtsam/nonlinear/tests/testSerializationNonlinear.cpp @@ -109,10 +109,13 @@ TEST (Serialization, TemplatedValues) { /** * Test deserializing from a known serialization generated by code from commit - * 3ba65669113f41d0e56a03b4b314047776bab5c4 (>4.2a4) + * 0af17f438f62f4788f3a572ecd36d06d224fd1e1 (>4.2a7) * We only test that deserialization matches since * (1) that's the main backward compatibility requirement and * (2) serialized string depends on boost version + * Also note: we don't run this test when quaternions or TBB are enabled since + * serialization structures are different and the serialized strings/xml are + * hard-coded in this test. */ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { PriorFactor factor( @@ -124,6 +127,7 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { roundtrip(factor, factor_deserialized_str_2); EXPECT(assert_equal(factor, factor_deserialized_str_2)); +#if !defined(GTSAM_USE_QUATERNIONS) && !defined(GTSAM_USE_TBB) // Deserialize string std::string serialized_str = "22 serialization::archive 15 1 0\n" @@ -153,6 +157,7 @@ TEST(Serialization, NoiseModelFactor1_backwards_compatibility) { "/../../gtsam/nonlinear/tests/priorFactor.xml", factor_deserialized_xml); EXPECT(assert_equal(factor, factor_deserialized_xml)); +#endif } TEST(Serialization, ISAM2) { From 12b35b41424d1564162fde59b47b474b23d26678 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 19 Jul 2022 18:59:58 -0400 Subject: [PATCH 0105/1497] remove pybind stl.h --- python/gtsam/preamble/nonlinear.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index a34e730580..d07a75f6fb 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -9,4 +9,4 @@ * automatic STL binding, such that the raw objects can be accessed in Python. * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. - */ \ No newline at end of file + */ From 7eb9a95c5fbf0e60813d69443e2e9ab7dcd50c58 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 22 Jul 2022 05:35:09 -0400 Subject: [PATCH 0106/1497] minor fixes --- gtsam/nonlinear/NonlinearFactor.cpp | 3 ++- python/gtsam/preamble/nonlinear.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gtsam/nonlinear/NonlinearFactor.cpp b/gtsam/nonlinear/NonlinearFactor.cpp index 3d572e9702..debff54acd 100644 --- a/gtsam/nonlinear/NonlinearFactor.cpp +++ b/gtsam/nonlinear/NonlinearFactor.cpp @@ -167,8 +167,9 @@ boost::shared_ptr NoiseModelFactor::linearize( return GaussianFactor::shared_ptr( new JacobianFactor(terms, b, boost::static_pointer_cast(noiseModel_)->unit())); - else + else { return GaussianFactor::shared_ptr(new JacobianFactor(terms, b)); + } } /* ************************************************************************* */ diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index d07a75f6fb..56a07cfdd1 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -10,3 +10,5 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ + +#include From 31cfce0b8dfc284fb593c2e27f5c0b9c0f374ae7 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 22 Jul 2022 05:15:40 -0400 Subject: [PATCH 0107/1497] update macos CI env --- .github/workflows/build-macos.yml | 10 +++++----- .github/workflows/build-python.yml | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 462723222f..7b76463280 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -19,16 +19,16 @@ jobs: # Github Actions requires a single row to be added to the build matrix. # See https://help.github.com/en/articles/workflow-syntax-for-github-actions. name: [ - macOS-10.15-xcode-11.3.1, + macos-11-xcode-13.4.1, ] build_type: [Debug, Release] build_unstable: [ON] include: - - name: macOS-10.15-xcode-11.3.1 - os: macOS-10.15 + - name: macos-11-xcode-13.4.1 + os: macos-11 compiler: xcode - version: "11.3.1" + version: "13.4.1" steps: - name: Checkout @@ -43,7 +43,7 @@ jobs: echo "CC=gcc-${{ matrix.version }}" >> $GITHUB_ENV echo "CXX=g++-${{ matrix.version }}" >> $GITHUB_ENV else - sudo xcode-select -switch /Applications/Xcode_${{ matrix.version }}.app + sudo xcode-select -switch /Applications/Xcode.app echo "CC=clang" >> $GITHUB_ENV echo "CXX=clang++" >> $GITHUB_ENV fi diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml index f42939bc20..f80b9362c9 100644 --- a/.github/workflows/build-python.yml +++ b/.github/workflows/build-python.yml @@ -22,7 +22,7 @@ jobs: ubuntu-18.04-gcc-5, ubuntu-18.04-gcc-9, ubuntu-18.04-clang-9, - macOS-10.15-xcode-11.3.1, + macOS-11-xcode-13.4.1, ubuntu-18.04-gcc-5-tbb, ] @@ -52,10 +52,10 @@ jobs: build_type: Debug python_version: "3" - - name: macOS-10.15-xcode-11.3.1 - os: macOS-10.15 + - name: macOS-11-xcode-13.4.1 + os: macOS-11 compiler: xcode - version: "11.3.1" + version: "13.4.1" - name: ubuntu-18.04-gcc-5-tbb os: ubuntu-18.04 @@ -103,7 +103,7 @@ jobs: echo "CC=gcc-${{ matrix.version }}" >> $GITHUB_ENV echo "CXX=g++-${{ matrix.version }}" >> $GITHUB_ENV else - sudo xcode-select -switch /Applications/Xcode_${{ matrix.version }}.app + sudo xcode-select -switch /Applications/Xcode.app echo "CC=clang" >> $GITHUB_ENV echo "CXX=clang++" >> $GITHUB_ENV fi From 7edd021956e659f1b2ecba5a630682df1d7ea0d2 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 22 Jul 2022 14:00:03 -0400 Subject: [PATCH 0108/1497] fix copying of test files in Cmake --- python/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index cba206d111..0d63c6c543 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -104,7 +104,8 @@ copy_directory("${CMAKE_CURRENT_SOURCE_DIR}/gtsam" # Hack to get python test and util files copied every time they are modified file(GLOB GTSAM_PYTHON_TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/gtsam/tests/*.py") foreach(test_file ${GTSAM_PYTHON_TEST_FILES}) - configure_file(${test_file} "${GTSAM_MODULE_PATH}/tests/${test_file}" COPYONLY) + get_filename_component(test_file_name ${test_file} NAME) + configure_file(${test_file} "${GTSAM_MODULE_PATH}/tests/${test_file_name}" COPYONLY) endforeach() file(GLOB GTSAM_PYTHON_UTIL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/gtsam/utils/*.py") foreach(util_file ${GTSAM_PYTHON_UTIL_FILES}) From aef4ec81857692c507fe0db759e3303d5cc4e565 Mon Sep 17 00:00:00 2001 From: agilemapper <87449851+agilemapper@users.noreply.github.com> Date: Sat, 23 Jul 2022 13:04:42 +0200 Subject: [PATCH 0109/1497] replace addtogroup with ingroup for the SLAM group --- gtsam/groups.dox | 5 ++++- gtsam/navigation/CombinedImuFactor.h | 4 ++-- gtsam/navigation/ImuFactor.h | 6 +++--- gtsam/nonlinear/PriorFactor.h | 2 +- gtsam/sam/BearingRangeFactor.h | 2 +- gtsam/slam/AntiFactor.h | 2 +- gtsam/slam/BetweenFactor.h | 2 +- gtsam/slam/BoundingConstraint.h | 2 +- gtsam/slam/EssentialMatrixConstraint.h | 2 +- gtsam/slam/GeneralSFMFactor.h | 2 +- gtsam/slam/ProjectionFactor.h | 2 +- gtsam/slam/SmartProjectionPoseFactor.h | 4 ++-- gtsam/slam/SmartProjectionRigFactor.h | 4 ++-- gtsam/slam/StereoFactor.h | 2 +- gtsam/slam/TriangulationFactor.h | 2 +- gtsam_unstable/slam/BetweenFactorEM.h | 2 +- gtsam_unstable/slam/BiasedGPSFactor.h | 2 +- gtsam_unstable/slam/MultiProjectionFactor.h | 2 +- gtsam_unstable/slam/PoseBetweenFactor.h | 2 +- gtsam_unstable/slam/PosePriorFactor.h | 2 +- gtsam_unstable/slam/PoseToPointFactor.h | 2 +- gtsam_unstable/slam/ProjectionFactorPPP.h | 2 +- gtsam_unstable/slam/ProjectionFactorPPPC.h | 2 +- gtsam_unstable/slam/ProjectionFactorRollingShutter.h | 2 +- .../slam/SmartProjectionPoseFactorRollingShutter.h | 4 ++-- gtsam_unstable/slam/SmartRangeFactor.h | 2 +- gtsam_unstable/slam/SmartStereoProjectionFactorPP.h | 4 ++-- gtsam_unstable/slam/SmartStereoProjectionPoseFactor.h | 4 ++-- gtsam_unstable/slam/TransformBtwRobotsUnaryFactor.h | 2 +- gtsam_unstable/slam/TransformBtwRobotsUnaryFactorEM.h | 2 +- 30 files changed, 41 insertions(+), 38 deletions(-) diff --git a/gtsam/groups.dox b/gtsam/groups.dox index 6031b33bbf..6f7124c42e 100644 --- a/gtsam/groups.dox +++ b/gtsam/groups.dox @@ -11,4 +11,7 @@ @} -*/ \ No newline at end of file +\defgroup SLAM Useful SLAM components +@{ @} + +*/ diff --git a/gtsam/navigation/CombinedImuFactor.h b/gtsam/navigation/CombinedImuFactor.h index 213f5f223f..54c5a7dbb3 100644 --- a/gtsam/navigation/CombinedImuFactor.h +++ b/gtsam/navigation/CombinedImuFactor.h @@ -123,7 +123,7 @@ struct GTSAM_EXPORT PreintegrationCombinedParams : PreintegrationParams { * it is received from the IMU) so as to avoid costly integration at time of * factor construction. * - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_EXPORT PreintegratedCombinedMeasurements : public PreintegrationType { @@ -252,7 +252,7 @@ class GTSAM_EXPORT PreintegratedCombinedMeasurements : public PreintegrationType * the correlation between the bias uncertainty and the preintegrated * measurements uncertainty. * - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_EXPORT CombinedImuFactor: public NoiseModelFactor6 { diff --git a/gtsam/navigation/ImuFactor.h b/gtsam/navigation/ImuFactor.h index 7408271627..c3b398e223 100644 --- a/gtsam/navigation/ImuFactor.h +++ b/gtsam/navigation/ImuFactor.h @@ -66,7 +66,7 @@ typedef ManifoldPreintegration PreintegrationType; * as soon as it is received from the IMU) so as to avoid costly integration * at time of factor construction. * - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_EXPORT PreintegratedImuMeasurements: public PreintegrationType { @@ -165,7 +165,7 @@ class GTSAM_EXPORT PreintegratedImuMeasurements: public PreintegrationType { * (which are usually slowly varying quantities), which is up to the caller. * See also CombinedImuFactor for a class that does this for you. * - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_EXPORT ImuFactor: public NoiseModelFactor5 { @@ -256,7 +256,7 @@ class GTSAM_EXPORT ImuFactor: public NoiseModelFactor5 { private: diff --git a/gtsam/nonlinear/PriorFactor.h b/gtsam/nonlinear/PriorFactor.h index a490162ac3..c5124a3fe7 100644 --- a/gtsam/nonlinear/PriorFactor.h +++ b/gtsam/nonlinear/PriorFactor.h @@ -24,7 +24,7 @@ namespace gtsam { /** * A class for a soft prior on any Value type - * @addtogroup SLAM + * @ingroup SLAM */ template class PriorFactor: public NoiseModelFactor1 { diff --git a/gtsam/sam/BearingRangeFactor.h b/gtsam/sam/BearingRangeFactor.h index 9874760c46..c83009651e 100644 --- a/gtsam/sam/BearingRangeFactor.h +++ b/gtsam/sam/BearingRangeFactor.h @@ -27,7 +27,7 @@ namespace gtsam { /** * Binary factor for a bearing/range measurement - * @addtogroup SLAM + * @ingroup SLAM */ template ::result_type, diff --git a/gtsam/slam/AntiFactor.h b/gtsam/slam/AntiFactor.h index 3b559fe792..a0d6a12071 100644 --- a/gtsam/slam/AntiFactor.h +++ b/gtsam/slam/AntiFactor.h @@ -26,7 +26,7 @@ namespace gtsam { * A class for downdating an existing factor from a graph. The AntiFactor returns the same * linearized Hessian matrices of the original factor, but with the opposite sign. This effectively * cancels out any affects of the original factor during optimization." - * @addtogroup SLAM + * @ingroup SLAM */ class AntiFactor: public NonlinearFactor { diff --git a/gtsam/slam/BetweenFactor.h b/gtsam/slam/BetweenFactor.h index f80462847f..fc1dc4481e 100644 --- a/gtsam/slam/BetweenFactor.h +++ b/gtsam/slam/BetweenFactor.h @@ -34,7 +34,7 @@ namespace gtsam { /** * A class for a measurement predicted by "between(config[key1],config[key2])" * @tparam VALUE the Value type - * @addtogroup SLAM + * @ingroup SLAM */ template class BetweenFactor: public NoiseModelFactor2 { diff --git a/gtsam/slam/BoundingConstraint.h b/gtsam/slam/BoundingConstraint.h index 3d5842fa2b..07c7656690 100644 --- a/gtsam/slam/BoundingConstraint.h +++ b/gtsam/slam/BoundingConstraint.h @@ -27,7 +27,7 @@ namespace gtsam { * greater/less than a fixed threshold. The function * will need to have its value function implemented to return * a scalar for comparison. - * @addtogroup SLAM + * @ingroup SLAM */ template struct BoundingConstraint1: public NoiseModelFactor1 { diff --git a/gtsam/slam/EssentialMatrixConstraint.h b/gtsam/slam/EssentialMatrixConstraint.h index 6274be9635..91487b522e 100644 --- a/gtsam/slam/EssentialMatrixConstraint.h +++ b/gtsam/slam/EssentialMatrixConstraint.h @@ -25,7 +25,7 @@ namespace gtsam { /** * Binary factor between two Pose3 variables induced by an EssentialMatrix measurement - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_EXPORT EssentialMatrixConstraint: public NoiseModelFactor2 { diff --git a/gtsam/slam/GeneralSFMFactor.h b/gtsam/slam/GeneralSFMFactor.h index bfc3a0f78d..5cf8d5b752 100644 --- a/gtsam/slam/GeneralSFMFactor.h +++ b/gtsam/slam/GeneralSFMFactor.h @@ -54,7 +54,7 @@ namespace gtsam { /** * Non-linear factor for a constraint derived from a 2D measurement. * The calibration is unknown here compared to GenericProjectionFactor - * @addtogroup SLAM + * @ingroup SLAM */ template class GeneralSFMFactor: public NoiseModelFactor2 { diff --git a/gtsam/slam/ProjectionFactor.h b/gtsam/slam/ProjectionFactor.h index 42dba8bd01..e01b9b0b8a 100644 --- a/gtsam/slam/ProjectionFactor.h +++ b/gtsam/slam/ProjectionFactor.h @@ -33,7 +33,7 @@ namespace gtsam { * Non-linear factor for a constraint derived from a 2D measurement. * The calibration is known here. * The main building block for visual SLAM. - * @addtogroup SLAM + * @ingroup SLAM */ template diff --git a/gtsam/slam/SmartProjectionPoseFactor.h b/gtsam/slam/SmartProjectionPoseFactor.h index f4c0c73aac..f1403bdb15 100644 --- a/gtsam/slam/SmartProjectionPoseFactor.h +++ b/gtsam/slam/SmartProjectionPoseFactor.h @@ -24,7 +24,7 @@ namespace gtsam { /** * - * @addtogroup SLAM + * @ingroup SLAM * * If you are using the factor, please cite: * L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert, Eliminating conditionally @@ -39,7 +39,7 @@ namespace gtsam { * The factor only constrains poses (variable dimension is 6). * This factor requires that values contains the involved poses (Pose3). * If the calibration should be optimized, as well, use SmartProjectionFactor instead! - * @addtogroup SLAM + * @ingroup SLAM */ template class SmartProjectionPoseFactor diff --git a/gtsam/slam/SmartProjectionRigFactor.h b/gtsam/slam/SmartProjectionRigFactor.h index 149c129288..40af55b2c5 100644 --- a/gtsam/slam/SmartProjectionRigFactor.h +++ b/gtsam/slam/SmartProjectionRigFactor.h @@ -29,7 +29,7 @@ namespace gtsam { /** * - * @addtogroup SLAM + * @ingroup SLAM * * If you are using the factor, please cite: * L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert, Eliminating @@ -46,7 +46,7 @@ namespace gtsam { * calibration (i.e., are from the same camera), use SmartProjectionPoseFactor * instead! If the calibration should be optimized, as well, use * SmartProjectionFactor instead! - * @addtogroup SLAM + * @ingroup SLAM */ template class SmartProjectionRigFactor : public SmartProjectionFactor { diff --git a/gtsam/slam/StereoFactor.h b/gtsam/slam/StereoFactor.h index de084c7625..b2fdbf7a45 100644 --- a/gtsam/slam/StereoFactor.h +++ b/gtsam/slam/StereoFactor.h @@ -25,7 +25,7 @@ namespace gtsam { /** * A Generic Stereo Factor - * @addtogroup SLAM + * @ingroup SLAM */ template class GenericStereoFactor: public NoiseModelFactor2 { diff --git a/gtsam/slam/TriangulationFactor.h b/gtsam/slam/TriangulationFactor.h index b6da02d556..405436b82d 100644 --- a/gtsam/slam/TriangulationFactor.h +++ b/gtsam/slam/TriangulationFactor.h @@ -27,7 +27,7 @@ namespace gtsam { /** * Non-linear factor for a constraint derived from a 2D measurement. * The calibration and pose are assumed known. - * @addtogroup SLAM + * @ingroup SLAM */ template class TriangulationFactor: public NoiseModelFactor1 { diff --git a/gtsam_unstable/slam/BetweenFactorEM.h b/gtsam_unstable/slam/BetweenFactorEM.h index 9c19bae8c5..ffaa05c7dd 100644 --- a/gtsam_unstable/slam/BetweenFactorEM.h +++ b/gtsam_unstable/slam/BetweenFactorEM.h @@ -28,7 +28,7 @@ namespace gtsam { /** * A class for a measurement predicted by "between(config[key1],config[key2])" * @tparam VALUE the Value type - * @addtogroup SLAM + * @ingroup SLAM */ template class BetweenFactorEM: public NonlinearFactor { diff --git a/gtsam_unstable/slam/BiasedGPSFactor.h b/gtsam_unstable/slam/BiasedGPSFactor.h index f2e9d3fa8b..5359fac4e5 100644 --- a/gtsam_unstable/slam/BiasedGPSFactor.h +++ b/gtsam_unstable/slam/BiasedGPSFactor.h @@ -25,7 +25,7 @@ namespace gtsam { /** * A class to model GPS measurements, including a bias term which models * common-mode errors and that can be partially corrected if other sensors are used - * @addtogroup SLAM + * @ingroup SLAM */ class BiasedGPSFactor: public NoiseModelFactor2 { diff --git a/gtsam_unstable/slam/MultiProjectionFactor.h b/gtsam_unstable/slam/MultiProjectionFactor.h index afc9e0b182..bd4f64fd77 100644 --- a/gtsam_unstable/slam/MultiProjectionFactor.h +++ b/gtsam_unstable/slam/MultiProjectionFactor.h @@ -29,7 +29,7 @@ namespace gtsam { /** * Non-linear factor for a constraint derived from a 2D measurement. The calibration is known here. * i.e. the main building block for visual SLAM. - * @addtogroup SLAM + * @ingroup SLAM */ template class MultiProjectionFactor: public NoiseModelFactor { diff --git a/gtsam_unstable/slam/PoseBetweenFactor.h b/gtsam_unstable/slam/PoseBetweenFactor.h index a6c583418c..a55f3a6e31 100644 --- a/gtsam_unstable/slam/PoseBetweenFactor.h +++ b/gtsam_unstable/slam/PoseBetweenFactor.h @@ -26,7 +26,7 @@ namespace gtsam { /** * A class for a measurement predicted by "between(config[key1],config[key2])" * @tparam POSE the Pose type - * @addtogroup SLAM + * @ingroup SLAM */ template class PoseBetweenFactor: public NoiseModelFactor2 { diff --git a/gtsam_unstable/slam/PosePriorFactor.h b/gtsam_unstable/slam/PosePriorFactor.h index f657fc443f..6668a9b4b7 100644 --- a/gtsam_unstable/slam/PosePriorFactor.h +++ b/gtsam_unstable/slam/PosePriorFactor.h @@ -23,7 +23,7 @@ namespace gtsam { /** * A class for a soft prior on any Value type - * @addtogroup SLAM + * @ingroup SLAM */ template class PosePriorFactor: public NoiseModelFactor1 { diff --git a/gtsam_unstable/slam/PoseToPointFactor.h b/gtsam_unstable/slam/PoseToPointFactor.h index b9b2ad5cea..071d13aec4 100644 --- a/gtsam_unstable/slam/PoseToPointFactor.h +++ b/gtsam_unstable/slam/PoseToPointFactor.h @@ -18,7 +18,7 @@ namespace gtsam { /** * A class for a measurement between a pose and a point. - * @addtogroup SLAM + * @ingroup SLAM */ template class PoseToPointFactor : public NoiseModelFactor2 { diff --git a/gtsam_unstable/slam/ProjectionFactorPPP.h b/gtsam_unstable/slam/ProjectionFactorPPP.h index 84adda7079..41f79d6140 100644 --- a/gtsam_unstable/slam/ProjectionFactorPPP.h +++ b/gtsam_unstable/slam/ProjectionFactorPPP.h @@ -28,7 +28,7 @@ namespace gtsam { /** * Non-linear factor for a constraint derived from a 2D measurement. The calibration is known here. * i.e. the main building block for visual SLAM. - * @addtogroup SLAM + * @ingroup SLAM */ template class ProjectionFactorPPP: public NoiseModelFactor3 { diff --git a/gtsam_unstable/slam/ProjectionFactorPPPC.h b/gtsam_unstable/slam/ProjectionFactorPPPC.h index 18ee13b9a9..ec0a426f9d 100644 --- a/gtsam_unstable/slam/ProjectionFactorPPPC.h +++ b/gtsam_unstable/slam/ProjectionFactorPPPC.h @@ -30,7 +30,7 @@ namespace gtsam { /** * Non-linear factor for a constraint derived from a 2D measurement. This factor * estimates the body pose, body-camera transform, 3D landmark, and calibration. - * @addtogroup SLAM + * @ingroup SLAM */ template class GTSAM_UNSTABLE_EXPORT ProjectionFactorPPPC diff --git a/gtsam_unstable/slam/ProjectionFactorRollingShutter.h b/gtsam_unstable/slam/ProjectionFactorRollingShutter.h index 2aeaa48249..c349fd095b 100644 --- a/gtsam_unstable/slam/ProjectionFactorRollingShutter.h +++ b/gtsam_unstable/slam/ProjectionFactorRollingShutter.h @@ -38,7 +38,7 @@ namespace gtsam { * define the alpha = (t_p - t_A) / (t_B - t_A), we will use the pose * interpolated between A and B by the alpha to project the corresponding * landmark to Point2. - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_UNSTABLE_EXPORT ProjectionFactorRollingShutter diff --git a/gtsam_unstable/slam/SmartProjectionPoseFactorRollingShutter.h b/gtsam_unstable/slam/SmartProjectionPoseFactorRollingShutter.h index ff84fcd16a..b2f58f75f3 100644 --- a/gtsam_unstable/slam/SmartProjectionPoseFactorRollingShutter.h +++ b/gtsam_unstable/slam/SmartProjectionPoseFactorRollingShutter.h @@ -25,7 +25,7 @@ namespace gtsam { /** * - * @addtogroup SLAM + * @ingroup SLAM * * If you are using the factor, please cite: * L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert, @@ -39,7 +39,7 @@ namespace gtsam { * shutter model of the camera with given readout time. The factor requires that * values contain (for each pixel observation) two consecutive camera poses from * which the pixel observation pose can be interpolated. - * @addtogroup SLAM + * @ingroup SLAM */ template class GTSAM_UNSTABLE_EXPORT SmartProjectionPoseFactorRollingShutter diff --git a/gtsam_unstable/slam/SmartRangeFactor.h b/gtsam_unstable/slam/SmartRangeFactor.h index 14e97f6bc2..8a2a1d3a8e 100644 --- a/gtsam_unstable/slam/SmartRangeFactor.h +++ b/gtsam_unstable/slam/SmartRangeFactor.h @@ -24,7 +24,7 @@ namespace gtsam { /** * Smart factor for range SLAM - * @addtogroup SLAM + * @ingroup SLAM */ class SmartRangeFactor: public NoiseModelFactor { protected: diff --git a/gtsam_unstable/slam/SmartStereoProjectionFactorPP.h b/gtsam_unstable/slam/SmartStereoProjectionFactorPP.h index e20241a0ee..e1bc01691e 100644 --- a/gtsam_unstable/slam/SmartStereoProjectionFactorPP.h +++ b/gtsam_unstable/slam/SmartStereoProjectionFactorPP.h @@ -23,7 +23,7 @@ namespace gtsam { /** * - * @addtogroup SLAM + * @ingroup SLAM * * If you are using the factor, please cite: * L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert, @@ -38,7 +38,7 @@ namespace gtsam { * calibration or the same calibration can be shared by multiple cameras. This * factor requires that values contain the involved poses and extrinsics (both * are Pose3 variables). - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_UNSTABLE_EXPORT SmartStereoProjectionFactorPP : public SmartStereoProjectionFactor { diff --git a/gtsam_unstable/slam/SmartStereoProjectionPoseFactor.h b/gtsam_unstable/slam/SmartStereoProjectionPoseFactor.h index a46000a686..9e83b7736b 100644 --- a/gtsam_unstable/slam/SmartStereoProjectionPoseFactor.h +++ b/gtsam_unstable/slam/SmartStereoProjectionPoseFactor.h @@ -26,7 +26,7 @@ namespace gtsam { /** * - * @addtogroup SLAM + * @ingroup SLAM * * If you are using the factor, please cite: * L. Carlone, Z. Kira, C. Beall, V. Indelman, F. Dellaert, @@ -41,7 +41,7 @@ namespace gtsam { * has its own calibration. * The factor only constrains poses (variable dimension is 6). * This factor requires that values contains the involved poses (Pose3). - * @addtogroup SLAM + * @ingroup SLAM */ class GTSAM_UNSTABLE_EXPORT SmartStereoProjectionPoseFactor : public SmartStereoProjectionFactor { diff --git a/gtsam_unstable/slam/TransformBtwRobotsUnaryFactor.h b/gtsam_unstable/slam/TransformBtwRobotsUnaryFactor.h index 956c759991..80d2abf9b9 100644 --- a/gtsam_unstable/slam/TransformBtwRobotsUnaryFactor.h +++ b/gtsam_unstable/slam/TransformBtwRobotsUnaryFactor.h @@ -29,7 +29,7 @@ namespace gtsam { /** * A class for a measurement predicted by "between(config[key1],config[key2])" * @tparam VALUE the Value type - * @addtogroup SLAM + * @ingroup SLAM */ template class TransformBtwRobotsUnaryFactor: public NonlinearFactor { // TODO why not NoiseModelFactor1 ? diff --git a/gtsam_unstable/slam/TransformBtwRobotsUnaryFactorEM.h b/gtsam_unstable/slam/TransformBtwRobotsUnaryFactorEM.h index 2b2edfae98..cce18cc441 100644 --- a/gtsam_unstable/slam/TransformBtwRobotsUnaryFactorEM.h +++ b/gtsam_unstable/slam/TransformBtwRobotsUnaryFactorEM.h @@ -31,7 +31,7 @@ namespace gtsam { /** * A class for a measurement predicted by "between(config[key1],config[key2])" * @tparam VALUE the Value type - * @addtogroup SLAM + * @ingroup SLAM */ template class TransformBtwRobotsUnaryFactorEM: public NonlinearFactor { From e6ccf977125794c0abba8ced4a45751cc5488a86 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Sun, 24 Jul 2022 02:54:07 -0400 Subject: [PATCH 0110/1497] hasUniqueCameras to camel case --- gtsam/sfm/DsfTrackGenerator.h | 192 ++++++++++++++++------------------ gtsam/sfm/sfm.i | 16 +-- 2 files changed, 101 insertions(+), 107 deletions(-) diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index c67215a91f..18c96653a1 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -17,7 +17,6 @@ */ #pragma once -#include #include #include @@ -39,8 +38,7 @@ typedef Eigen::MatrixX2i CorrespondenceIndices; // N x 2 array using KeypointCoordinates = Eigen::MatrixX2d; -struct Keypoints -{ +struct Keypoints { KeypointCoordinates coordinates; // typedef'd for Eigen::VectorXd boost::optional scales; @@ -57,8 +55,7 @@ using MatchIndicesMap = std::map; // @param camera index // @param 2d measurement // Implemented as named tuple, instead of std::pair (like SfmMeasurement in SfmTrack.h) -struct NamedSfmMeasurement -{ +struct NamedSfmMeasurement { size_t i; gtsam::Point2 uv; @@ -71,24 +68,23 @@ struct NamedSfmMeasurement * Note: Equivalent to gtsam.SfmTrack, but without the 3d measurement. * This class holds data temporarily before 3D point is initialized. */ -class SfmTrack2d -{ - private: - std::vector measurements_; - - public: - void addMeasurement(const NamedSfmMeasurement &m) { - measurements_.emplace_back(m); - } - std::vector measurements() {return measurements_; } +class SfmTrack2d { + private: + std::vector measurements_; + + public: + void addMeasurement(const NamedSfmMeasurement &m) { + measurements_.emplace_back(m); + } + std::vector measurements() {return measurements_; } // @brief Validates the track by checking that no two measurements are from the same camera. // // returns boolean result of the validation. - bool has_unique_cameras() + bool hasUniqueCameras() { std::vector track_cam_idxs; - for (auto & measurement: measurements_) + for (auto & measurement : measurements_) { track_cam_idxs.emplace_back(measurement.i); } @@ -101,93 +97,91 @@ class SfmTrack2d /** * @brief Generates point tracks from connected components in the keypoint matches graph. */ -class DsfTrackGenerator -{ - - public: - /** Default constructor. */ - DsfTrackGenerator() {} - - // Creates a list of tracks from 2d point correspondences. - // - // Creates a disjoint-set forest (DSF) and 2d tracks from pairwise matches. - // We create a singleton for union-find set elements from camera index of a - // detection and the index of that detection in that camera's keypoint list, - // i.e. (i,k). - // @param Map from (i1,i2) image pair indices to (K,2) matrix, for K - // correspondence indices, from each image. - // @param Length-N list of keypoints, for N images/cameras. - std::vector generate_tracks_from_pairwise_matches( - const MatchIndicesMap& matches_dict, - const KeypointsList& keypoints_list) - { - std::vector track_2d_list; - - std::cout << "[SfmTrack2d] Starting Union-Find..." << std::endl; - // Generate the DSF to form tracks. - DSFMapIndexPair dsf; - - for (const auto& kv: matches_dict) { - const auto pair_idxs = kv.first; - const auto corr_idxs = kv.second; - - // Image pair is (i1,i2). - size_t i1 = pair_idxs.first; - size_t i2 = pair_idxs.second; - for (size_t k = 0; k < corr_idxs.rows(); k++) - { - // Measurement indices are found in a single matrix row, as (k1,k2). - size_t k1 = corr_idxs(k,0); - size_t k2 = corr_idxs(k,1); - // Unique keys for the DSF are (i,k), representing keypoint index in an image. - dsf.merge(IndexPair(i1, k1), IndexPair(i2, k2)); - } +class DsfTrackGenerator { + + public: + /** Default constructor. */ + DsfTrackGenerator() {} + + // Creates a list of tracks from 2d point correspondences. + // + // Creates a disjoint-set forest (DSF) and 2d tracks from pairwise matches. + // We create a singleton for union-find set elements from camera index of a + // detection and the index of that detection in that camera's keypoint list, + // i.e. (i,k). + // @param Map from (i1,i2) image pair indices to (K,2) matrix, for K + // correspondence indices, from each image. + // @param Length-N list of keypoints, for N images/cameras. + std::vector generate_tracks_from_pairwise_matches( + const MatchIndicesMap& matches_dict, + const KeypointsList& keypoints_list) { + std::vector track_2d_list; + + std::cout << "[SfmTrack2d] Starting Union-Find..." << std::endl; + // Generate the DSF to form tracks. + DSFMapIndexPair dsf; + + for (const auto& kv : matches_dict) { + const auto pair_idxs = kv.first; + const auto corr_idxs = kv.second; + + // Image pair is (i1,i2). + size_t i1 = pair_idxs.first; + size_t i2 = pair_idxs.second; + for (size_t k = 0; k < corr_idxs.rows(); k++) + { + // Measurement indices are found in a single matrix row, as (k1,k2). + size_t k1 = corr_idxs(k, 0); + size_t k2 = corr_idxs(k, 1); + // Unique keys for the DSF are (i,k), representing keypoint index in an image. + dsf.merge(IndexPair(i1, k1), IndexPair(i2, k2)); } + } - std::cout << "[SfmTrack2d] Union-Find Complete" << std::endl; - const std::map > key_sets = dsf.sets(); - - // Return immediately if no sets were found. - if (key_sets.empty()) return track_2d_list; - - size_t erroneous_track_count = 0; - // Create a list of tracks. - // Each track will be represented as a list of (camera_idx, measurements). - for (const auto& kv: key_sets) { - const auto set_id = kv.first; - const auto index_pair_set = kv.second; - - // Initialize track from measurements. - SfmTrack2d track_2d; - - for (const auto& index_pair: index_pair_set) - { - // Camera index is represented by i, and measurement index is represented by k. - size_t i = index_pair.i(); - size_t k = index_pair.j(); - // Add measurement to this track. - track_2d.addMeasurement(NamedSfmMeasurement(i, keypoints_list[i].coordinates.row(k))); - } - - // Skip erroneous track that had repeated measurements within the same image. - // This is an expected result from an incorrect correspondence slipping through. - if (track_2d.has_unique_cameras()) - { - track_2d_list.emplace_back(track_2d); - } else { - erroneous_track_count++; - } + std::cout << "[SfmTrack2d] Union-Find Complete" << std::endl; + const std::map > key_sets = dsf.sets(); + + // Return immediately if no sets were found. + if (key_sets.empty()) return track_2d_list; + + size_t erroneous_track_count = 0; + // Create a list of tracks. + // Each track will be represented as a list of (camera_idx, measurements). + for (const auto& kv : key_sets) { + const auto set_id = kv.first; + const auto index_pair_set = kv.second; + + // Initialize track from measurements. + SfmTrack2d track_2d; + + for (const auto& index_pair : index_pair_set) + { + // Camera index is represented by i, and measurement index is represented by k. + size_t i = index_pair.i(); + size_t k = index_pair.j(); + // Add measurement to this track. + track_2d.addMeasurement(NamedSfmMeasurement(i, keypoints_list[i].coordinates.row(k))); } - double erroneous_track_pct = static_cast(erroneous_track_count) - / static_cast(key_sets.size()) * 100; - // TODO(johnwlambert): restrict decimal places to 2 decimals. - std::cout << "DSF Union-Find: " << erroneous_track_pct; - std::cout << "% of tracks discarded from multiple obs. in a single image." << std::endl; - - // TODO(johnwlambert): return the Transitivity failure percentage here. - return track_2d_list; + // Skip erroneous track that had repeated measurements within the same image. + // This is an expected result from an incorrect correspondence slipping through. + if (track_2d.hasUniqueCameras()) + { + track_2d_list.emplace_back(track_2d); + } else { + erroneous_track_count++; + } } + + double erroneous_track_pct = static_cast(erroneous_track_count) + / static_cast(key_sets.size()) * 100; + // TODO(johnwlambert): restrict decimal places to 2 decimals. + std::cout << "DSF Union-Find: " << erroneous_track_pct; + std::cout << "% of tracks discarded from multiple obs. in a single image." << std::endl; + + // TODO(johnwlambert): return the Transitivity failure percentage here. + return track_2d_list; + } }; } // namespace gtsam diff --git a/gtsam/sfm/sfm.i b/gtsam/sfm/sfm.i index 2a683a032c..b46b308eb6 100644 --- a/gtsam/sfm/sfm.i +++ b/gtsam/sfm/sfm.i @@ -17,6 +17,13 @@ class MatchIndicesMap { }; +class Keypoints +{ + Keypoints(const gtsam::KeypointCoordinates& coordinates); + gtsam::KeypointCoordinates coordinates; +}; // check if this should be a method + + class KeypointsList { KeypointsList(); KeypointsList(const gtsam::KeypointsList& other); @@ -28,13 +35,6 @@ class KeypointsList { }; -class Keypoints -{ - Keypoints(const gtsam::KeypointCoordinates& coordinates); - gtsam::KeypointCoordinates coordinates; -}; // check if this should be a method - - class NamedSfmMeasurement { size_t i; @@ -46,7 +46,7 @@ class SfmTrack2d { void addMeasurement(const gtsam::NamedSfmMeasurement &m); std::vector measurements(); - bool has_unique_cameras(); + bool hasUniqueCameras(); }; From 720145ae672274493fbc4f9b1b8718608141adb1 Mon Sep 17 00:00:00 2001 From: senselessdev1 Date: Sun, 24 Jul 2022 03:07:04 -0400 Subject: [PATCH 0111/1497] remove unnecessary extra typedef --- gtsam/sfm/DsfTrackGenerator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtsam/sfm/DsfTrackGenerator.h b/gtsam/sfm/DsfTrackGenerator.h index 18c96653a1..5ab87a7dfa 100644 --- a/gtsam/sfm/DsfTrackGenerator.h +++ b/gtsam/sfm/DsfTrackGenerator.h @@ -31,7 +31,6 @@ namespace gtsam { typedef DSFMap DSFMapIndexPair; -typedef std::pair ImagePair; typedef Eigen::MatrixX2i CorrespondenceIndices; // N x 2 array //struct Keypoints; @@ -49,7 +48,8 @@ struct Keypoints { using KeypointsList = std::vector; using KeypointsVector = std::vector; // TODO(johnwlambert): prefer KeypointsSet? -using MatchIndicesMap = std::map; +// Mapping from each image pair to (N,2) array representing indices of matching keypoints. +using MatchIndicesMap = std::map; // @param camera index From eb6e56a4f889426b4d07ab85052fa42498dd97d8 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 25 Jul 2022 17:20:09 -0400 Subject: [PATCH 0112/1497] Mark JacobianVector as opaque --- python/gtsam/preamble/base.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/gtsam/preamble/base.h b/python/gtsam/preamble/base.h index d07a75f6fb..b1ed2ba141 100644 --- a/python/gtsam/preamble/base.h +++ b/python/gtsam/preamble/base.h @@ -10,3 +10,5 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ + +PYBIND11_MAKE_OPAQUE(std::vector); // JacobianVector From 27951b7b180f7cdfc3300fb9d8d163586fb9f305 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 25 Jul 2022 22:17:48 -0400 Subject: [PATCH 0113/1497] use python 3.7 --- .github/scripts/python.sh | 2 +- .github/workflows/build-python.yml | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/scripts/python.sh b/.github/scripts/python.sh index 0855dbc21b..b734f59191 100644 --- a/.github/scripts/python.sh +++ b/.github/scripts/python.sh @@ -59,7 +59,7 @@ PATH=$PATH:$($PYTHON -c "import site; print(site.USER_BASE)")/bin BUILD_PYBIND="ON" -sudo $PYTHON -m pip install -r $GITHUB_WORKSPACE/python/requirements.txt +$PYTHON -m pip install -r $GITHUB_WORKSPACE/python/requirements.txt mkdir $GITHUB_WORKSPACE/build cd $GITHUB_WORKSPACE/build diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml index f80b9362c9..d391e571c0 100644 --- a/.github/workflows/build-python.yml +++ b/.github/workflows/build-python.yml @@ -27,7 +27,7 @@ jobs: ] build_type: [Debug, Release] - python_version: [3] + python_version: [3.7] include: - name: ubuntu-18.04-gcc-5 os: ubuntu-18.04 @@ -44,14 +44,6 @@ jobs: compiler: clang version: "9" - # NOTE temporarily added this as it is a required check. - - name: ubuntu-18.04-clang-9 - os: ubuntu-18.04 - compiler: clang - version: "9" - build_type: Debug - python_version: "3" - - name: macOS-11-xcode-13.4.1 os: macOS-11 compiler: xcode @@ -65,7 +57,11 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.7' - name: Install (Linux) if: runner.os == 'Linux' run: | From 4edcb41ad3680a9d4f6ee2f829c8ffd49b2bdba8 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 25 Jul 2022 22:19:05 -0400 Subject: [PATCH 0114/1497] remove redundant KeyVector definition --- gtsam/gtsam.i | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/gtsam/gtsam.i b/gtsam/gtsam.i index d4e959c3dd..2671f0ef77 100644 --- a/gtsam/gtsam.i +++ b/gtsam/gtsam.i @@ -66,27 +66,6 @@ class KeySet { void serialize() const; }; -// Actually a vector -class KeyVector { - KeyVector(); - KeyVector(const gtsam::KeyVector& other); - - // Note: no print function - - // common STL methods - size_t size() const; - bool empty() const; - void clear(); - - // structure specific methods - size_t at(size_t i) const; - size_t front() const; - size_t back() const; - void push_back(size_t key) const; - - void serialize() const; -}; - // Actually a FastMap class KeyGroupMap { KeyGroupMap(); From 42bab8f3e70eee07a2ae591786f3b2a297b6784a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 25 Jul 2022 22:19:29 -0400 Subject: [PATCH 0115/1497] use KeyVector for GNC inliers & outliers --- gtsam/nonlinear/GncParams.h | 12 ++++++++---- gtsam/nonlinear/nonlinear.i | 8 ++++---- python/gtsam/preamble/nonlinear.h | 2 -- python/gtsam/specializations/nonlinear.h | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gtsam/nonlinear/GncParams.h b/gtsam/nonlinear/GncParams.h index a7ccb88b76..08ae423366 100644 --- a/gtsam/nonlinear/GncParams.h +++ b/gtsam/nonlinear/GncParams.h @@ -72,8 +72,12 @@ class GTSAM_EXPORT GncParams { double relativeCostTol = 1e-5; ///< If relative cost change is below this threshold, stop iterating double weightsTol = 1e-4; ///< If the weights are within weightsTol from being binary, stop iterating (only for TLS) Verbosity verbosity = SILENT; ///< Verbosity level - std::vector knownInliers = std::vector(); ///< Slots in the factor graph corresponding to measurements that we know are inliers - std::vector knownOutliers = std::vector(); ///< Slots in the factor graph corresponding to measurements that we know are outliers + + // *NOTE* We use KeyVector for inliers and outliers since it is fast + wrapping + ///< Slots in the factor graph corresponding to measurements that we know are inliers + KeyVector knownInliers = KeyVector(); + ///< Slots in the factor graph corresponding to measurements that we know are outliers + KeyVector knownOutliers = KeyVector(); /// Set the robust loss function to be used in GNC (chosen among the ones in GncLossType). void setLossType(const GncLossType type) { @@ -114,7 +118,7 @@ class GTSAM_EXPORT GncParams { * This functionality is commonly used in SLAM when one may assume the odometry is outlier free, and * only apply GNC to prune outliers from the loop closures. * */ - void setKnownInliers(const std::vector& knownIn) { + void setKnownInliers(const KeyVector& knownIn) { for (size_t i = 0; i < knownIn.size(); i++){ knownInliers.push_back(knownIn[i]); } @@ -125,7 +129,7 @@ class GTSAM_EXPORT GncParams { * corresponds to the slots in the factor graph. For instance, if you have a nonlinear factor graph nfg, * and you provide knownOut = {0, 2, 15}, GNC will not apply outlier rejection to nfg[0], nfg[2], and nfg[15]. * */ - void setKnownOutliers(const std::vector& knownOut) { + void setKnownOutliers(const KeyVector& knownOut) { for (size_t i = 0; i < knownOut.size(); i++){ knownOutliers.push_back(knownOut[i]); } diff --git a/gtsam/nonlinear/nonlinear.i b/gtsam/nonlinear/nonlinear.i index c793332368..4bb80a0d62 100644 --- a/gtsam/nonlinear/nonlinear.i +++ b/gtsam/nonlinear/nonlinear.i @@ -529,8 +529,8 @@ virtual class GncParams { double relativeCostTol; double weightsTol; Verbosity verbosity; - std::vector knownInliers; - std::vector knownOutliers; + gtsam::KeyVector knownInliers; + gtsam::KeyVector knownOutliers; void setLossType(const gtsam::GncLossType type); void setMaxIterations(const size_t maxIter); @@ -538,8 +538,8 @@ virtual class GncParams { void setRelativeCostTol(double value); void setWeightsTol(double value); void setVerbosityGNC(const gtsam::This::Verbosity value); - void setKnownInliers(const std::vector& knownIn); - void setKnownOutliers(const std::vector& knownOut); + void setKnownInliers(const gtsam::KeyVector& knownIn); + void setKnownOutliers(const gtsam::KeyVector& knownOut); void print(const string& str = "GncParams: ") const; enum Verbosity { diff --git a/python/gtsam/preamble/nonlinear.h b/python/gtsam/preamble/nonlinear.h index 56a07cfdd1..d07a75f6fb 100644 --- a/python/gtsam/preamble/nonlinear.h +++ b/python/gtsam/preamble/nonlinear.h @@ -10,5 +10,3 @@ * Without this they will be automatically converted to a Python object, and all * mutations on Python side will not be reflected on C++. */ - -#include diff --git a/python/gtsam/specializations/nonlinear.h b/python/gtsam/specializations/nonlinear.h index d46ccdc668..da8842eaf4 100644 --- a/python/gtsam/specializations/nonlinear.h +++ b/python/gtsam/specializations/nonlinear.h @@ -9,4 +9,4 @@ * interface, but without the `` copying mechanism. Combined * with `PYBIND11_MAKE_OPAQUE` this allows the types to be modified with Python, * and saves one copy operation. - */ \ No newline at end of file + */ From 8ddc2ea989d17abb4b8fc551176a3bc411cdae71 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 07:15:48 -0400 Subject: [PATCH 0116/1497] rename to HybridNonlinearFactorGraph --- ...orGraph.h => HybridNonlinearFactorGraph.h} | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) rename gtsam/hybrid/{NonlinearHybridFactorGraph.h => HybridNonlinearFactorGraph.h} (92%) diff --git a/gtsam/hybrid/NonlinearHybridFactorGraph.h b/gtsam/hybrid/HybridNonlinearFactorGraph.h similarity index 92% rename from gtsam/hybrid/NonlinearHybridFactorGraph.h rename to gtsam/hybrid/HybridNonlinearFactorGraph.h index 82a331531e..c54a1057e2 100644 --- a/gtsam/hybrid/NonlinearHybridFactorGraph.h +++ b/gtsam/hybrid/HybridNonlinearFactorGraph.h @@ -10,7 +10,7 @@ * -------------------------------------------------------------------------- */ /** - * @file NonlinearHybridFactorGraph.h + * @file HybridNonlinearFactorGraph.h * @brief Nonlinear hybrid factor graph that uses type erasure * @author Varun Agrawal * @date May 28, 2022 @@ -35,7 +35,7 @@ namespace gtsam { * This is the non-linear version of a hybrid factor graph. * Everything inside needs to be hybrid factor or hybrid conditional. */ -class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { +class GTSAM_EXPORT HybridNonlinearFactorGraph : public HybridFactorGraph { protected: /// Check if FACTOR type is derived from NonlinearFactor. template @@ -44,7 +44,7 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { public: using Base = HybridFactorGraph; - using This = NonlinearHybridFactorGraph; ///< this class + using This = HybridNonlinearFactorGraph; ///< this class using shared_ptr = boost::shared_ptr; ///< shared_ptr to This using Values = gtsam::Values; ///< backwards compatibility @@ -53,7 +53,7 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { /// @name Constructors /// @{ - NonlinearHybridFactorGraph() = default; + HybridNonlinearFactorGraph() = default; /** * Implicit copy/downcast constructor to override explicit template container @@ -61,7 +61,7 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { * `cachedSeparatorMarginal_.reset(*separatorMarginal)` * */ template - NonlinearHybridFactorGraph(const FactorGraph& graph) + HybridNonlinearFactorGraph(const FactorGraph& graph) : Base(graph) {} /// @} @@ -131,21 +131,21 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { * Simply prints the factor graph. */ void print( - const std::string& str = "NonlinearHybridFactorGraph", + const std::string& str = "HybridNonlinearFactorGraph", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {} /** * @return true if all internal graphs of `this` are equal to those of * `other` */ - bool equals(const NonlinearHybridFactorGraph& other, + bool equals(const HybridNonlinearFactorGraph& other, double tol = 1e-9) const { return false; } /** * @brief Linearize all the continuous factors in the - * NonlinearHybridFactorGraph. + * HybridNonlinearFactorGraph. * * @param continuousValues: Dictionary of continuous values. * @return GaussianHybridFactorGraph::shared_ptr @@ -200,7 +200,7 @@ class GTSAM_EXPORT NonlinearHybridFactorGraph : public HybridFactorGraph { }; template <> -struct traits - : public Testable {}; +struct traits + : public Testable {}; } // namespace gtsam From 7a55341e3202ad2aac6a1f8521e7b2794c639f7d Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 07:21:05 -0400 Subject: [PATCH 0117/1497] add IsGaussian template check --- gtsam/hybrid/HybridGaussianFactorGraph.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gtsam/hybrid/HybridGaussianFactorGraph.h b/gtsam/hybrid/HybridGaussianFactorGraph.h index b98654b92b..ca9d8049ea 100644 --- a/gtsam/hybrid/HybridGaussianFactorGraph.h +++ b/gtsam/hybrid/HybridGaussianFactorGraph.h @@ -75,8 +75,14 @@ struct EliminationTraits { * Everything inside needs to be hybrid factor or hybrid conditional. */ class GTSAM_EXPORT HybridGaussianFactorGraph - : public HybridFactorGraph,, + : public HybridFactorGraph, public EliminateableFactorGraph { + protected: + /// Check if FACTOR type is derived from GaussianFactor. + template + using IsGaussian = typename std::enable_if< + std::is_base_of::value>::type; + public: using Base = HybridFactorGraph; using This = HybridGaussianFactorGraph; ///< this class From 43c28e7870661214f9024c7ed67d4e63c3fb823a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 07:40:24 -0400 Subject: [PATCH 0118/1497] renaming fixes --- gtsam/hybrid/HybridNonlinearFactorGraph.h | 8 +-- ...cpp => testHybridNonlinearFactorGraph.cpp} | 61 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) rename gtsam/hybrid/tests/{testNonlinearHybridFactorGraph.cpp => testHybridNonlinearFactorGraph.cpp} (94%) diff --git a/gtsam/hybrid/HybridNonlinearFactorGraph.h b/gtsam/hybrid/HybridNonlinearFactorGraph.h index c54a1057e2..f1396bcc0c 100644 --- a/gtsam/hybrid/HybridNonlinearFactorGraph.h +++ b/gtsam/hybrid/HybridNonlinearFactorGraph.h @@ -18,7 +18,7 @@ #pragma once -#include +#include #include #include #include @@ -148,11 +148,11 @@ class GTSAM_EXPORT HybridNonlinearFactorGraph : public HybridFactorGraph { * HybridNonlinearFactorGraph. * * @param continuousValues: Dictionary of continuous values. - * @return GaussianHybridFactorGraph::shared_ptr + * @return HybridGaussianFactorGraph::shared_ptr */ - GaussianHybridFactorGraph linearize(const Values& continuousValues) const { + HybridGaussianFactorGraph linearize(const Values& continuousValues) const { // create an empty linear FG - GaussianHybridFactorGraph linearFG; + HybridGaussianFactorGraph linearFG; linearFG.reserve(size()); diff --git a/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp b/gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp similarity index 94% rename from gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp rename to gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp index 6e40199921..6c5e949212 100644 --- a/gtsam/hybrid/tests/testNonlinearHybridFactorGraph.cpp +++ b/gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp @@ -7,8 +7,8 @@ * -------------------------------------------------------------------------- */ /** - * @file testDCFactorGraph.cpp - * @brief Unit tests for DCFactorGraph + * @file testHybridNonlinearFactorGraph.cpp + * @brief Unit tests for HybridNonlinearFactorGraph * @author Varun Agrawal * @author Fan Jiang * @author Frank Dellaert @@ -22,9 +22,8 @@ #include #include #include -#include +#include #include -#include #include #include #include @@ -49,7 +48,7 @@ using symbol_shorthand::X; * existing gaussian factor graph in the hybrid factor graph. */ TEST(HybridFactorGraph, GaussianFactorGraph) { - NonlinearHybridFactorGraph fg; + HybridNonlinearFactorGraph fg; // Add a simple prior factor to the nonlinear factor graph fg.emplace_nonlinear>(X(0), 0, Isotropic::Sigma(1, 0.1)); @@ -58,7 +57,7 @@ TEST(HybridFactorGraph, GaussianFactorGraph) { Values linearizationPoint; linearizationPoint.insert(X(0), 0); - GaussianHybridFactorGraph ghfg = fg.linearize(linearizationPoint); + HybridGaussianFactorGraph ghfg = fg.linearize(linearizationPoint); // Add a factor to the GaussianFactorGraph ghfg.add(JacobianFactor(X(0), I_1x1, Vector1(5))); @@ -69,9 +68,9 @@ TEST(HybridFactorGraph, GaussianFactorGraph) { /* ************************************************************************** */ /// Test that the resize method works correctly for a -/// NonlinearHybridFactorGraph. -TEST(NonlinearHybridFactorGraph, Resize) { - NonlinearHybridFactorGraph fg; +/// HybridNonlinearFactorGraph. +TEST(HybridNonlinearFactorGraph, Resize) { + HybridNonlinearFactorGraph fg; auto nonlinearFactor = boost::make_shared>(); fg.push_back(nonlinearFactor); @@ -90,9 +89,9 @@ TEST(NonlinearHybridFactorGraph, Resize) { /* ************************************************************************** */ /// Test that the resize method works correctly for a -/// GaussianHybridFactorGraph. -TEST(GaussianHybridFactorGraph, Resize) { - NonlinearHybridFactorGraph nhfg; +/// HybridGaussianFactorGraph. +TEST(HybridGaussianFactorGraph, Resize) { + HybridNonlinearFactorGraph nhfg; auto nonlinearFactor = boost::make_shared>( X(0), X(1), 0.0, Isotropic::Sigma(1, 0.1)); nhfg.push_back(nonlinearFactor); @@ -115,8 +114,8 @@ TEST(GaussianHybridFactorGraph, Resize) { linearizationPoint.insert(X(0), 0); linearizationPoint.insert(X(1), 1); - // Generate `GaussianHybridFactorGraph` by linearizing - GaussianHybridFactorGraph gfg = nhfg.linearize(linearizationPoint); + // Generate `HybridGaussianFactorGraph` by linearizing + HybridGaussianFactorGraph gfg = nhfg.linearize(linearizationPoint); EXPECT_LONGS_EQUAL(gfg.size(), 3); @@ -129,41 +128,41 @@ TEST(GaussianHybridFactorGraph, Resize) { * Test push_back on HFG makes the correct distinction. */ TEST(HybridFactorGraph, PushBack) { - NonlinearHybridFactorGraph fg; + HybridNonlinearFactorGraph fg; auto nonlinearFactor = boost::make_shared>(); fg.push_back(nonlinearFactor); EXPECT_LONGS_EQUAL(fg.size(), 1); - fg = NonlinearHybridFactorGraph(); + fg = HybridNonlinearFactorGraph(); auto discreteFactor = boost::make_shared(); fg.push_back(discreteFactor); EXPECT_LONGS_EQUAL(fg.size(), 1); - fg = NonlinearHybridFactorGraph(); + fg = HybridNonlinearFactorGraph(); auto dcFactor = boost::make_shared(); fg.push_back(dcFactor); EXPECT_LONGS_EQUAL(fg.size(), 1); - // Now do the same with GaussianHybridFactorGraph - GaussianHybridFactorGraph ghfg; + // Now do the same with HybridGaussianFactorGraph + HybridGaussianFactorGraph ghfg; auto gaussianFactor = boost::make_shared(); ghfg.push_back(gaussianFactor); EXPECT_LONGS_EQUAL(ghfg.size(), 1); - ghfg = GaussianHybridFactorGraph(); + ghfg = HybridGaussianFactorGraph(); ghfg.push_back(discreteFactor); EXPECT_LONGS_EQUAL(ghfg.size(), 1); - ghfg = GaussianHybridFactorGraph(); + ghfg = HybridGaussianFactorGraph(); ghfg.push_back(dcFactor); EXPECT_LONGS_EQUAL(ghfg.size(), 1); @@ -193,7 +192,7 @@ TEST(HybridFactorGraph, PushBack) { // Switching self(3); // // Linearize here: -// GaussianHybridFactorGraph actualLinearized = +// HybridGaussianFactorGraph actualLinearized = // self.nonlinearFactorGraph.linearize(self.linearizationPoint); // EXPECT_LONGS_EQUAL(8, actualLinearized.size()); @@ -224,7 +223,7 @@ TEST(HybridFactorGraph, PushBack) { // Switching self(3); // // Gather factors on x1, has a simple Gaussian and a mixture factor. -// GaussianHybridFactorGraph factors; +// HybridGaussianFactorGraph factors; // factors.push_gaussian(self.linearizedFactorGraph.gaussianGraph()[0]); // factors.push_dc(self.linearizedFactorGraph.dcGraph()[0]); @@ -255,7 +254,7 @@ TEST(HybridFactorGraph, PushBack) { // Switching self(3); // // Gather factors on x2, will be two mixture factors (with x1 and x3, -// resp.). GaussianHybridFactorGraph factors; +// resp.). HybridGaussianFactorGraph factors; // factors.push_dc(self.linearizedFactorGraph.dcGraph()[0]); // involves m1 // factors.push_dc(self.linearizedFactorGraph.dcGraph()[1]); // involves m2 @@ -355,7 +354,7 @@ TEST(HybridFactorGraph, PushBack) { // Switching self(K, between_sigma, prior_sigma); // // Clear out discrete factors since sum() cannot hanldle those -// GaussianHybridFactorGraph linearizedFactorGraph( +// HybridGaussianFactorGraph linearizedFactorGraph( // self.linearizedFactorGraph.gaussianGraph(), DiscreteFactorGraph(), // self.linearizedFactorGraph.dcGraph()); @@ -400,7 +399,7 @@ TEST(HybridFactorGraph, PushBack) { // // Eliminate partially. // HybridBayesNet::shared_ptr hybridBayesNet; -// GaussianHybridFactorGraph::shared_ptr remainingFactorGraph; +// HybridGaussianFactorGraph::shared_ptr remainingFactorGraph; // std::tie(hybridBayesNet, remainingFactorGraph) = // linearizedFactorGraph.eliminatePartialSequential(ordering); @@ -435,7 +434,7 @@ TEST(HybridFactorGraph, PushBack) { // // We first do a partial elimination // HybridBayesNet::shared_ptr hybridBayesNet_partial; -// GaussianHybridFactorGraph::shared_ptr remainingFactorGraph_partial; +// HybridGaussianFactorGraph::shared_ptr remainingFactorGraph_partial; // DiscreteBayesNet discreteBayesNet; // { @@ -500,7 +499,7 @@ TEST(HybridFactorGraph, PushBack) { // // Eliminate partially. // HybridBayesNet::shared_ptr hybridBayesNet; -// GaussianHybridFactorGraph::shared_ptr remainingFactorGraph; +// HybridGaussianFactorGraph::shared_ptr remainingFactorGraph; // std::tie(hybridBayesNet, remainingFactorGraph) = // linearizedFactorGraph.eliminatePartialSequential(ordering); @@ -678,7 +677,7 @@ TEST(HybridFactorGraph, PushBack) { // // issue arises if we eliminate a landmark variable first since it is not // // connected to a DCFactor. // TEST(HybridFactorGraph, DefaultDecisionTree) { -// NonlinearHybridFactorGraph fg; +// HybridNonlinearFactorGraph fg; // // Add a prior on pose x1 at the origin. A prior factor consists of a mean // and @@ -732,9 +731,9 @@ TEST(HybridFactorGraph, PushBack) { // ordering += X(0); // ordering += X(1); -// GaussianHybridFactorGraph linearized = fg.linearize(initialEstimate); +// HybridGaussianFactorGraph linearized = fg.linearize(initialEstimate); // gtsam::HybridBayesNet::shared_ptr hybridBayesNet; -// gtsam::GaussianHybridFactorGraph::shared_ptr remainingFactorGraph; +// gtsam::HybridGaussianFactorGraph::shared_ptr remainingFactorGraph; // // This should NOT fail // std::tie(hybridBayesNet, remainingFactorGraph) = From 1d51c4e64692f0792685d4d50873ba00ef61d238 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 07:54:05 -0400 Subject: [PATCH 0119/1497] Use new GncParams::IndexVector --- gtsam/nonlinear/GncParams.h | 12 +++++++----- tests/testGncOptimizer.cpp | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/gtsam/nonlinear/GncParams.h b/gtsam/nonlinear/GncParams.h index 08ae423366..e069d5f3d9 100644 --- a/gtsam/nonlinear/GncParams.h +++ b/gtsam/nonlinear/GncParams.h @@ -73,11 +73,13 @@ class GTSAM_EXPORT GncParams { double weightsTol = 1e-4; ///< If the weights are within weightsTol from being binary, stop iterating (only for TLS) Verbosity verbosity = SILENT; ///< Verbosity level - // *NOTE* We use KeyVector for inliers and outliers since it is fast + wrapping + //TODO(Varun) replace IndexVector with vector once pybind11/stl.h is globally enabled. + /// Use IndexVector for inliers and outliers since it is fast + wrapping + using IndexVector = FastVector; ///< Slots in the factor graph corresponding to measurements that we know are inliers - KeyVector knownInliers = KeyVector(); + IndexVector knownInliers = IndexVector(); ///< Slots in the factor graph corresponding to measurements that we know are outliers - KeyVector knownOutliers = KeyVector(); + IndexVector knownOutliers = IndexVector(); /// Set the robust loss function to be used in GNC (chosen among the ones in GncLossType). void setLossType(const GncLossType type) { @@ -118,7 +120,7 @@ class GTSAM_EXPORT GncParams { * This functionality is commonly used in SLAM when one may assume the odometry is outlier free, and * only apply GNC to prune outliers from the loop closures. * */ - void setKnownInliers(const KeyVector& knownIn) { + void setKnownInliers(const IndexVector& knownIn) { for (size_t i = 0; i < knownIn.size(); i++){ knownInliers.push_back(knownIn[i]); } @@ -129,7 +131,7 @@ class GTSAM_EXPORT GncParams { * corresponds to the slots in the factor graph. For instance, if you have a nonlinear factor graph nfg, * and you provide knownOut = {0, 2, 15}, GNC will not apply outlier rejection to nfg[0], nfg[2], and nfg[15]. * */ - void setKnownOutliers(const KeyVector& knownOut) { + void setKnownOutliers(const IndexVector& knownOut) { for (size_t i = 0; i < knownOut.size(); i++){ knownOutliers.push_back(knownOut[i]); } diff --git a/tests/testGncOptimizer.cpp b/tests/testGncOptimizer.cpp index c3335ce20c..15d660114f 100644 --- a/tests/testGncOptimizer.cpp +++ b/tests/testGncOptimizer.cpp @@ -567,7 +567,7 @@ TEST(GncOptimizer, optimizeWithKnownInliers) { Values initial; initial.insert(X(1), p0); - std::vector knownInliers; + GncParams::IndexVector knownInliers; knownInliers.push_back(0); knownInliers.push_back(1); knownInliers.push_back(2); @@ -644,7 +644,7 @@ TEST(GncOptimizer, barcsq) { Values initial; initial.insert(X(1), p0); - std::vector knownInliers; + GncParams::IndexVector knownInliers; knownInliers.push_back(0); knownInliers.push_back(1); knownInliers.push_back(2); @@ -691,7 +691,7 @@ TEST(GncOptimizer, setInlierCostThresholds) { Values initial; initial.insert(X(1), p0); - std::vector knownInliers; + GncParams::IndexVector knownInliers; knownInliers.push_back(0); knownInliers.push_back(1); knownInliers.push_back(2); @@ -763,7 +763,7 @@ TEST(GncOptimizer, optimizeSmallPoseGraph) { // GNC // Note: in difficult instances, we set the odometry measurements to be // inliers, but this problem is simple enought to succeed even without that - // assumption std::vector knownInliers; + // assumption GncParams::IndexVector knownInliers; GncParams gncParams; auto gnc = GncOptimizer>(*graph, *initial, gncParams); @@ -784,12 +784,12 @@ TEST(GncOptimizer, knownInliersAndOutliers) { // nonconvexity with known inliers and known outliers (check early stopping // when all measurements are known to be inliers or outliers) { - std::vector knownInliers; + GncParams::IndexVector knownInliers; knownInliers.push_back(0); knownInliers.push_back(1); knownInliers.push_back(2); - std::vector knownOutliers; + GncParams::IndexVector knownOutliers; knownOutliers.push_back(3); GncParams gncParams; @@ -813,11 +813,11 @@ TEST(GncOptimizer, knownInliersAndOutliers) { // nonconvexity with known inliers and known outliers { - std::vector knownInliers; + GncParams::IndexVector knownInliers; knownInliers.push_back(2); knownInliers.push_back(0); - std::vector knownOutliers; + GncParams::IndexVector knownOutliers; knownOutliers.push_back(3); GncParams gncParams; @@ -841,7 +841,7 @@ TEST(GncOptimizer, knownInliersAndOutliers) { // only known outliers { - std::vector knownOutliers; + GncParams::IndexVector knownOutliers; knownOutliers.push_back(3); GncParams gncParams; @@ -916,11 +916,11 @@ TEST(GncOptimizer, setWeights) { // initialize weights and also set known inliers/outliers { GncParams gncParams; - std::vector knownInliers; + GncParams::IndexVector knownInliers; knownInliers.push_back(2); knownInliers.push_back(0); - std::vector knownOutliers; + GncParams::IndexVector knownOutliers; knownOutliers.push_back(3); gncParams.setKnownInliers(knownInliers); gncParams.setKnownOutliers(knownOutliers); From d92ce6ba9afe226370bfdecf95e4b04febc91466 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 13:11:21 -0400 Subject: [PATCH 0120/1497] break up Python CI steps so reading logs is easier --- .github/scripts/python.sh | 87 ++++++++++++++++++------------ .github/workflows/build-python.yml | 13 ++--- 2 files changed, 61 insertions(+), 39 deletions(-) diff --git a/.github/scripts/python.sh b/.github/scripts/python.sh index 0855dbc21b..662c4196ea 100644 --- a/.github/scripts/python.sh +++ b/.github/scripts/python.sh @@ -43,46 +43,67 @@ if [ -z ${PYTHON_VERSION+x} ]; then exit 127 fi -PYTHON="python${PYTHON_VERSION}" +export PYTHON="python${PYTHON_VERSION}" -if [[ $(uname) == "Darwin" ]]; then +function install_dependencies() +{ + if [[ $(uname) == "Darwin" ]]; then brew install wget -else + else # Install a system package required by our library sudo apt-get install -y wget libicu-dev python3-pip python3-setuptools -fi - -PATH=$PATH:$($PYTHON -c "import site; print(site.USER_BASE)")/bin - -[ "${GTSAM_WITH_TBB:-OFF}" = "ON" ] && install_tbb - - -BUILD_PYBIND="ON" + fi -sudo $PYTHON -m pip install -r $GITHUB_WORKSPACE/python/requirements.txt + export PATH=$PATH:$($PYTHON -c "import site; print(site.USER_BASE)")/bin -mkdir $GITHUB_WORKSPACE/build -cd $GITHUB_WORKSPACE/build + [ "${GTSAM_WITH_TBB:-OFF}" = "ON" ] && install_tbb -cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ - -DGTSAM_BUILD_TESTS=OFF \ - -DGTSAM_BUILD_UNSTABLE=${GTSAM_BUILD_UNSTABLE:-ON} \ - -DGTSAM_USE_QUATERNIONS=OFF \ - -DGTSAM_WITH_TBB=${GTSAM_WITH_TBB:-OFF} \ - -DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \ - -DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF \ - -DGTSAM_BUILD_PYTHON=${BUILD_PYBIND} \ - -DGTSAM_UNSTABLE_BUILD_PYTHON=${GTSAM_BUILD_UNSTABLE:-ON} \ - -DGTSAM_PYTHON_VERSION=$PYTHON_VERSION \ - -DPYTHON_EXECUTABLE:FILEPATH=$(which $PYTHON) \ - -DGTSAM_ALLOW_DEPRECATED_SINCE_V42=OFF \ - -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/gtsam_install + $PYTHON -m pip install -r $GITHUB_WORKSPACE/python/requirements.txt +} +function build() +{ + mkdir $GITHUB_WORKSPACE/build + cd $GITHUB_WORKSPACE/build + + BUILD_PYBIND="ON" + + cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \ + -DGTSAM_BUILD_TESTS=OFF \ + -DGTSAM_BUILD_UNSTABLE=${GTSAM_BUILD_UNSTABLE:-ON} \ + -DGTSAM_USE_QUATERNIONS=OFF \ + -DGTSAM_WITH_TBB=${GTSAM_WITH_TBB:-OFF} \ + -DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \ + -DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF \ + -DGTSAM_BUILD_PYTHON=${BUILD_PYBIND} \ + -DGTSAM_UNSTABLE_BUILD_PYTHON=${GTSAM_BUILD_UNSTABLE:-ON} \ + -DGTSAM_PYTHON_VERSION=$PYTHON_VERSION \ + -DPYTHON_EXECUTABLE:FILEPATH=$(which $PYTHON) \ + -DGTSAM_ALLOW_DEPRECATED_SINCE_V42=OFF \ + -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/gtsam_install + + + # Set to 2 cores so that Actions does not error out during resource provisioning. + make -j2 install + + cd $GITHUB_WORKSPACE/build/python + $PYTHON -m pip install --user . +} -# Set to 2 cores so that Actions does not error out during resource provisioning. -make -j2 install +function test() +{ + cd $GITHUB_WORKSPACE/python/gtsam/tests + $PYTHON -m unittest discover -v +} -cd $GITHUB_WORKSPACE/build/python -$PYTHON -m pip install --user . -cd $GITHUB_WORKSPACE/python/gtsam/tests -$PYTHON -m unittest discover -v +# select between build or test +case $1 in + -d) + install_dependencies + -b) + build + ;; + -t) + test + ;; +esac diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml index f80b9362c9..1e1519da60 100644 --- a/.github/workflows/build-python.yml +++ b/.github/workflows/build-python.yml @@ -117,11 +117,12 @@ jobs: uses: pierotofy/set-swap-space@master with: swap-size-gb: 6 - - name: Build (Linux) - if: runner.os == 'Linux' + - name: Install Dependencies run: | - bash .github/scripts/python.sh - - name: Build (macOS) - if: runner.os == 'macOS' + bash .github/scripts/python.sh -d + - name: Build + run: | + bash .github/scripts/python.sh -b + - name: Test run: | - bash .github/scripts/python.sh + bash .github/scripts/python.sh -t From 987448fa7784f90ba291d5bfb5764fb0b076d7ab Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 13:09:42 -0400 Subject: [PATCH 0121/1497] remove derived push_back in HybridNonlinearFactorGraph and HybridFactorGraph --- gtsam/hybrid/HybridFactorGraph.h | 8 -------- gtsam/hybrid/HybridNonlinearFactorGraph.h | 8 -------- 2 files changed, 16 deletions(-) diff --git a/gtsam/hybrid/HybridFactorGraph.h b/gtsam/hybrid/HybridFactorGraph.h index 892136b86c..2d96072b49 100644 --- a/gtsam/hybrid/HybridFactorGraph.h +++ b/gtsam/hybrid/HybridFactorGraph.h @@ -135,14 +135,6 @@ class HybridFactorGraph : public FactorGraph { push_hybrid(p); } } - - /** Constructor from iterator over factors (shared_ptr or plain objects) */ - template - void push_back(ITERATOR firstFactor, ITERATOR lastFactor) { - for (auto&& it = firstFactor; it != lastFactor; it++) { - push_back(*it); - } - } }; } // namespace gtsam diff --git a/gtsam/hybrid/HybridNonlinearFactorGraph.h b/gtsam/hybrid/HybridNonlinearFactorGraph.h index f1396bcc0c..6c5dd515fa 100644 --- a/gtsam/hybrid/HybridNonlinearFactorGraph.h +++ b/gtsam/hybrid/HybridNonlinearFactorGraph.h @@ -109,14 +109,6 @@ class GTSAM_EXPORT HybridNonlinearFactorGraph : public HybridFactorGraph { } } - /** Constructor from iterator over factors (shared_ptr or plain objects) */ - template - void push_back(ITERATOR firstFactor, ITERATOR lastFactor) { - for (auto&& it = firstFactor; it != lastFactor; it++) { - push_back(*it); - } - } - // /// Add a nonlinear factor to the factor graph. // void add(NonlinearFactor&& factor) { // Base::add(boost::make_shared(std::move(factor))); From bb5b2be792d422cf19f3da5981bbb29bb67c5c4a Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 14:03:21 -0400 Subject: [PATCH 0122/1497] fix typo --- .github/scripts/python.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/python.sh b/.github/scripts/python.sh index 662c4196ea..718eee5eaf 100644 --- a/.github/scripts/python.sh +++ b/.github/scripts/python.sh @@ -100,6 +100,7 @@ function test() case $1 in -d) install_dependencies + ;; -b) build ;; From d39cdc53e8b6c28792eed1eb3a72036c1576e8ca Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 15:51:07 -0400 Subject: [PATCH 0123/1497] update the directory list in cmake --- doc/CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 2218addcfc..f0975821fc 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -26,6 +26,7 @@ if (GTSAM_BUILD_DOCS) gtsam/basis gtsam/discrete gtsam/geometry + gtsam/hybrid gtsam/inference gtsam/linear gtsam/navigation @@ -33,7 +34,6 @@ if (GTSAM_BUILD_DOCS) gtsam/sam gtsam/sfm gtsam/slam - gtsam/smart gtsam/symbolic gtsam ) @@ -42,10 +42,12 @@ if (GTSAM_BUILD_DOCS) set(gtsam_unstable_doc_subdirs gtsam_unstable/base gtsam_unstable/discrete + gtsam_unstable/dynamics + gtsam_unstable/geometry gtsam_unstable/linear - gtsam_unstable/nonlinear - gtsam_unstable/slam - gtsam_unstable/dynamics + gtsam_unstable/nonlinear + gtsam_unstable/partition + gtsam_unstable/slam gtsam_unstable ) From 4283c8c4933f5cfaabb8506b6d1b266425e1f5eb Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 26 Jul 2022 15:52:08 -0400 Subject: [PATCH 0124/1497] upgrade the Doxyfile config file --- doc/Doxyfile.in | 3015 ++++++++++++++++++++++++++++++----------------- 1 file changed, 1952 insertions(+), 1063 deletions(-) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 12193d0be5..0f789be66f 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -1,104 +1,143 @@ -# Doxyfile 1.7.5.1 +# Doxyfile 1.9.4 # This file describes the settings to be used by the documentation system -# doxygen (www.doxygen.org) for a project +# doxygen (www.doxygen.org) for a project. # -# All text after a hash (#) is considered a comment and will be ignored +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. # The format is: -# TAG = value [value, ...] -# For lists items can also be appended using: -# TAG += value [value, ...] -# Values that contain spaces should be placed between quotes (" ") +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). +# +# Note: +# +# Use doxygen to compare the used configuration file with the template +# configuration file: +# doxygen -x [configFile] +# Use doxygen to compare the used configuration file with the template +# configuration file without replacing the environment variables: +# doxygen -x_noenv [configFile] #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- -# This tag specifies the encoding used for all characters in the config file -# that follow. The default is UTF-8 which is also the encoding used for all -# text before the first occurrence of this tag. Doxygen uses libiconv (or the -# iconv built into libc) for the transcoding. See -# http://www.gnu.org/software/libiconv for the list of possible encodings. +# This tag specifies the encoding used for all characters in the configuration +# file that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# https://www.gnu.org/software/libiconv/ for the list of possible encodings. +# The default value is: UTF-8. DOXYFILE_ENCODING = UTF-8 -# The PROJECT_NAME tag is a single word (or sequence of words) that should -# identify the project. Note that if you do not use Doxywizard you need -# to put quotes around the project name if it contains spaces. +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. PROJECT_NAME = gtsam -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or -# if some version control system is used. +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. PROJECT_NUMBER = @GTSAM_VERSION_MAJOR@.@GTSAM_VERSION_MINOR@.@GTSAM_VERSION_PATCH@ -# Using the PROJECT_BRIEF tag one can provide an optional one line description -# for a project that appears at the top of each page and should give viewer -# a quick idea about the purpose of the project. Keep the description short. +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. PROJECT_BRIEF = gtsam -# With the PROJECT_LOGO tag one can specify an logo or icon that is -# included in the documentation. The maximum height of the logo should not -# exceed 55 pixels and the maximum width should not exceed 200 pixels. -# Doxygen will copy the logo to the output directory. +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. -PROJECT_LOGO = +PROJECT_LOGO = -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location -# where doxygen was started. If left blank the current directory will be used. +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. OUTPUT_DIRECTORY = . -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would -# otherwise cause performance problems for the file system. +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 +# sub-directories (in 2 levels) under the output directory of each output format +# and will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to +# control the number of sub-directories. +# The default value is: NO. CREATE_SUBDIRS = NO -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, -# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English -# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, -# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, -# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. +# Controls the number of sub-directories that will be created when +# CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every +# level increment doubles the number of directories, resulting in 4096 +# directories at level 8 which is the default and also the maximum value. The +# sub-directories are organized in 2 levels, the first level always has a fixed +# numer of 16 directories. +# Minimum value: 0, maximum value: 8, default value: 8. +# This tag requires that the tag CREATE_SUBDIRS is set to YES. + +CREATE_SUBDIRS_LEVEL = 8 + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian, +# Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English +# (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek, +# Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with +# English messages), Korean, Korean-en (Korean with English messages), Latvian, +# Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, +# Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, +# Swedish, Turkish, Ukrainian and Vietnamese. +# The default value is: English. OUTPUT_LANGUAGE = English -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). -# Set to NO to disable this. +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. BRIEF_MEMBER_DESC = YES -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. +# The default value is: YES. REPEAT_BRIEF = YES -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" -# "represents" "a" "an" "the" +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ @@ -112,549 +151,789 @@ ABBREVIATE_BRIEF = "The $name class" \ an \ the -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief # description. +# The default value is: NO. ALWAYS_DETAILED_SEC = NO -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. +# The default value is: NO. INLINE_INHERITED_MEMB = NO -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set -# to NO the shortest path that makes the file name unique will be used. +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. FULL_PATH_NAMES = YES -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the -# path to strip. +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. -STRIP_FROM_PATH = +STRIP_FROM_PATH = -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that -# are normally passed to the compiler using the -I flag. +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. -STRIP_FROM_INC_PATH = +STRIP_FROM_INC_PATH = -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful if your file system -# doesn't support long names like on DOS, Mac, or CD-ROM. +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. SHORT_NAMES = YES -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like regular Qt-style comments -# (thus requiring an explicit @brief command for a brief description.) +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. JAVADOC_AUTOBRIEF = YES -# If the QT_AUTOBRIEF tag is set to YES then Doxygen will -# interpret the first line (until the first dot) of a Qt-style -# comment as the brief description. If set to NO, the comments -# will behave just like regular Qt-style comments (thus requiring -# an explicit \brief command for a brief description.) +# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line +# such as +# /*************** +# as being the beginning of a Javadoc-style comment "banner". If set to NO, the +# Javadoc-style will behave just like regular comments and it will not be +# interpreted by doxygen. +# The default value is: NO. + +JAVADOC_BANNER = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. QT_AUTOBRIEF = NO -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed -# description. Set this tag to YES if you prefer the old behaviour instead. +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. MULTILINE_CPP_IS_BRIEF = NO -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it -# re-implements. +# By default Python docstrings are displayed as preformatted text and doxygen's +# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the +# doxygen's special commands can be used and the contents of the docstring +# documentation blocks is shown as doxygen documentation. +# The default value is: YES. + +PYTHON_DOCSTRING = YES + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. INHERIT_DOCS = YES -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will -# be part of the file/class/namespace that contains it. +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. SEPARATE_MEMBER_PAGES = NO -# The TAB_SIZE tag can be used to set the number of spaces in a tab. -# Doxygen uses this value to replace tabs by spaces in code fragments. +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. TAB_SIZE = 8 -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". -# You can put \n's in the value part of an alias to insert newlines. - -ALIASES = - -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list -# of all members will be omitted, etc. +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:^^" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". Note that you cannot put \n's in the value part of an alias +# to insert newlines (in the resulting output). You can put ^^ in the value part +# of an alias to insert a newline as if a physical newline was in the original +# file. When you need a literal { or } or , in the value part of an alias you +# have to escape them by means of a backslash (\), this can lead to conflicts +# with the commands \{ and \} for these it is advised to use the version @{ and +# @} or use a double escape (\\{ and \\}) + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. OPTIMIZE_OUTPUT_FOR_C = NO -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for -# Java. For instance, namespaces will be presented as packages, qualified -# scopes will look different, etc. +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. OPTIMIZE_OUTPUT_JAVA = NO -# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran -# sources only. Doxygen will then generate output that is more tailored for -# Fortran. +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. OPTIMIZE_FOR_FORTRAN = NO -# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL -# sources. Doxygen will then generate output that is tailored for -# VHDL. +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. OPTIMIZE_OUTPUT_VHDL = NO -# Doxygen selects the parser to use depending on the extension of the files it -# parses. With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this -# tag. The format is ext=language, where ext is a file extension, and language -# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, -# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make -# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C -# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions -# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. - -EXTENSION_MAPPING = - -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want -# to include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also makes the inheritance and collaboration +# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice +# sources only. Doxygen will then generate output that is more tailored for that +# language. For instance, namespaces will be presented as modules, types will be +# separated into more groups, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_SLICE = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, +# Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, +# VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: +# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser +# tries to guess whether the code is fixed or free formatted code, this is the +# default for Fortran type files). For instance to make doxygen treat .inc files +# as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. When specifying no_extension you should add +# * to the FILE_PATTERNS. +# +# Note see also the list of default file extension mappings. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See https://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 5. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 5 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. +# The default value is: NO. BUILTIN_STL_SUPPORT = YES -# If you use Microsoft's C++/CLI language, you should set this option to YES to +# If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. +# The default value is: NO. CPP_CLI_SUPPORT = NO -# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. -# Doxygen will parse them like normal C++ but will assume all classes use public -# instead of private inheritance when no explicit protection keyword is present. +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. SIP_SUPPORT = NO -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or -# setting a simple type. If this is not the case, or you want to show the -# methods anyway, you should set this option to NO. +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. IDL_PROPERTY_SUPPORT = YES -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. +# The default value is: NO. DISTRIBUTE_GROUP_DOC = NO -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using -# the \nosubgrouping command. +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. SUBGROUPING = YES -# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and -# unions are shown inside the group in which they are included (e.g. using -# @ingroup) instead of on a separate page (for HTML and Man pages) or -# section (for LaTeX and RTF). +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. INLINE_GROUPED_CLASSES = NO -# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and -# unions with only public data fields will be shown inline in the documentation -# of the scope in which they are defined (i.e. file, namespace, or group -# documentation), provided this scope is documented. If set to NO (the default), -# structs, classes, and unions are shown on a separate page (for HTML and Man -# pages) or section (for LaTeX and RTF). +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. INLINE_SIMPLE_STRUCTS = NO -# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum -# is documented as struct, union, or enum with the name of the typedef. So -# typedef struct TypeS {} TypeT, will appear in the documentation as a struct -# with name TypeT. When disabled the typedef will appear as a member of a file, -# namespace, or class. And the struct will be named TypeS. This can typically -# be useful for C code in case the coding convention dictates that all compound +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. TYPEDEF_HIDES_STRUCT = NO -# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to -# determine which symbols to keep in memory and which to flush to disk. -# When the cache is full, less often used symbols will be written to disk. -# For small to medium size projects (<1000 input files) the default value is -# probably good enough. For larger projects a too small cache size can cause -# doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penalty. -# If the system has enough physical memory increasing the cache will improve the -# performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will roughly double the -# memory usage. The cache size is given by this formula: -# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols - -SYMBOL_CACHE_SIZE = 0 +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +# The NUM_PROC_THREADS specifies the number of threads doxygen is allowed to use +# during processing. When set to 0 doxygen will based this on the number of +# cores available in the system. You can set it explicitly to a value larger +# than 0 to get more control over the balance between CPU load and processing +# speed. At this moment only the input processing can be done using multiple +# threads. Since this is still an experimental feature the default is set to 1, +# which effectively disables parallel processing. Please report any issues you +# encounter. Generating dot graphs in parallel is controlled by the +# DOT_NUM_THREADS setting. +# Minimum value: 0, maximum value: 32, default value: 1. + +NUM_PROC_THREADS = 1 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless -# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. EXTRACT_ALL = NO -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class -# will be included in the documentation. +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. EXTRACT_PRIVATE = NO -# If the EXTRACT_STATIC tag is set to YES all static members of a file -# will be included in the documentation. +# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual +# methods of a class will be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIV_VIRTUAL = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. EXTRACT_STATIC = NO -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. -# If set to NO only classes defined in header files are included. +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. EXTRACT_LOCAL_CLASSES = NO -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. -# If set to NO (the default) only methods in the interface are included. +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. EXTRACT_LOCAL_METHODS = NO -# If this flag is set to YES, the members of anonymous namespaces will be -# extracted and appear in the documentation as a namespace called -# 'anonymous_namespace{file}', where file will be replaced with the base -# name of the file that contains the anonymous namespace. By default -# anonymous namespaces are hidden. +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. EXTRACT_ANON_NSPACES = NO -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. -# This option has no effect if EXTRACT_ALL is enabled. +# If this flag is set to YES, the name of an unnamed parameter in a declaration +# will be determined by the corresponding definition. By default unnamed +# parameters remain unnamed in the output. +# The default value is: YES. + +RESOLVE_UNNAMED_PARAMS = YES + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. HIDE_UNDOC_MEMBERS = NO -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various -# overviews. This option has no effect if EXTRACT_ALL is enabled. +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. HIDE_UNDOC_CLASSES = NO -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# declarations. If set to NO, these declarations will be included in the # documentation. +# The default value is: NO. HIDE_FRIEND_COMPOUNDS = NO -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the -# function's detailed documentation block. +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. HIDE_IN_BODY_DOCS = NO -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. -# Set it to YES to include the internal documentation. +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. INTERNAL_DOCS = NO -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows -# and Mac users are advised to set this option to NO. +# With the correct setting of option CASE_SENSE_NAMES doxygen will better be +# able to match the capabilities of the underlying filesystem. In case the +# filesystem is case sensitive (i.e. it supports files in the same directory +# whose names only differ in casing), the option must be set to YES to properly +# deal with such files in case they appear in the input. For filesystems that +# are not case sensitive the option should be set to NO to properly deal with +# output files written for symbols that only differ in casing, such as for two +# classes, one named CLASS and the other named Class, and to also support +# references to files without having to specify the exact matching casing. On +# Windows (including Cygwin) and MacOS, users should typically set this option +# to NO, whereas on Linux or other Unix flavors it should typically be set to +# YES. +# The default value is: system dependent. CASE_SENSE_NAMES = NO -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the -# documentation. If set to YES the scope will be hidden. +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. HIDE_SCOPE_NAMES = NO -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation -# of that file. +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class +# will show which file needs to be included to use the class. +# The default value is: YES. + +SHOW_HEADERFILE = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. SHOW_INCLUDE_FILES = NO -# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen -# will list include files with double quotes in the documentation -# rather than with sharp brackets. +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. FORCE_LOCAL_INCLUDES = NO -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] -# is inserted in the documentation for inline members. +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. INLINE_INFO = YES -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in -# declaration order. +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. SORT_MEMBER_DOCS = YES -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in -# declaration order. +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. SORT_BRIEF_DOCS = NO -# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen -# will sort the (brief and detailed) documentation of class members so that -# constructors and destructors are listed first. If set to NO (the default) -# the constructors will appear in the respective orders defined by -# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. -# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO -# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. SORT_MEMBERS_CTORS_1ST = NO -# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the -# hierarchy of group names into alphabetical order. If set to NO (the default) -# the group names will appear in their defined order. +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. SORT_GROUP_NAMES = NO -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. -# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the -# alphabetical list. +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. SORT_BY_SCOPE_NAME = NO -# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to -# do proper type resolution of all parameters of a function it will reject a -# match between the prototype and the implementation of a member function even -# if there is only one candidate or it is obvious which candidate to choose -# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen -# will still accept a match between prototype and implementation in such cases. +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. STRICT_PROTO_MATCHING = NO -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo -# commands in the documentation. +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. GENERATE_TODOLIST = YES -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test -# commands in the documentation. +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. GENERATE_TESTLIST = YES -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug -# commands in the documentation. +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. GENERATE_BUGLIST = YES -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting -# \deprecated commands in the documentation. +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. GENERATE_DEPRECATEDLIST= YES -# The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. -ENABLED_SECTIONS = +ENABLED_SECTIONS = -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or macro consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and macros in the -# documentation can be controlled using \showinitializer or \hideinitializer -# command in the documentation regardless of this setting. +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. MAX_INITIALIZER_LINES = 30 -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the # list will mention the files that were used to generate the documentation. +# The default value is: YES. SHOW_USED_FILES = YES -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is NO. - -SHOW_DIRECTORIES = YES - -# Set the SHOW_FILES tag to NO to disable the generation of the Files page. -# This will remove the Files entry from the Quick Index and from the -# Folder Tree View (if specified). The default is YES. +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. SHOW_FILES = YES -# Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. This will remove the Namespaces entry from the Quick Index -# and from the Folder Tree View (if specified). The default is YES. +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. SHOW_NAMESPACES = YES -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from -# the version control system). Doxygen will invoke the program by executing (via -# popen()) the command , where is the value of -# the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the program writes to standard output -# is used as the file version. See the manual for examples. - -FILE_VERSION_FILTER = - -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed -# by doxygen. The layout file controls the global structure of the generated -# output files in an output format independent way. The create the layout file -# that represents doxygen's defaults, run doxygen with the -l option. -# You can optionally specify a file name after the option, if omitted -# DoxygenLayout.xml will be used as the name of the layout file. +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. See also section "Changing the +# layout of pages" for information. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. LAYOUT_FILE = DoxygenLayout.xml -# The CITE_BIB_FILES tag can be used to specify one or more bib files -# containing the references data. This must be a list of .bib files. The -# .bib extension is automatically appended if omitted. Using this command -# requires the bibtex tool to be installed. See also -# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style -# of the bibliography can be controlled using LATEX_BIB_STYLE. +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. -CITE_BIB_FILES = +CITE_BIB_FILES = #--------------------------------------------------------------------------- -# configuration options related to warning and progress messages +# Configuration options related to warning and progress messages #--------------------------------------------------------------------------- -# The QUIET tag can be used to turn on/off the messages that are generated -# by doxygen. Possible values are YES and NO. If left blank NO is used. +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. QUIET = NO -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank -# NO is used. +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. WARNINGS = YES -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will -# automatically be disabled. +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. WARN_IF_UNDOCUMENTED = NO -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that -# don't exist or using markup commands wrongly. +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as documenting some parameters in +# a documented function twice, or documenting parameters that don't exist or +# using markup commands wrongly. +# The default value is: YES. WARN_IF_DOC_ERROR = YES -# The WARN_NO_PARAMDOC option can be enabled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of -# documentation. +# If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete +# function parameter documentation. If set to NO, doxygen will accept that some +# parameters have no documentation without warning. +# The default value is: YES. + +WARN_IF_INCOMPLETE_DOC = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong parameter +# documentation, but not about the absence of documentation. If EXTRACT_ALL is +# set to YES then this flag will automatically be disabled. See also +# WARN_IF_INCOMPLETE_DOC +# The default value is: NO. WARN_NO_PARAMDOC = NO -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could -# be obtained via FILE_VERSION_FILTER) +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS +# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but +# at the end of the doxygen process doxygen will return with a non-zero status. +# Possible values are: NO, YES and FAIL_ON_WARNINGS. +# The default value is: NO. + +WARN_AS_ERROR = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# See also: WARN_LINE_FORMAT +# The default value is: $file:$line: $text. WARN_FORMAT = "$file:$line: $text" -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written -# to stderr. +# In the $text part of the WARN_FORMAT command it is possible that a reference +# to a more specific place is given. To make it easier to jump to this place +# (outside of doxygen) the user can define a custom "cut" / "paste" string. +# Example: +# WARN_LINE_FORMAT = "'vi $file +$line'" +# See also: WARN_FORMAT +# The default value is: at line $line of file $file. + +WARN_LINE_FORMAT = "at line $line of file $file" -WARN_LOGFILE = +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). In case the file specified cannot be opened for writing the +# warning and error messages are written to standard error. When as file - is +# specified the warning and error messages are written to standard output +# (stdout). + +WARN_LOGFILE = #--------------------------------------------------------------------------- -# configuration options related to the input files +# Configuration options related to the input files #--------------------------------------------------------------------------- -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories -# with spaces. +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. INPUT = @GTSAM_DOXYGEN_INPUT_PATHS@ -# This tag can be used to specify the character encoding of the source files -# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is -# also the default input encoding. Doxygen uses libiconv (or the iconv built -# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for -# the list of possible encodings. +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: +# https://www.gnu.org/software/libiconv/) for the list of possible encodings. +# The default value is: UTF-8. INPUT_ENCODING = UTF-8 -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh -# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py -# *.f90 *.f *.for *.vhd *.vhdl +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# Note the list of default checked file patterns might differ from the list of +# default file extension mappings. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, +# *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C +# comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, +# *.vhdl, *.ucf, *.qsf and *.ice. FILE_PATTERNS = *.c \ *.cc \ @@ -689,1101 +968,1711 @@ FILE_PATTERNS = *.c \ *.vhd \ *.vhdl -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. -# If left blank NO is used. +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. RECURSIVE = NO -# The EXCLUDE tag can be used to specify files and/or directories that should -# excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. -# Note that relative paths are relative to directory from which doxygen is run. +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. -EXCLUDE = +EXCLUDE = -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix file system feature) are excluded +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded # from the input. +# The default value is: NO. EXCLUDE_SYMLINKS = NO -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories -# for example use the pattern */test/* +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = -# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the -# output. The symbol name can be a fully qualified name, a word, or if the -# wildcard * is used, a substring. Examples: ANamespace, AClass, -# AClass::ANamespace, ANamespace::*Test +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# ANamespace::AClass, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* -EXCLUDE_SYMBOLS = +EXCLUDE_SYMBOLS = -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see -# the \include command). +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). -EXAMPLE_PATH = +EXAMPLE_PATH = -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank all files are included. +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. EXAMPLE_PATTERNS = * -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. -# Possible values are YES and NO. If left blank NO is used. +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. EXAMPLE_RECURSIVE = NO -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see -# the \image command). +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). -IMAGE_PATH = +IMAGE_PATH = -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command , where -# is the value of the INPUT_FILTER tag, and is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. If FILTER_PATTERNS is specified, this tag will be -# ignored. +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. -INPUT_FILTER = +FILTER_PATTERNS = -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty or if -# non of the patterns match the file name, INPUT_FILTER is applied. +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. -FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source -# files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. -FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = -# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file -# pattern. A pattern will override the setting for FILTER_PATTERN (if any) -# and it is also possible to disable source filtering for a specific pattern -# using *.ext= (so without naming a filter). This option only has effect when -# FILTER_SOURCE_FILES is enabled. +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. -FILTER_SOURCE_PATTERNS = +USE_MDFILE_AS_MAINPAGE = #--------------------------------------------------------------------------- -# configuration options related to source browsing +# Configuration options related to source browsing #--------------------------------------------------------------------------- -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. SOURCE_BROWSER = NO -# Setting the INLINE_SOURCES tag to YES will include the body -# of functions and classes directly in the documentation. +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. INLINE_SOURCES = NO -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. STRIP_CODE_COMMENTS = YES -# If the REFERENCED_BY_RELATION tag is set to YES -# then for each documented function all documented -# functions referencing it will be listed. +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# entity all documented functions referencing it will be listed. +# The default value is: NO. REFERENCED_BY_RELATION = NO -# If the REFERENCES_RELATION tag is set to YES -# then for each documented function all documented entities -# called/used by that function will be listed. +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. REFERENCES_RELATION = NO -# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) -# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from -# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. Otherwise they will link to the documentation. +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. REFERENCES_LINK_SOURCE = YES -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You -# will need version 4.8.6 or higher. +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see https://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. USE_HTAGS = NO -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for -# which an include is specified. Set to NO to disable this. +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index +# Configuration options related to the alphabetical class index #--------------------------------------------------------------------------- -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project -# contains a lot of classes, structs, unions or interfaces. +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. ALPHABETICAL_INDEX = YES -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns -# in which this list will be split (can be a number in the range [1..20]) - -COLS_IN_ALPHA_INDEX = 5 - -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that -# should be ignored while generating the index headers. +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. -IGNORE_PREFIX = +IGNORE_PREFIX = #--------------------------------------------------------------------------- -# configuration options related to the HTML output +# Configuration options related to the HTML output #--------------------------------------------------------------------------- -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will -# generate HTML output. +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. GENERATE_HTML = @GTSAM_BUILD_DOC_HTML_YN@ -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be -# put in front of it. If left blank `html' will be used as the default path. +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_OUTPUT = html -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank -# doxygen will generate files with .html extension. +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_FILE_EXTENSION = .html -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a -# standard header. Note that when using a custom header you are responsible -# for the proper inclusion of any scripts and style sheets that doxygen -# needs, which is dependent on the configuration options used. -# It is adviced to generate a default header using "doxygen -w html -# header.html footer.html stylesheet.css YourConfigFile" and then modify -# that header. Note that the header is subject to change so you typically -# have to redo this when upgrading to a newer version of doxygen or when -# changing the value of configuration settings such as GENERATE_TREEVIEW! - -HTML_HEADER = - -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a -# standard footer. - -HTML_FOOTER = - -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! - -HTML_STYLESHEET = - -# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or -# other source files which should be copied to the HTML output directory. Note -# that these files will be copied to the base HTML output directory. Use the -# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these -# files. In the HTML_STYLESHEET file, use the file name only. Also note that -# the files will be copied as-is; there are no commands or markers available. - -HTML_EXTRA_FILES = - -# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. -# Doxygen will adjust the colors in the stylesheet and background images -# according to this color. Hue is specified as an angle on a colorwheel, -# see http://en.wikipedia.org/wiki/Hue for more information. -# For instance the value 0 represents red, 60 is yellow, 120 is green, -# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. -# The allowed range is 0 to 359. +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a color-wheel, see +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_HUE = 220 -# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of -# the colors in the HTML output. For a value of 0 the output will use -# grayscales only. A value of 255 will produce the most vivid colors. +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use gray-scales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_SAT = 100 -# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to -# the luminance component of the colors in the HTML output. Values below -# 100 gradually make the output lighter, whereas values above 100 make -# the output darker. The value divided by 100 is the actual gamma applied, -# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, -# and 100 does not change the gamma. +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_COLORSTYLE_GAMMA = 80 -# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML -# page will contain the date and time when the page was generated. Setting -# this to NO can help when comparing the output of multiple runs. +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_TIMESTAMP = YES -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. +# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML +# documentation will contain a main index with vertical navigation menus that +# are dynamically created via JavaScript. If disabled, the navigation index will +# consists of multiple levels of tabs that are statically embedded in every HTML +# page. Disable this option to support browsers that do not have JavaScript, +# like the Qt help browser. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. -HTML_ALIGN_MEMBERS = YES +HTML_DYNAMIC_MENUS = YES -# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML -# documentation will contain sections that can be hidden and shown after the -# page has loaded. For this to work a browser that supports -# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox -# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. HTML_DYNAMIC_SECTIONS = YES -# If the GENERATE_DOCSET tag is set to YES, additional index files -# will be generated that can be used as input for Apple's Xcode 3 -# integrated development environment, introduced with OSX 10.5 (Leopard). -# To create a documentation set, doxygen will generate a Makefile in the -# HTML output directory. Running make will produce the docset in that -# directory and running "make install" will install the docset in -# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find -# it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html -# for more information. +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: +# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To +# create a documentation set, doxygen will generate a Makefile in the HTML +# output directory. Running make will produce the docset in that directory and +# running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy +# genXcode/_index.html for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_DOCSET = NO -# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the -# feed. A documentation feed provides an umbrella under which multiple -# documentation sets from a single provider (such as a company or product suite) -# can be grouped. +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_FEEDNAME = "Doxygen generated docs" -# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that -# should uniquely identify the documentation set bundle. This should be a -# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen -# will append .docset to the name. +# This tag determines the URL of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDURL = + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_BUNDLE_ID = org.doxygen.Project -# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify -# the documentation publisher. This should be a reverse domain-name style +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style # string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_ID = org.doxygen.Publisher -# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. DOCSET_PUBLISHER_NAME = Publisher -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) -# of the generated HTML documentation. +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# on Windows. In the beginning of 2021 Microsoft took the original page, with +# a.o. the download links, offline the HTML help workshop was already many years +# in maintenance mode). You can download the HTML help workshop from the web +# archives at Installation executable (see: +# http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo +# ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_HTMLHELP = NO -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be # written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. -CHM_FILE = +CHM_FILE = -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run -# the HTML help compiler on the generated index.hhp. +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. -HHC_LOCATION = +HHC_LOCATION = -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that -# it should be included in the master .chm file (NO). +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the main .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. GENERATE_CHI = NO -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING -# is used to encode HtmlHelp index (hhk), content (hhc) and project file -# content. +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. -CHM_INDEX_ENCODING = +CHM_INDEX_ENCODING = -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a -# normal table of contents (NO) in the .chm file. +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. BINARY_TOC = NO -# The TOC_EXPAND flag can be set to YES to add extra items for group members -# to the contents of the HTML help documentation and to the tree view. +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. TOC_EXPAND = NO -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and -# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated -# that can be used as input for Qt's qhelpgenerator to generate a -# Qt Compressed Help (.qch) of the generated HTML documentation. +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_QHP = NO -# If the QHG_LOCATION tag is specified, the QCH_FILE tag can -# be used to specify the file name of the resulting .qch file. -# The path specified is relative to the HTML output folder. +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. -QCH_FILE = +QCH_FILE = -# The QHP_NAMESPACE tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#namespace +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_NAMESPACE = org.doxygen.Project -# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating -# Qt Help Project output. For more information please see -# http://doc.trolltech.com/qthelpproject.html#virtual-folders +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. QHP_VIRTUAL_FOLDER = doc -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to -# add. For more information please see -# http://doc.trolltech.com/qthelpproject.html#custom-filters +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. -QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_NAME = -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the -# custom filter to add. For more information please see -# -# Qt Help Project / Custom Filters. +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. -QHP_CUST_FILTER_ATTRS = +QHP_CUST_FILTER_ATTRS = -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this -# project's -# filter section matches. -# -# Qt Help Project / Filter Attributes. +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. -QHP_SECT_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = -# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can -# be used to specify the location of Qt's qhelpgenerator. -# If non-empty doxygen will try to run qhelpgenerator on the generated -# .qhp file. +# The QHG_LOCATION tag can be used to specify the location (absolute path +# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to +# run qhelpgenerator on the generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. -QHG_LOCATION = +QHG_LOCATION = -# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files -# will be generated, which together with the HTML files, form an Eclipse help -# plugin. To install this plugin and make it available under the help contents -# menu in Eclipse, the contents of the directory containing the HTML and XML -# files needs to be copied into the plugins directory of eclipse. The name of -# the directory within the plugins directory should be the same as -# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before -# the help appears. +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. GENERATE_ECLIPSEHELP = NO -# A unique identifier for the eclipse help plugin. When installing the plugin -# the directory name containing the HTML and XML files should also have -# this name. +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. ECLIPSE_DOC_ID = org.doxygen.Project -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. DISABLE_INDEX = NO -# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values -# (range [0,1..20]) that doxygen will group on one line in the generated HTML -# documentation. Note that a value of 0 will completely suppress the enum -# values from appearing in the overview section. +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine tune the look of the index (see "Fine-tuning the output"). As an +# example, the default style sheet generated by doxygen has an example that +# shows how to put an image at the root of the tree instead of the PROJECT_NAME. +# Since the tree basically has the same information as the tab index, you could +# consider setting DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. -ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = YES -# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index -# structure should be generated to display hierarchical information. -# If the tag value is set to YES, a side panel will be generated -# containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). -# Windows users are probably better off using the HTML help feature. +# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the +# FULL_SIDEBAR option determines if the side bar is limited to only the treeview +# area (value NO) or if it should extend to the full height of the window (value +# YES). Setting this to YES gives a layout similar to +# https://docs.readthedocs.io with more room for contents, but less room for the +# project logo, title, and description. If either GENERATE_TREEVIEW or +# DISABLE_INDEX is set to NO, this option has no effect. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. -GENERATE_TREEVIEW = YES +FULL_SIDEBAR = NO -# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, -# and Class Hierarchy pages using a tree view instead of an ordered list. +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. -USE_INLINE_TREES = NO +ENUM_VALUES_PER_LINE = 4 -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree -# is shown. +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. TREEVIEW_WIDTH = 250 -# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open -# links to external symbols imported via tag files in a separate window. +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. EXT_LINKS_IN_WINDOW = NO -# Use this tag to change the font size of Latex formulas included -# as images in the HTML documentation. The default is 10. Note that -# when you change the font size after a successful doxygen run you need -# to manually remove any form_*.png images from the HTML output directory -# to force them to be regenerated. +# If the OBFUSCATE_EMAILS tag is set to YES, doxygen will obfuscate email +# addresses. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +OBFUSCATE_EMAILS = YES + +# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg +# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see +# https://inkscape.org) to generate formulas as SVG images instead of PNGs for +# the HTML output. These images will generally look nicer at scaled resolutions. +# Possible values are: png (the default) and svg (looks nicer but requires the +# pdf2svg or inkscape tool). +# The default value is: png. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FORMULA_FORMAT = png + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_FONTSIZE = 10 -# Use the FORMULA_TRANPARENT tag to determine whether or not the images -# generated for formulas are transparent PNGs. Transparent PNGs are -# not supported properly for IE 6.0, but are supported on all modern browsers. -# Note that when changing this option you need to delete any form_*.png files -# in the HTML output before the changes have effect. +# Use the FORMULA_TRANSPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. FORMULA_TRANSPARENT = YES -# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax -# (see http://www.mathjax.org) which uses client side Javascript for the -# rendering instead of using prerendered bitmaps. Use this if you do not -# have LaTeX installed or if you want to formulas look prettier in the HTML -# output. When enabled you also need to install MathJax separately and -# configure the path to it using the MATHJAX_RELPATH option. +# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands +# to create new LaTeX commands to be used in formulas as building blocks. See +# the section "Including formulas" for details. + +FORMULA_MACROFILE = + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# https://www.mathjax.org) which uses client side JavaScript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. USE_MATHJAX = YES -# When MathJax is enabled you need to specify the location relative to the -# HTML output directory using the MATHJAX_RELPATH option. The destination -# directory should contain the MathJax.js script. For instance, if the mathjax -# directory is located at the same level as the HTML output directory, then -# MATHJAX_RELPATH should be ../mathjax. The default value points to the -# mathjax.org site, so you can quickly see the result without installing -# MathJax, but it is strongly recommended to install a local copy of MathJax -# before deployment. +# With MATHJAX_VERSION it is possible to specify the MathJax version to be used. +# Note that the different versions of MathJax have different requirements with +# regards to the different settings, so it is possible that also other MathJax +# settings have to be changed when switching between the different MathJax +# versions. +# Possible values are: MathJax_2 and MathJax_3. +# The default value is: MathJax_2. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_VERSION = MathJax_2 + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. For more details about the output format see MathJax +# version 2 (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 +# (see: +# http://docs.mathjax.org/en/latest/web/components/output.html). +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility. This is the name for Mathjax version 2, for MathJax version 3 +# this will be translated into chtml), NativeMML (i.e. MathML. Only supported +# for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This +# is the name for Mathjax version 3, for MathJax version 2 this will be +# translated into HTML-CSS) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from https://www.mathjax.org before deployment. The default value is: +# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 +# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# for MathJax version 2 (see +# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions): +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# For example for MathJax version 3 (see +# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): +# MATHJAX_EXTENSIONS = ams +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /