-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved HybridBayesNet API #1823
Conversation
Hmmm. If anything I want to get away from adding non-pointer types to FG/BN. There is just a useless copy and another allocation. The preferred style to promote is |
I don't see a My main motivation for this was to be able to add shared pointers to the hybrid Bayes net. Currently we can only add raw pointers. Adding support for non-pointer types is syntactic sugar, which makes tests less verbose. My hope is that the user is cognizant of the difference. I'll remove the const& on the shared pointer version and attempt to add |
The only things that should be possible going forward are
|
KeyVector frontalKeys{z}, continuousParents; | ||
DiscreteKeys discreteParents{m}; | ||
std::vector<GaussianConditional::shared_ptr> conditionals = {c0, c1}; | ||
auto gm = make_shared<GaussianMixture>(frontalKeys, continuousParents, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dellaert clang is having a hard time figuring out the constructor for the shared pointer if I use ({z}, {}, {m}, {c0, c1})
. It's so weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it is an issue regarding lvalues.
Okay done. |
gtsam/hybrid/HybridBayesNet.h
Outdated
} | ||
|
||
/** | ||
* Preferred: add a conditional directly using a pointer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, no, emplace_shared should be preferred. I don’t think this raw pointer call fits anything we have ever done in GTSAM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was pre-existing and confusing to me as well. I'm going to remove it.
I don’t see that. Can you check emplace_shared in FactorGraph.h ? |
gtsam/hybrid/HybridBayesNet.h
Outdated
* @param conditional The conditional as a shared pointer. | ||
*/ | ||
template <class CONDITIONAL> | ||
void push_back(std::shared_ptr<CONDITIONAL> conditional) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good. Although check what we do in GaussianBayesNet. I think we use const& to a shared pointer there. My comment before about const& was about a ref to the underlying object, not the shared pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GaussianBayesNet
inherits from FactorGraph
which has this method (which I followed), so no const& for the shared pointer:
/// Add a factor directly using a shared_ptr.
template <class DERIVEDFACTOR>
IsDerived<DERIVEDFACTOR> push_back(std::shared_ptr<DERIVEDFACTOR> factor) {
factors_.push_back(std::shared_ptr<FACTOR>(factor));
}
I should add const& since it provides a small performance benefit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!!!
HybridBayesNet
.HybridValues
into.h
and.cpp
.