Skip to content

Commit

Permalink
make None the default HybridCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Sep 16, 2024
1 parent 97eb6bc commit 4302ee3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
27 changes: 19 additions & 8 deletions gtsam/hybrid/HybridFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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 << "[";
Expand Down
4 changes: 2 additions & 2 deletions gtsam/hybrid/HybridFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 4302ee3

Please sign in to comment.