From a1467c5e848ef19a08c4d8e8a112554bfb9cdc8e Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Thu, 30 Jan 2025 10:11:20 -0500 Subject: [PATCH] Guard all printing --- gtsam/hybrid/HybridSmoother.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gtsam/hybrid/HybridSmoother.cpp b/gtsam/hybrid/HybridSmoother.cpp index 65e9d9bd6..89e091c42 100644 --- a/gtsam/hybrid/HybridSmoother.cpp +++ b/gtsam/hybrid/HybridSmoother.cpp @@ -57,19 +57,23 @@ Ordering HybridSmoother::getOrdering(const HybridGaussianFactorGraph &factors, void HybridSmoother::update(const HybridGaussianFactorGraph &graph, std::optional maxNrLeaves, const std::optional given_ordering) { +#ifdef DEBUG_SMOOTHER std::cout << "hybridBayesNet_ size before: " << hybridBayesNet_.size() << std::endl; std::cout << "newFactors size: " << graph.size() << std::endl; +#endif HybridGaussianFactorGraph updatedGraph; // Add the necessary conditionals from the previous timestep(s). std::tie(updatedGraph, hybridBayesNet_) = addConditionals(graph, hybridBayesNet_); +#ifdef DEBUG_SMOOTHER // print size of graph, updatedGraph, hybridBayesNet_ std::cout << "updatedGraph size: " << updatedGraph.size() << std::endl; std::cout << "hybridBayesNet_ size after: " << hybridBayesNet_.size() << std::endl; std::cout << "total size: " << updatedGraph.size() + hybridBayesNet_.size() << std::endl; +#endif Ordering ordering; // If no ordering provided, then we compute one @@ -87,7 +91,7 @@ void HybridSmoother::update(const HybridGaussianFactorGraph &graph, // Eliminate. HybridBayesNet bayesNetFragment = *updatedGraph.eliminateSequential(ordering); -#ifdef DEBUG_SMOOTHER +#ifdef DEBUG_SMOOTHER_DETAIL for (auto conditional : bayesNetFragment) { auto e = std::dynamic_pointer_cast( conditional); @@ -95,11 +99,13 @@ void HybridSmoother::update(const HybridGaussianFactorGraph &graph, } #endif +#ifdef DEBUG_SMOOTHER // Print discrete keys in the bayesNetFragment: std::cout << "Discrete keys in bayesNetFragment: "; for (auto &key : HybridFactorGraph(bayesNetFragment).discreteKeySet()) { std::cout << DefaultKeyFormatter(key) << " "; } +#endif /// Prune if (maxNrLeaves) { @@ -111,14 +117,16 @@ void HybridSmoother::update(const HybridGaussianFactorGraph &graph, fixedValues_.insert(newlyFixedValues); } +#ifdef DEBUG_SMOOTHER // Print discrete keys in the bayesNetFragment: std::cout << "\nAfter pruning: "; for (auto &key : HybridFactorGraph(bayesNetFragment).discreteKeySet()) { std::cout << DefaultKeyFormatter(key) << " "; } std::cout << std::endl << std::endl; +#endif -#ifdef DEBUG_SMOOTHER +#ifdef DEBUG_SMOOTHER_DETAIL for (auto conditional : bayesNetFragment) { auto c = std::dynamic_pointer_cast( conditional); @@ -159,8 +167,6 @@ HybridSmoother::addConditionals(const HybridGaussianFactorGraph &originalGraph, auto conditional = hybridBayesNet.at(i); for (auto &key : conditional->frontals()) { - // GTSAM_PRINT(*std::dynamic_pointer_cast(conditional)); - // GTSAM_PRINT(*conditional); if (std::find(factorKeys.begin(), factorKeys.end(), key) != factorKeys.end()) { // Add the conditional parents to factorKeys @@ -173,7 +179,9 @@ HybridSmoother::addConditionals(const HybridGaussianFactorGraph &originalGraph, } } } +#ifdef DEBUG_SMOOTHER PrintKeySet(factorKeys); +#endif for (size_t i = 0; i < hybridBayesNet.size(); i++) { auto conditional = hybridBayesNet.at(i);