From d4920687047dbf8b9fdbc353d993ca9fc85faf4e Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 11 Apr 2025 16:46:11 -0400 Subject: [PATCH] first restrict before checking numer of keys --- gtsam/hybrid/HybridNonlinearFactorGraph.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gtsam/hybrid/HybridNonlinearFactorGraph.cpp b/gtsam/hybrid/HybridNonlinearFactorGraph.cpp index 4f8cf45ee..6ab28ccb4 100644 --- a/gtsam/hybrid/HybridNonlinearFactorGraph.cpp +++ b/gtsam/hybrid/HybridNonlinearFactorGraph.cpp @@ -23,7 +23,6 @@ #include #include #include - namespace gtsam { /* ************************************************************************* */ @@ -237,10 +236,11 @@ HybridNonlinearFactorGraph HybridNonlinearFactorGraph::restrict( if (auto hf = dynamic_pointer_cast(f)) { result.push_back(hf->restrict(discreteValues)); } else if (auto df = dynamic_pointer_cast(f)) { - // In the case where all the values have been selected, we ignore the - // factor since it doesn't add any information - if (df->discreteKeys().size() > 0) { - result.push_back(df->restrict(discreteValues)); + auto restricted_df = df->restrict(discreteValues); + // In the case where all the discrete values have been selected, + // we ignore the factor since it doesn't add any information + if (restricted_df->discreteKeys().size() > 0) { + result.push_back(restricted_df); } } else { result.push_back(f); // Everything else is just added as is