From 4302ee33c96d5179f00394903869f80409246713 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Mon, 16 Sep 2024 13:30:07 -0400 Subject: [PATCH] make None the default HybridCategory --- gtsam/hybrid/HybridFactor.cpp | 27 +++++++++++++++++++-------- gtsam/hybrid/HybridFactor.h | 4 ++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gtsam/hybrid/HybridFactor.cpp b/gtsam/hybrid/HybridFactor.cpp index 89b1943cdf..5582166a3e 100644 --- a/gtsam/hybrid/HybridFactor.cpp +++ b/gtsam/hybrid/HybridFactor.cpp @@ -55,20 +55,28 @@ HybridFactor::HybridFactor(const KeyVector &keys) continuousKeys_(keys) {} /* ************************************************************************ */ -HybridFactor::HybridFactor(const KeyVector &continuousKeys, - const DiscreteKeys &discreteKeys) - : Base(CollectKeys(continuousKeys, discreteKeys)), - discreteKeys_(discreteKeys), - continuousKeys_(continuousKeys) { +HybridCategory GetCategory(const KeyVector &continuousKeys, + const DiscreteKeys &discreteKeys) { if ((continuousKeys.size() == 0) && (discreteKeys.size() != 0)) { - category_ = HybridCategory::Discrete; + return HybridCategory::Discrete; } else if ((continuousKeys.size() != 0) && (discreteKeys.size() == 0)) { - category_ = HybridCategory::Continuous; + return HybridCategory::Continuous; + } else if ((continuousKeys.size() != 0) && (discreteKeys.size() != 0)) { + return HybridCategory::Hybrid; } else { - category_ = HybridCategory::Hybrid; + // Case where we have no keys. Should never happen. + return HybridCategory::None; } } +/* ************************************************************************ */ +HybridFactor::HybridFactor(const KeyVector &continuousKeys, + const DiscreteKeys &discreteKeys) + : Base(CollectKeys(continuousKeys, discreteKeys)), + category_(GetCategory(continuousKeys, discreteKeys)), + discreteKeys_(discreteKeys), + continuousKeys_(continuousKeys) {} + /* ************************************************************************ */ HybridFactor::HybridFactor(const DiscreteKeys &discreteKeys) : Base(CollectKeys({}, discreteKeys)), @@ -98,6 +106,9 @@ void HybridFactor::print(const std::string &s, case HybridCategory::Hybrid: std::cout << "Hybrid "; break; + case HybridCategory::None: + std::cout << "None "; + break; } std::cout << "["; diff --git a/gtsam/hybrid/HybridFactor.h b/gtsam/hybrid/HybridFactor.h index 2cc7453f41..d0b9bbabe8 100644 --- a/gtsam/hybrid/HybridFactor.h +++ b/gtsam/hybrid/HybridFactor.h @@ -42,7 +42,7 @@ DiscreteKeys CollectDiscreteKeys(const DiscreteKeys &key1, const DiscreteKeys &key2); /// Enum to help with categorizing hybrid factors. -enum class HybridCategory { Discrete, Continuous, Hybrid }; +enum class HybridCategory { None, Discrete, Continuous, Hybrid }; /** * Base class for *truly* hybrid probabilistic factors @@ -57,7 +57,7 @@ enum class HybridCategory { Discrete, Continuous, Hybrid }; class GTSAM_EXPORT HybridFactor : public Factor { private: /// Record what category of HybridFactor this is. - HybridCategory category_; + HybridCategory category_ = HybridCategory::None; protected: // Set of DiscreteKeys for this factor.