From 4d6eef2c2ff2088cb54e53241ce061e0fa978459 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 29 Apr 2021 19:43:27 -0400 Subject: [PATCH 1/2] override print methods and update wrapper --- gtsam/discrete/DiscreteFactor.h | 11 +++-- gtsam/discrete/DiscreteFactorGraph.h | 5 +- gtsam/geometry/CalibratedCamera.h | 7 ++- gtsam/geometry/PinholeCamera.h | 2 +- gtsam/geometry/PinholePose.h | 2 +- gtsam/gtsam.i | 22 +++++---- gtsam/inference/BayesNet-inst.h | 46 +++++++++---------- gtsam/inference/BayesNet.h | 16 ++++--- gtsam/inference/Factor.cpp | 4 +- gtsam/inference/Factor.h | 8 +++- gtsam/inference/FactorGraph-inst.h | 2 +- gtsam/inference/FactorGraph.h | 6 +-- gtsam/linear/GaussianBayesNet.h | 7 +++ gtsam/linear/GaussianFactor.h | 7 ++- gtsam/navigation/AttitudeFactor.cpp | 3 +- gtsam/navigation/AttitudeFactor.h | 8 ++-- gtsam/navigation/GPSFactor.cpp | 3 +- gtsam/navigation/GPSFactor.h | 8 ++-- gtsam/nonlinear/NonlinearFactor.h | 5 +- gtsam/nonlinear/NonlinearFactorGraph.h | 5 +- gtsam/sfm/BinaryMeasurement.h | 4 +- gtsam/symbolic/SymbolicBayesNet.h | 7 +++ gtsam/symbolic/SymbolicConditional.cpp | 23 +++++----- gtsam/symbolic/SymbolicConditional.h | 4 +- gtsam/symbolic/SymbolicFactor.h | 14 ++++++ gtsam/symbolic/SymbolicFactorGraph.h | 7 +++ gtsam_unstable/linear/InequalityFactorGraph.h | 5 +- 27 files changed, 151 insertions(+), 90 deletions(-) diff --git a/gtsam/discrete/DiscreteFactor.h b/gtsam/discrete/DiscreteFactor.h index e24dfdf2a8..f8b3fc0bb3 100644 --- a/gtsam/discrete/DiscreteFactor.h +++ b/gtsam/discrete/DiscreteFactor.h @@ -74,13 +74,14 @@ class GTSAM_EXPORT DiscreteFactor: public Factor { /// @name Testable /// @{ - // equals + /// equals virtual bool equals(const DiscreteFactor& lf, double tol = 1e-9) const = 0; - // print - virtual void print(const std::string& s = "DiscreteFactor\n", - const KeyFormatter& formatter = DefaultKeyFormatter) const { - Factor::print(s, formatter); + /// print + virtual void print( + const std::string& s = "DiscreteFactor\n", + const KeyFormatter& formatter = DefaultKeyFormatter) const override { + Base::print(s, formatter); } /** Test whether the factor is empty */ diff --git a/gtsam/discrete/DiscreteFactorGraph.h b/gtsam/discrete/DiscreteFactorGraph.h index 4c2607f1f8..8df602af50 100644 --- a/gtsam/discrete/DiscreteFactorGraph.h +++ b/gtsam/discrete/DiscreteFactorGraph.h @@ -129,8 +129,9 @@ public EliminateableFactorGraph { double operator()(const DiscreteFactor::Values & values) const; /// print - void print(const std::string& s = "DiscreteFactorGraph", - const KeyFormatter& formatter =DefaultKeyFormatter) const; + void print( + const std::string& s = "DiscreteFactorGraph", + const KeyFormatter& formatter = DefaultKeyFormatter) const override; /** Solve the factor graph by performing variable elimination in COLAMD order using * the dense elimination function specified in \c function, diff --git a/gtsam/geometry/CalibratedCamera.h b/gtsam/geometry/CalibratedCamera.h index eff747eb50..97ebe8c7eb 100644 --- a/gtsam/geometry/CalibratedCamera.h +++ b/gtsam/geometry/CalibratedCamera.h @@ -144,7 +144,7 @@ class GTSAM_EXPORT PinholeBase { bool equals(const PinholeBase &camera, double tol = 1e-9) const; /// print - void print(const std::string& s = "PinholeBase") const; + virtual void print(const std::string& s = "PinholeBase") const; /// @} /// @name Standard Interface @@ -324,6 +324,11 @@ class GTSAM_EXPORT CalibratedCamera: public PinholeBase { /// Return canonical coordinate Vector localCoordinates(const CalibratedCamera& T2) const; + /// print + void print(const std::string& s = "CalibratedCamera") const override { + PinholeBase::print(s); + } + /// @deprecated inline size_t dim() const { return dimension; diff --git a/gtsam/geometry/PinholeCamera.h b/gtsam/geometry/PinholeCamera.h index ecff766e23..8ac67a5c35 100644 --- a/gtsam/geometry/PinholeCamera.h +++ b/gtsam/geometry/PinholeCamera.h @@ -148,7 +148,7 @@ class PinholeCamera: public PinholeBaseK { } /// print - void print(const std::string& s = "PinholeCamera") const { + void print(const std::string& s = "PinholeCamera") const override { Base::print(s); K_.print(s + ".calibration"); } diff --git a/gtsam/geometry/PinholePose.h b/gtsam/geometry/PinholePose.h index 1b5a06609c..949caaa276 100644 --- a/gtsam/geometry/PinholePose.h +++ b/gtsam/geometry/PinholePose.h @@ -340,7 +340,7 @@ class PinholePose: public PinholeBaseK { } /// print - void print(const std::string& s = "PinholePose") const { + void print(const std::string& s = "PinholePose") const override { Base::print(s); if (!K_) std::cout << "s No calibration given" << std::endl; diff --git a/gtsam/gtsam.i b/gtsam/gtsam.i index 33e9a58ca9..c5bf6511c6 100644 --- a/gtsam/gtsam.i +++ b/gtsam/gtsam.i @@ -986,7 +986,7 @@ class CalibratedCamera { static gtsam::CalibratedCamera Level(const gtsam::Pose2& pose2, double height); // Testable - void print(string s = "") const; + void print(string s = "CalibratedCamera") const; bool equals(const gtsam::CalibratedCamera& camera, double tol) const; // Manifold @@ -1163,8 +1163,9 @@ virtual class SymbolicFactor { // From Factor size_t size() const; - void print(string s = "", const gtsam::KeyFormatter& keyFormatter = - gtsam::DefaultKeyFormatter) const; + void print(string s = "SymbolicFactor", + const gtsam::KeyFormatter& keyFormatter = + gtsam::DefaultKeyFormatter) const; bool equals(const gtsam::SymbolicFactor& other, double tol) const; gtsam::KeyVector keys(); }; @@ -1177,8 +1178,9 @@ virtual class SymbolicFactorGraph { // From FactorGraph void push_back(gtsam::SymbolicFactor* factor); - void print(string s = "", const gtsam::KeyFormatter& keyFormatter = - gtsam::DefaultKeyFormatter) const; + void print(string s = "SymbolicFactorGraph", + const gtsam::KeyFormatter& keyFormatter = + gtsam::DefaultKeyFormatter) const; bool equals(const gtsam::SymbolicFactorGraph& rhs, double tol) const; size_t size() const; bool exists(size_t idx) const; @@ -1242,8 +1244,9 @@ class SymbolicBayesNet { SymbolicBayesNet(); SymbolicBayesNet(const gtsam::SymbolicBayesNet& other); // Testable - void print(string s = "", const gtsam::KeyFormatter& keyFormatter = - gtsam::DefaultKeyFormatter) const; + void print(string s = "SymbolicBayesNet", + const gtsam::KeyFormatter& keyFormatter = + gtsam::DefaultKeyFormatter) const; bool equals(const gtsam::SymbolicBayesNet& other, double tol) const; // Standard interface @@ -2097,8 +2100,9 @@ class NonlinearFactorGraph { NonlinearFactorGraph(const gtsam::NonlinearFactorGraph& graph); // FactorGraph - void print(string s = "", const gtsam::KeyFormatter& keyFormatter = - gtsam::DefaultKeyFormatter) const; + void print(string s = "NonlinearFactorGraph: ", + const gtsam::KeyFormatter& keyFormatter = + gtsam::DefaultKeyFormatter) const; bool equals(const gtsam::NonlinearFactorGraph& fg, double tol) const; size_t size() const; bool empty() const; diff --git a/gtsam/inference/BayesNet-inst.h b/gtsam/inference/BayesNet-inst.h index a3bd878877..a737622585 100644 --- a/gtsam/inference/BayesNet-inst.h +++ b/gtsam/inference/BayesNet-inst.h @@ -26,30 +26,30 @@ namespace gtsam { - /* ************************************************************************* */ - template - void BayesNet::print(const std::string& s, const KeyFormatter& formatter) const - { - Base::print(s, formatter); - } +/* ************************************************************************* */ +template +void BayesNet::print( + const std::string& s, const KeyFormatter& formatter) const { + Base::print(s, formatter); +} - /* ************************************************************************* */ - template - void BayesNet::saveGraph(const std::string &s, const KeyFormatter& keyFormatter) const - { - std::ofstream of(s.c_str()); - of << "digraph G{\n"; - - for (auto conditional: boost::adaptors::reverse(*this)) { - typename CONDITIONAL::Frontals frontals = conditional->frontals(); - Key me = frontals.front(); - typename CONDITIONAL::Parents parents = conditional->parents(); - for(Key p: parents) - of << keyFormatter(p) << "->" << keyFormatter(me) << std::endl; - } - - of << "}"; - of.close(); +/* ************************************************************************* */ +template +void BayesNet::saveGraph(const std::string& s, + const KeyFormatter& keyFormatter) const { + std::ofstream of(s.c_str()); + of << "digraph G{\n"; + + for (auto conditional : boost::adaptors::reverse(*this)) { + typename CONDITIONAL::Frontals frontals = conditional->frontals(); + Key me = frontals.front(); + typename CONDITIONAL::Parents parents = conditional->parents(); + for (Key p : parents) + of << keyFormatter(p) << "->" << keyFormatter(me) << std::endl; } + of << "}"; + of.close(); } + +} // namespace gtsam diff --git a/gtsam/inference/BayesNet.h b/gtsam/inference/BayesNet.h index 0597ece98f..938278d5ad 100644 --- a/gtsam/inference/BayesNet.h +++ b/gtsam/inference/BayesNet.h @@ -57,16 +57,18 @@ namespace gtsam { /// @name Testable /// @{ - /** print out graph */ - void print(const std::string& s = "BayesNet", - const KeyFormatter& formatter = DefaultKeyFormatter) const; + /** print out graph */ + void print( + const std::string& s = "BayesNet", + const KeyFormatter& formatter = DefaultKeyFormatter) const override; - /// @} + /// @} - /// @name Standard Interface - /// @{ + /// @name Standard Interface + /// @{ - void saveGraph(const std::string &s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; + void saveGraph(const std::string& s, + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; }; } diff --git a/gtsam/inference/Factor.cpp b/gtsam/inference/Factor.cpp index 58448edbba..6fe96c7771 100644 --- a/gtsam/inference/Factor.cpp +++ b/gtsam/inference/Factor.cpp @@ -33,8 +33,8 @@ namespace gtsam { /* ************************************************************************* */ void Factor::printKeys(const std::string& s, const KeyFormatter& formatter) const { - std::cout << s << " "; - for(Key key: keys_) std::cout << " " << formatter(key); + std::cout << (s.empty() ? "" : s + " "); + for (Key key : keys_) std::cout << " " << formatter(key); std::cout << std::endl; } diff --git a/gtsam/inference/Factor.h b/gtsam/inference/Factor.h index 1aaaff0e43..57f95b0ea5 100644 --- a/gtsam/inference/Factor.h +++ b/gtsam/inference/Factor.h @@ -135,10 +135,14 @@ typedef FastSet FactorIndexSet; /// @{ /// print - void print(const std::string& s = "Factor", const KeyFormatter& formatter = DefaultKeyFormatter) const; + virtual void print( + const std::string& s = "Factor", + const KeyFormatter& formatter = DefaultKeyFormatter) const; /// print only keys - void printKeys(const std::string& s = "Factor", const KeyFormatter& formatter = DefaultKeyFormatter) const; + virtual void printKeys( + const std::string& s = "Factor", + const KeyFormatter& formatter = DefaultKeyFormatter) const; protected: /// check equality diff --git a/gtsam/inference/FactorGraph-inst.h b/gtsam/inference/FactorGraph-inst.h index df68019e12..e1c18274a8 100644 --- a/gtsam/inference/FactorGraph-inst.h +++ b/gtsam/inference/FactorGraph-inst.h @@ -37,7 +37,7 @@ namespace gtsam { template void FactorGraph::print(const std::string& s, const KeyFormatter& formatter) const { - std::cout << s << std::endl; + std::cout << (s.empty() ? "" : s + " ") << std::endl; std::cout << "size: " << size() << std::endl; for (size_t i = 0; i < factors_.size(); i++) { std::stringstream ss; diff --git a/gtsam/inference/FactorGraph.h b/gtsam/inference/FactorGraph.h index 9d2308d9b8..90b9d7ef23 100644 --- a/gtsam/inference/FactorGraph.h +++ b/gtsam/inference/FactorGraph.h @@ -285,9 +285,9 @@ class FactorGraph { /// @name Testable /// @{ - /** print out graph */ - void print(const std::string& s = "FactorGraph", - const KeyFormatter& formatter = DefaultKeyFormatter) const; + /// print out graph + virtual void print(const std::string& s = "FactorGraph", + const KeyFormatter& formatter = DefaultKeyFormatter) const; /** Check equality */ bool equals(const This& fg, double tol = 1e-9) const; diff --git a/gtsam/linear/GaussianBayesNet.h b/gtsam/linear/GaussianBayesNet.h index 06782c3cf2..a45168e0b1 100644 --- a/gtsam/linear/GaussianBayesNet.h +++ b/gtsam/linear/GaussianBayesNet.h @@ -177,6 +177,13 @@ namespace gtsam { */ VectorValues backSubstituteTranspose(const VectorValues& gx) const; + /// print graph + virtual void print( + const std::string& s = "", + const KeyFormatter& formatter = DefaultKeyFormatter) const override { + Base::print(s, formatter); + } + /** * @brief Save the GaussianBayesNet as an image. Requires `dot` to be * installed. diff --git a/gtsam/linear/GaussianFactor.h b/gtsam/linear/GaussianFactor.h index 9b4c5f940b..72ad696933 100644 --- a/gtsam/linear/GaussianFactor.h +++ b/gtsam/linear/GaussianFactor.h @@ -54,8 +54,11 @@ namespace gtsam { virtual ~GaussianFactor() {} // Implementing Testable interface - virtual void print(const std::string& s = "", - const KeyFormatter& formatter = DefaultKeyFormatter) const = 0; + + /// print + virtual void print( + const std::string& s = "", + const KeyFormatter& formatter = DefaultKeyFormatter) const override = 0; /** Equals for testable */ virtual bool equals(const GaussianFactor& lf, double tol = 1e-9) const = 0; diff --git a/gtsam/navigation/AttitudeFactor.cpp b/gtsam/navigation/AttitudeFactor.cpp index 7f335152e3..8c8eb5772f 100644 --- a/gtsam/navigation/AttitudeFactor.cpp +++ b/gtsam/navigation/AttitudeFactor.cpp @@ -42,7 +42,8 @@ Vector AttitudeFactor::attitudeError(const Rot3& nRb, //*************************************************************************** void Rot3AttitudeFactor::print(const string& s, const KeyFormatter& keyFormatter) const { - cout << s << "Rot3AttitudeFactor on " << keyFormatter(this->key()) << "\n"; + cout << (s.empty() ? "" : s + " ") << "Rot3AttitudeFactor on " + << keyFormatter(this->key()) << "\n"; nZ_.print(" measured direction in nav frame: "); bRef_.print(" reference direction in body frame: "); this->noiseModel_->print(" noise model: "); diff --git a/gtsam/navigation/AttitudeFactor.h b/gtsam/navigation/AttitudeFactor.h index 23fbbca892..3016b31aff 100644 --- a/gtsam/navigation/AttitudeFactor.h +++ b/gtsam/navigation/AttitudeFactor.h @@ -114,8 +114,8 @@ class GTSAM_EXPORT Rot3AttitudeFactor: public NoiseModelFactor1, public At } /** print */ - void print(const std::string& s, const KeyFormatter& keyFormatter = - DefaultKeyFormatter) const override; + void print(const std::string& s = "", const KeyFormatter& keyFormatter = + DefaultKeyFormatter) const override; /** equals */ bool equals(const NonlinearFactor& expected, double tol = 1e-9) const override; @@ -188,8 +188,8 @@ class GTSAM_EXPORT Pose3AttitudeFactor: public NoiseModelFactor1, } /** print */ - void print(const std::string& s, const KeyFormatter& keyFormatter = - DefaultKeyFormatter) const override; + void print(const std::string& s = "", const KeyFormatter& keyFormatter = + DefaultKeyFormatter) const override; /** equals */ bool equals(const NonlinearFactor& expected, double tol = 1e-9) const override; diff --git a/gtsam/navigation/GPSFactor.cpp b/gtsam/navigation/GPSFactor.cpp index f2448c4883..1d6b78e136 100644 --- a/gtsam/navigation/GPSFactor.cpp +++ b/gtsam/navigation/GPSFactor.cpp @@ -24,7 +24,8 @@ namespace gtsam { //*************************************************************************** void GPSFactor::print(const string& s, const KeyFormatter& keyFormatter) const { - cout << s << "GPSFactor on " << keyFormatter(key()) << "\n"; + cout << (s.empty() ? "" : s + " ") << "GPSFactor on " << keyFormatter(key()) + << "\n"; cout << " GPS measurement: " << nT_ << "\n"; noiseModel_->print(" noise model: "); } diff --git a/gtsam/navigation/GPSFactor.h b/gtsam/navigation/GPSFactor.h index f6469346e6..8fcf0f0994 100644 --- a/gtsam/navigation/GPSFactor.h +++ b/gtsam/navigation/GPSFactor.h @@ -71,8 +71,8 @@ class GTSAM_EXPORT GPSFactor: public NoiseModelFactor1 { } /// print - void print(const std::string& s, const KeyFormatter& keyFormatter = - DefaultKeyFormatter) const override; + void print(const std::string& s = "", const KeyFormatter& keyFormatter = + DefaultKeyFormatter) const override; /// equals bool equals(const NonlinearFactor& expected, double tol = 1e-9) const override; @@ -143,8 +143,8 @@ class GTSAM_EXPORT GPSFactor2: public NoiseModelFactor1 { } /// print - void print(const std::string& s, const KeyFormatter& keyFormatter = - DefaultKeyFormatter) const override; + void print(const std::string& s = "", const KeyFormatter& keyFormatter = + DefaultKeyFormatter) const override; /// equals bool equals(const NonlinearFactor& expected, double tol = 1e-9) const override; diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index 8c257f7ca1..adb6310e84 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -70,8 +70,9 @@ class GTSAM_EXPORT NonlinearFactor: public Factor { /// @{ /** print */ - virtual void print(const std::string& s = "", - const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; + virtual void print( + const std::string& s = "", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override; /** Check if two factors are equal */ virtual bool equals(const NonlinearFactor& f, double tol = 1e-9) const; diff --git a/gtsam/nonlinear/NonlinearFactorGraph.h b/gtsam/nonlinear/NonlinearFactorGraph.h index 989f493d39..9bca4a29d2 100644 --- a/gtsam/nonlinear/NonlinearFactorGraph.h +++ b/gtsam/nonlinear/NonlinearFactorGraph.h @@ -99,8 +99,9 @@ namespace gtsam { NonlinearFactorGraph(const FactorGraph& graph) : Base(graph) {} /** print */ - void print(const std::string& str = "NonlinearFactorGraph: ", - const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; + void print( + const std::string& str = "NonlinearFactorGraph: ", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override; /** print errors along with factors*/ void printErrors(const Values& values, const std::string& str = "NonlinearFactorGraph: ", diff --git a/gtsam/sfm/BinaryMeasurement.h b/gtsam/sfm/BinaryMeasurement.h index 99e553f7a2..7e102fee79 100644 --- a/gtsam/sfm/BinaryMeasurement.h +++ b/gtsam/sfm/BinaryMeasurement.h @@ -64,8 +64,8 @@ template class BinaryMeasurement : public Factor { /// @name Testable /// @{ - void print(const std::string &s, - const KeyFormatter &keyFormatter = DefaultKeyFormatter) const { + void print(const std::string &s, const KeyFormatter &keyFormatter = + DefaultKeyFormatter) const override { std::cout << s << "BinaryMeasurement(" << keyFormatter(this->key1()) << "," << keyFormatter(this->key2()) << ")\n"; traits::Print(measured_, " measured: "); diff --git a/gtsam/symbolic/SymbolicBayesNet.h b/gtsam/symbolic/SymbolicBayesNet.h index ca87b2bbc4..45df56abdd 100644 --- a/gtsam/symbolic/SymbolicBayesNet.h +++ b/gtsam/symbolic/SymbolicBayesNet.h @@ -63,6 +63,13 @@ namespace gtsam { /** Check equality */ GTSAM_EXPORT bool equals(const This& bn, double tol = 1e-9) const; + /// print + GTSAM_EXPORT void print( + const std::string& s = "SymbolicBayesNet", + const KeyFormatter& formatter = DefaultKeyFormatter) const override { + Base::print(s, formatter); + } + /// @} /// @name Standard Interface diff --git a/gtsam/symbolic/SymbolicConditional.cpp b/gtsam/symbolic/SymbolicConditional.cpp index d733c09378..f0d9944b22 100644 --- a/gtsam/symbolic/SymbolicConditional.cpp +++ b/gtsam/symbolic/SymbolicConditional.cpp @@ -20,18 +20,17 @@ namespace gtsam { - using namespace std; +using namespace std; - /* ************************************************************************* */ - void SymbolicConditional::print(const std::string& str, const KeyFormatter& keyFormatter) const - { - BaseConditional::print(str, keyFormatter); - } - - /* ************************************************************************* */ - bool SymbolicConditional::equals(const This& c, double tol) const - { - return BaseFactor::equals(c) && BaseConditional::equals(c); - } +/* ************************************************************************* */ +void SymbolicConditional::print(const std::string& str, + const KeyFormatter& keyFormatter) const { + BaseConditional::print(str, keyFormatter); +} +/* ************************************************************************* */ +bool SymbolicConditional::equals(const This& c, double tol) const { + return BaseFactor::equals(c) && BaseConditional::equals(c); } + +} // namespace gtsam diff --git a/gtsam/symbolic/SymbolicConditional.h b/gtsam/symbolic/SymbolicConditional.h index ead72a9894..4088cbfb66 100644 --- a/gtsam/symbolic/SymbolicConditional.h +++ b/gtsam/symbolic/SymbolicConditional.h @@ -105,7 +105,9 @@ namespace gtsam { /// @name Testable /** Print with optional formatter */ - virtual void print(const std::string& str = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; + virtual void print( + const std::string& str = "", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override; /** Check equality */ bool equals(const This& c, double tol = 1e-9) const; diff --git a/gtsam/symbolic/SymbolicFactor.h b/gtsam/symbolic/SymbolicFactor.h index 66657aa7da..2a488a4daf 100644 --- a/gtsam/symbolic/SymbolicFactor.h +++ b/gtsam/symbolic/SymbolicFactor.h @@ -92,6 +92,20 @@ namespace gtsam { bool equals(const This& other, double tol = 1e-9) const; + /// print + void print( + const std::string& s = "SymbolicFactor", + const KeyFormatter& formatter = DefaultKeyFormatter) const override { + Base::print(s, formatter); + } + + /// print only keys + void printKeys( + const std::string& s = "SymbolicFactor", + const KeyFormatter& formatter = DefaultKeyFormatter) const override { + Base::printKeys(s, formatter); + } + /// @} /// @name Advanced Constructors diff --git a/gtsam/symbolic/SymbolicFactorGraph.h b/gtsam/symbolic/SymbolicFactorGraph.h index b6f0de2aef..7f4c846314 100644 --- a/gtsam/symbolic/SymbolicFactorGraph.h +++ b/gtsam/symbolic/SymbolicFactorGraph.h @@ -88,6 +88,13 @@ namespace gtsam { bool equals(const This& fg, double tol = 1e-9) const; + /// print + void print( + const std::string& s = "SymbolicFactorGraph", + const KeyFormatter& formatter = DefaultKeyFormatter) const override { + Base::print(s, formatter); + } + /// @} /// @name Standard Interface diff --git a/gtsam_unstable/linear/InequalityFactorGraph.h b/gtsam_unstable/linear/InequalityFactorGraph.h index d042b04369..7016a7e97a 100644 --- a/gtsam_unstable/linear/InequalityFactorGraph.h +++ b/gtsam_unstable/linear/InequalityFactorGraph.h @@ -37,8 +37,9 @@ class InequalityFactorGraph: public FactorGraph { typedef boost::shared_ptr shared_ptr; /** print */ - void print(const std::string& str, const KeyFormatter& keyFormatter = - DefaultKeyFormatter) const { + void print( + const std::string& str = "", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override { Base::print(str, keyFormatter); } From 6c3aca8cac62989eee3c1d23db77e25ddc1f4b87 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 30 Apr 2021 12:58:52 -0400 Subject: [PATCH 2/2] remove virtual from overridden methods, add virtual destructors to appease compiler --- gtsam/discrete/DiscreteBayesNet.h | 3 +++ gtsam/discrete/DiscreteFactor.h | 2 +- gtsam/discrete/DiscreteFactorGraph.h | 3 +++ gtsam/linear/GaussianBayesNet.h | 5 ++++- gtsam/linear/GaussianFactor.h | 2 +- gtsam/linear/Preconditioner.h | 4 ++-- gtsam/nonlinear/NonlinearFactor.h | 5 ++--- gtsam/nonlinear/NonlinearFactorGraph.h | 3 +++ gtsam/sfm/BinaryMeasurement.h | 3 +++ gtsam/symbolic/SymbolicBayesNet.h | 3 +++ gtsam/symbolic/SymbolicConditional.h | 2 +- gtsam/symbolic/SymbolicFactorGraph.h | 3 +++ gtsam_unstable/discrete/Scheduler.cpp | 5 ++--- gtsam_unstable/discrete/Scheduler.h | 18 +++++++++++------- .../ConcurrentFilteringAndSmoothing.h | 8 ++++++-- gtsam_unstable/nonlinear/FixedLagSmoother.h | 4 +++- .../EquivInertialNavFactor_GlobalVel_NoBias.h | 4 +++- 17 files changed, 54 insertions(+), 23 deletions(-) diff --git a/gtsam/discrete/DiscreteBayesNet.h b/gtsam/discrete/DiscreteBayesNet.h index 237caf7451..d5ba30584c 100644 --- a/gtsam/discrete/DiscreteBayesNet.h +++ b/gtsam/discrete/DiscreteBayesNet.h @@ -55,6 +55,9 @@ namespace gtsam { template DiscreteBayesNet(const FactorGraph& graph) : Base(graph) {} + /// Destructor + virtual ~DiscreteBayesNet() {} + /// @} /// @name Testable diff --git a/gtsam/discrete/DiscreteFactor.h b/gtsam/discrete/DiscreteFactor.h index f8b3fc0bb3..6b0919507b 100644 --- a/gtsam/discrete/DiscreteFactor.h +++ b/gtsam/discrete/DiscreteFactor.h @@ -78,7 +78,7 @@ class GTSAM_EXPORT DiscreteFactor: public Factor { virtual bool equals(const DiscreteFactor& lf, double tol = 1e-9) const = 0; /// print - virtual void print( + void print( const std::string& s = "DiscreteFactor\n", const KeyFormatter& formatter = DefaultKeyFormatter) const override { Base::print(s, formatter); diff --git a/gtsam/discrete/DiscreteFactorGraph.h b/gtsam/discrete/DiscreteFactorGraph.h index 8df602af50..f39adc9a86 100644 --- a/gtsam/discrete/DiscreteFactorGraph.h +++ b/gtsam/discrete/DiscreteFactorGraph.h @@ -91,6 +91,9 @@ public EliminateableFactorGraph { template DiscreteFactorGraph(const FactorGraph& graph) : Base(graph) {} + /// Destructor + virtual ~DiscreteFactorGraph() {} + /// @name Testable /// @{ diff --git a/gtsam/linear/GaussianBayesNet.h b/gtsam/linear/GaussianBayesNet.h index a45168e0b1..e55a89bcda 100644 --- a/gtsam/linear/GaussianBayesNet.h +++ b/gtsam/linear/GaussianBayesNet.h @@ -55,6 +55,9 @@ namespace gtsam { template GaussianBayesNet(const FactorGraph& graph) : Base(graph) {} + /// Destructor + virtual ~GaussianBayesNet() {} + /// @} /// @name Testable @@ -178,7 +181,7 @@ namespace gtsam { VectorValues backSubstituteTranspose(const VectorValues& gx) const; /// print graph - virtual void print( + void print( const std::string& s = "", const KeyFormatter& formatter = DefaultKeyFormatter) const override { Base::print(s, formatter); diff --git a/gtsam/linear/GaussianFactor.h b/gtsam/linear/GaussianFactor.h index 72ad696933..3347228684 100644 --- a/gtsam/linear/GaussianFactor.h +++ b/gtsam/linear/GaussianFactor.h @@ -56,7 +56,7 @@ namespace gtsam { // Implementing Testable interface /// print - virtual void print( + void print( const std::string& s = "", const KeyFormatter& formatter = DefaultKeyFormatter) const override = 0; diff --git a/gtsam/linear/Preconditioner.h b/gtsam/linear/Preconditioner.h index 3a406c0a50..1a5a08090a 100644 --- a/gtsam/linear/Preconditioner.h +++ b/gtsam/linear/Preconditioner.h @@ -44,9 +44,9 @@ struct GTSAM_EXPORT PreconditionerParameters { inline Kernel kernel() const { return kernel_; } inline Verbosity verbosity() const { return verbosity_; } - void print() const ; + void print() const; - virtual void print(std::ostream &os) const ; + virtual void print(std::ostream &os) const; static Kernel kernelTranslator(const std::string &s); static Verbosity verbosityTranslator(const std::string &s); diff --git a/gtsam/nonlinear/NonlinearFactor.h b/gtsam/nonlinear/NonlinearFactor.h index adb6310e84..21c05dc2c4 100644 --- a/gtsam/nonlinear/NonlinearFactor.h +++ b/gtsam/nonlinear/NonlinearFactor.h @@ -70,9 +70,8 @@ class GTSAM_EXPORT NonlinearFactor: public Factor { /// @{ /** print */ - virtual void print( - const std::string& s = "", - const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override; + void print(const std::string& s = "", const KeyFormatter& keyFormatter = + DefaultKeyFormatter) const override; /** Check if two factors are equal */ virtual bool equals(const NonlinearFactor& f, double tol = 1e-9) const; diff --git a/gtsam/nonlinear/NonlinearFactorGraph.h b/gtsam/nonlinear/NonlinearFactorGraph.h index 9bca4a29d2..4d321f8aba 100644 --- a/gtsam/nonlinear/NonlinearFactorGraph.h +++ b/gtsam/nonlinear/NonlinearFactorGraph.h @@ -98,6 +98,9 @@ namespace gtsam { template NonlinearFactorGraph(const FactorGraph& graph) : Base(graph) {} + /// Destructor + virtual ~NonlinearFactorGraph() {} + /** print */ void print( const std::string& str = "NonlinearFactorGraph: ", diff --git a/gtsam/sfm/BinaryMeasurement.h b/gtsam/sfm/BinaryMeasurement.h index 7e102fee79..bdb45d622c 100644 --- a/gtsam/sfm/BinaryMeasurement.h +++ b/gtsam/sfm/BinaryMeasurement.h @@ -52,6 +52,9 @@ template class BinaryMeasurement : public Factor { measured_(measured), noiseModel_(model) {} + /// Destructor + virtual ~BinaryMeasurement() {} + /// @name Standard Interface /// @{ diff --git a/gtsam/symbolic/SymbolicBayesNet.h b/gtsam/symbolic/SymbolicBayesNet.h index 45df56abdd..464af060b6 100644 --- a/gtsam/symbolic/SymbolicBayesNet.h +++ b/gtsam/symbolic/SymbolicBayesNet.h @@ -55,6 +55,9 @@ namespace gtsam { template SymbolicBayesNet(const FactorGraph& graph) : Base(graph) {} + /// Destructor + virtual ~SymbolicBayesNet() {} + /// @} /// @name Testable diff --git a/gtsam/symbolic/SymbolicConditional.h b/gtsam/symbolic/SymbolicConditional.h index 4088cbfb66..3abec92b80 100644 --- a/gtsam/symbolic/SymbolicConditional.h +++ b/gtsam/symbolic/SymbolicConditional.h @@ -105,7 +105,7 @@ namespace gtsam { /// @name Testable /** Print with optional formatter */ - virtual void print( + void print( const std::string& str = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override; diff --git a/gtsam/symbolic/SymbolicFactorGraph.h b/gtsam/symbolic/SymbolicFactorGraph.h index 7f4c846314..36379fd831 100644 --- a/gtsam/symbolic/SymbolicFactorGraph.h +++ b/gtsam/symbolic/SymbolicFactorGraph.h @@ -81,6 +81,9 @@ namespace gtsam { template SymbolicFactorGraph(const FactorGraph& graph) : Base(graph) {} + /// Destructor + virtual ~SymbolicFactorGraph() {} + /// @} /// @name Testable diff --git a/gtsam_unstable/discrete/Scheduler.cpp b/gtsam_unstable/discrete/Scheduler.cpp index a810482917..3273778c4a 100644 --- a/gtsam_unstable/discrete/Scheduler.cpp +++ b/gtsam_unstable/discrete/Scheduler.cpp @@ -178,8 +178,7 @@ namespace gtsam { } // buildGraph /** print */ - void Scheduler::print(const string& s) const { - + void Scheduler::print(const string& s, const KeyFormatter& formatter) const { cout << s << " Faculty:" << endl; for(const string& name: facultyName_) cout << name << '\n'; @@ -210,7 +209,7 @@ namespace gtsam { CSP::print(s + " Factor graph"); cout << endl; - } // print + } // print /** Print readable form of assignment */ void Scheduler::printAssignment(sharedValues assignment) const { diff --git a/gtsam_unstable/discrete/Scheduler.h b/gtsam_unstable/discrete/Scheduler.h index 15ba60f46f..6faf9956f3 100644 --- a/gtsam_unstable/discrete/Scheduler.h +++ b/gtsam_unstable/discrete/Scheduler.h @@ -66,15 +66,17 @@ namespace gtsam { /** * Constructor - * WE need to know the number of students in advance for ordering keys. + * We need to know the number of students in advance for ordering keys. * then add faculty, slots, areas, availability, students, in that order */ - Scheduler(size_t maxNrStudents):maxNrStudents_(maxNrStudents) { - } + Scheduler(size_t maxNrStudents) : maxNrStudents_(maxNrStudents) {} + + /// Destructor + virtual ~Scheduler() {} - void addFaculty(const std::string& facultyName) { - facultyIndex_[facultyName] = nrFaculty(); - facultyName_.push_back(facultyName); + void addFaculty(const std::string& facultyName) { + facultyIndex_[facultyName] = nrFaculty(); + facultyName_.push_back(facultyName); } size_t nrFaculty() const { @@ -140,7 +142,9 @@ namespace gtsam { void buildGraph(size_t mutexBound = 7); /** print */ - void print(const std::string& s = "Scheduler") const; + void print( + const std::string& s = "Scheduler", + const KeyFormatter& formatter = DefaultKeyFormatter) const override; /** Print readable form of assignment */ void printAssignment(sharedValues assignment) const; diff --git a/gtsam_unstable/nonlinear/ConcurrentFilteringAndSmoothing.h b/gtsam_unstable/nonlinear/ConcurrentFilteringAndSmoothing.h index 316db921ae..c87b992750 100644 --- a/gtsam_unstable/nonlinear/ConcurrentFilteringAndSmoothing.h +++ b/gtsam_unstable/nonlinear/ConcurrentFilteringAndSmoothing.h @@ -47,7 +47,9 @@ class GTSAM_UNSTABLE_EXPORT ConcurrentFilter { virtual ~ConcurrentFilter() {}; /** Implement a standard 'print' function */ - virtual void print(const std::string& s = "Concurrent Filter:\n", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const = 0; + virtual void print( + const std::string& s = "Concurrent Filter:\n", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const = 0; /** Check if two Concurrent Smoothers are equal */ virtual bool equals(const ConcurrentFilter& rhs, double tol = 1e-9) const = 0; @@ -107,7 +109,9 @@ class GTSAM_UNSTABLE_EXPORT ConcurrentSmoother { virtual ~ConcurrentSmoother() {}; /** Implement a standard 'print' function */ - virtual void print(const std::string& s = "Concurrent Smoother:\n", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const = 0; + virtual void print( + const std::string& s = "Concurrent Smoother:\n", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const = 0; /** Check if two Concurrent Smoothers are equal */ virtual bool equals(const ConcurrentSmoother& rhs, double tol = 1e-9) const = 0; diff --git a/gtsam_unstable/nonlinear/FixedLagSmoother.h b/gtsam_unstable/nonlinear/FixedLagSmoother.h index 362cfae968..17fcf3908c 100644 --- a/gtsam_unstable/nonlinear/FixedLagSmoother.h +++ b/gtsam_unstable/nonlinear/FixedLagSmoother.h @@ -69,7 +69,9 @@ class GTSAM_UNSTABLE_EXPORT FixedLagSmoother { virtual ~FixedLagSmoother() { } /** Print the factor for debugging and testing (implementing Testable) */ - virtual void print(const std::string& s = "FixedLagSmoother:\n", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; + virtual void print( + const std::string& s = "FixedLagSmoother:\n", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; /** Check if two IncrementalFixedLagSmoother Objects are equal */ virtual bool equals(const FixedLagSmoother& rhs, double tol = 1e-9) const; diff --git a/gtsam_unstable/slam/EquivInertialNavFactor_GlobalVel_NoBias.h b/gtsam_unstable/slam/EquivInertialNavFactor_GlobalVel_NoBias.h index 9f5d800db9..40dc81c9ab 100644 --- a/gtsam_unstable/slam/EquivInertialNavFactor_GlobalVel_NoBias.h +++ b/gtsam_unstable/slam/EquivInertialNavFactor_GlobalVel_NoBias.h @@ -132,7 +132,9 @@ class EquivInertialNavFactor_GlobalVel_NoBias : public NoiseModelFactor4key1()) << "," << keyFormatter(this->key2()) << ","