From bcc52becfbeb1af2c4cf966f03ccc3c30a9c91c9 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 4 Jan 2025 17:22:58 -0500 Subject: [PATCH] emplace then prune --- gtsam/hybrid/HybridBayesNet.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gtsam/hybrid/HybridBayesNet.cpp b/gtsam/hybrid/HybridBayesNet.cpp index 841b74f4fe..d6fd7e6bda 100644 --- a/gtsam/hybrid/HybridBayesNet.cpp +++ b/gtsam/hybrid/HybridBayesNet.cpp @@ -61,13 +61,15 @@ HybridBayesNet HybridBayesNet::prune(size_t maxNrLeaves) const { } } + // Create the result starting with the pruned joint. + HybridBayesNet result; + result.emplace_shared(joint); // Prune the joint. NOTE: imperative and, again, possibly quite expensive. - DiscreteConditional pruned(joint); - pruned.prune(maxNrLeaves); + result.back()->asDiscrete()->prune(maxNrLeaves); - // Create a the result starting with the pruned joint. - HybridBayesNet result; - result.push_back(std::make_shared(pruned)); + // Get pruned discrete probabilities so + // we can prune HybridGaussianConditionals. + DiscreteConditional pruned = *result.back()->asDiscrete(); /* To prune, we visitWith every leaf in the HybridGaussianConditional. * For each leaf, using the assignment we can check the discrete decision tree