more robust product

release/4.3a0
Varun Agrawal 2025-01-05 15:20:09 -05:00
parent bc63cc8cb8
commit 713c49c915
1 changed files with 10 additions and 3 deletions

View File

@ -65,9 +65,16 @@ namespace gtsam {
/* ************************************************************************ */
DecisionTreeFactor DiscreteFactorGraph::product() const {
DiscreteFactor::shared_ptr result = *this->begin();
for (auto it = this->begin() + 1; it != this->end(); ++it) {
if (*it) result = result->multiply(*it);
DiscreteFactor::shared_ptr result;
for (auto it = this->begin(); it != this->end(); ++it) {
if (*it) {
if (result) {
result = result->multiply(*it);
} else {
// Assign to the first non-null factor
result = *it;
}
}
}
return result->toDecisionTreeFactor();
}