diff --git a/gtsam/hybrid/HybridBayesNet.cpp b/gtsam/hybrid/HybridBayesNet.cpp index a80c4c0f2..841b74f4f 100644 --- a/gtsam/hybrid/HybridBayesNet.cpp +++ b/gtsam/hybrid/HybridBayesNet.cpp @@ -61,12 +61,13 @@ HybridBayesNet HybridBayesNet::prune(size_t maxNrLeaves) const { } } - // Prune the joint. NOTE: again, possibly quite expensive. - const DiscreteConditional::shared_ptr pruned = joint.prune(maxNrLeaves); + // Prune the joint. NOTE: imperative and, again, possibly quite expensive. + DiscreteConditional pruned(joint); + pruned.prune(maxNrLeaves); // Create a the result starting with the pruned joint. HybridBayesNet result; - result.push_back(std::move(pruned)); + result.push_back(std::make_shared(pruned)); /* To prune, we visitWith every leaf in the HybridGaussianConditional. * For each leaf, using the assignment we can check the discrete decision tree @@ -80,7 +81,7 @@ HybridBayesNet HybridBayesNet::prune(size_t maxNrLeaves) const { for (auto &&conditional : *this) { if (auto hgc = conditional->asHybrid()) { // Prune the hybrid Gaussian conditional! - auto prunedHybridGaussianConditional = hgc->prune(*pruned); + auto prunedHybridGaussianConditional = hgc->prune(pruned); // Type-erase and add to the pruned Bayes Net fragment. result.push_back(prunedHybridGaussianConditional); diff --git a/gtsam/hybrid/HybridBayesTree.cpp b/gtsam/hybrid/HybridBayesTree.cpp index 65664e2b1..22777600f 100644 --- a/gtsam/hybrid/HybridBayesTree.cpp +++ b/gtsam/hybrid/HybridBayesTree.cpp @@ -200,12 +200,11 @@ VectorValues HybridBayesTree::optimize(const DiscreteValues& assignment) const { /* ************************************************************************* */ void HybridBayesTree::prune(const size_t maxNrLeaves) { - auto discreteProbs = + auto prunedDiscreteProbs = this->roots_.at(0)->conditional()->asDiscrete(); - DiscreteConditional::shared_ptr prunedDiscreteProbs = - discreteProbs->prune(maxNrLeaves); - discreteProbs->setData(prunedDiscreteProbs); + // Imperative pruning + prunedDiscreteProbs->prune(maxNrLeaves); /// Helper struct for pruning the hybrid bayes tree. struct HybridPrunerData {