use double dispatch for else case

release/4.3a0
Varun Agrawal 2025-01-05 15:19:57 -05:00
parent 8390ffa2cb
commit bc63cc8cb8
2 changed files with 7 additions and 0 deletions

View File

@ -70,6 +70,9 @@ namespace gtsam {
result = std::make_shared<TableFactor>((*tf) * TableFactor(*this));
} else if (auto dtf = std::dynamic_pointer_cast<DecisionTreeFactor>(f)) {
result = std::make_shared<DecisionTreeFactor>(this->operator*(*dtf));
} else {
// Simulate double dispatch in C++
result = std::make_shared<DecisionTreeFactor>(f->operator*(*this));
}
return result;
}

View File

@ -262,6 +262,10 @@ DiscreteFactor::shared_ptr TableFactor::multiply(
result = std::make_shared<TableFactor>(this->operator*(*tf));
} else if (auto dtf = std::dynamic_pointer_cast<DecisionTreeFactor>(f)) {
result = std::make_shared<TableFactor>(this->operator*(TableFactor(*dtf)));
} else {
// Simulate double dispatch in C++
result = std::make_shared<DecisionTreeFactor>(
f->operator*(this->toDecisionTreeFactor()));
}
return result;
}