-
Notifications
You must be signed in to change notification settings - Fork 767
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
boost::optional<const Ordering &> #156
Conversation
…s &>)` to overloaded `func(...)` and `func(..., const Class &)` not all done Also, although it currently passes all tests, I think some more tests may be needed...
compiles and passes tests, but some potentially code-breaking changes in: Marginals.h - order of arguments had to change since `factorization` has a default value EliminatableFactorGraph.h - marginalMultifrontalBayesNet and marginalMultifrontalBayesTree no longer accept `boost::none` as a placeholder to specify later arguments Notes: EliminateableFactorGraph.h - `orderingType` is no longer needed in function overloads that specify ordering, but I left it for the time being to avoid potential code breaking
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.
some notes
|
||
// Cast or convert to Jacobians | ||
FastVector<JacobianFactor::shared_ptr> jacobians = _convertOrCastToJacobians( | ||
graph); | ||
|
||
gttic(Order_slots); |
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.
4 new constructors (generated from combinations of 2 optional parameters) will use this same code so i moved it into a separate function, not sure why diff util didn't recognize it better
gtsam/nonlinear/Marginals.h
Outdated
Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization = CHOLESKY, | ||
EliminateableFactorGraph<GaussianFactorGraph>::OptionalOrdering ordering = boost::none); | ||
Marginals(const NonlinearFactorGraph& graph, const Values& solution, Factorization factorization = CHOLESKY); | ||
|
||
/** Construct a marginals class from a nonlinear factor graph. | ||
* @param graph The factor graph defining the full joint density on all variables. | ||
* @param solution The linearization point about which to compute Gaussian marginals (usually the MLE as obtained from a NonlinearOptimizer). | ||
* @param factorization The linear decomposition mode - either Marginals::CHOLESKY (faster and suitable for most problems) or Marginals::QR (slower but more numerically stable for poorly-conditioned problems). | ||
* @param ordering The ordering for elimination. | ||
*/ | ||
Marginals(const NonlinearFactorGraph& graph, const Values& solution, const Ordering& ordering, // argument order switch due to default value of factorization, potentially code breaking | ||
Factorization factorization = CHOLESKY); |
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.
note ordering
now comes before factorization
because factorization
has a default value
KeyVector keys = values.keys(); | ||
Ordering defaultOrdering(keys); | ||
return linearizeToHessianFactor(values, defaultOrdering, dampen); |
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.
is this tactic of creating a "default" ordering inefficient compared to creating a helper function? (as I did with the rest of the PR)
boost::shared_ptr<BayesTreeType> marginalMultifrontalBayesTree( | ||
boost::variant<const Ordering&, const KeyVector&> variables, | ||
OptionalOrdering marginalizedVariableOrdering = boost::none, | ||
const Ordering& marginalizedVariableOrdering, // this no longer takes boost::none - potentially code breaking | ||
const Eliminate& function = EliminationTraitsType::DefaultEliminate, | ||
OptionalVariableIndex variableIndex = boost::none) const; |
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.
potentially breaks code,
now becomesmarginalMultifrontalBayesTree(variables, boost::none, EliminationQR, variableIndex);
marginalMultifrontalBayesTree(variables, EliminationQR, variableIndex);
const Values& values, boost::optional<Ordering&> ordering, const Dampen& dampen) const { | ||
const Values& values, const Dampen& dampen) const { |
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.
potentially breaks code,
changes tolinearizeToHessianFactor(values, boost::none, dampen)
linearizeToHessianFactor(values, dampen)
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.
added deprecated function to .h file
Unfortunately, API breaking/ changing is not allowed here. So we have to find another solution |
Can we have a flag that enables another overload for |
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.
I added a bunch of comments. Did not get to Marginals yet, but I assume some of earlier comments I made establish a pattern...
@@ -250,10 +250,10 @@ HessianFactor::HessianFactor(const GaussianFactor& gf) : | |||
|
|||
/* ************************************************************************* */ | |||
HessianFactor::HessianFactor(const GaussianFactorGraph& factors, | |||
boost::optional<const Scatter&> scatter) { | |||
const Scatter& scatter) { |
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.
Are we doing scatter in this PR?
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.
I included Scatter to address issue #148
// Order variable slots - we maintain the vector of ordered slots, as well as keep a list | ||
// 'unorderedSlots' of any variables discovered that are not in the ordering. Those will then | ||
// be added after all of the ordered variables. | ||
FastVector<VariableSlots::const_iterator> orderedSlotsHelper( |
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.
Did not read in detail but is this a delegated constructor pattern?
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.
I instead put it in a member function rather than delegated constructor for a couple reasons:
- stuff needs to get done before the shared code, i.e.
JacobianFactor() {
// specific stuff createssome_variables
// common stuff relies onsome_variables
} - I didn't want to mess up the gttic() timings
In fact actually there are 2 helper functions (orderedSlotsHelper
and JacobianFactorHelper
), see constructor in line 409 for the quintessential example.
I also converted boost::optional<const VariableSlots &>
while I was here because it was convenient, but I can revert that if you prefer to keep this PR tidy.
Let’s keep this PR focused... |
also removed some edits that were tangential to the PR.
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.
addressed comments for API breaking changes, unrelated changes, and others.
@@ -250,10 +250,10 @@ HessianFactor::HessianFactor(const GaussianFactor& gf) : | |||
|
|||
/* ************************************************************************* */ | |||
HessianFactor::HessianFactor(const GaussianFactorGraph& factors, | |||
boost::optional<const Scatter&> scatter) { | |||
const Scatter& scatter) { |
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.
I included Scatter to address issue #148
// Order variable slots - we maintain the vector of ordered slots, as well as keep a list | ||
// 'unorderedSlots' of any variables discovered that are not in the ordering. Those will then | ||
// be added after all of the ordered variables. | ||
FastVector<VariableSlots::const_iterator> orderedSlotsHelper( |
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.
I instead put it in a member function rather than delegated constructor for a couple reasons:
- stuff needs to get done before the shared code, i.e.
JacobianFactor() {
// specific stuff createssome_variables
// common stuff relies onsome_variables
} - I didn't want to mess up the gttic() timings
In fact actually there are 2 helper functions (orderedSlotsHelper
and JacobianFactorHelper
), see constructor in line 409 for the quintessential example.
I also converted boost::optional<const VariableSlots &>
while I was here because it was convenient, but I can revert that if you prefer to keep this PR tidy.
gtsam/linear/Scatter.cpp
Outdated
} | ||
|
||
// Now, find dimensions of variables and/or extend | ||
void Scatter::setDimensions(const GaussianFactorGraph& gfg, size_t sortStart) { |
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.
changed to delegated constructor
* \endcode | ||
* */ | ||
boost::shared_ptr<BayesTreeType> eliminateMultifrontal( | ||
const Ordering& ordering, |
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.
done
const Values& values, boost::optional<Ordering&> ordering, const Dampen& dampen) const { | ||
const Values& values, const Dampen& dampen) const { |
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.
added deprecated function to .h file
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.
I have no time to do a second, detailed review. I propose @ProfFan goes through fine comb, and you wait to merge until he signs off. However, please resist expanding the scope of this PR, and please make absolutely sure it is backwards compatible. All API-breaking needs to be in deprecated
blocks.
@gchenfc We need to have API stability tests probably :( |
No, I vote not to retain them. Let's merge this once API calls are verified (by a detailed review, not by additional tests). Again, don't expand scope... |
@dellaert I am all good with that 👍 The current testset should have already validated the API calls, but I will double check. |
Status? |
Good to go. |
And, @ProfFan , by "good to go" you mean : you verified it's 100% backward compatible, yes? :-) |
It is 99% backward compatible due to the fact that if someone used the pattern |
BTW, this can be 100% if we retain the old |
Apologies for late reply, but I had already added deprecated overloads with |
@gchenfc Feel free to check and add :) Currently I have not found any issue in the current revision. |
ba3dcab16 Merge pull request #156 from borglab/fix/matlab-properties feb4ee1b9 update docs e57fec56b add unit test for templated class property git-subtree-dir: wrap git-subtree-split: ba3dcab16a8316634b56e3c4c6061531c91eb36c
Get rid of boost::optional, this PR is for Ordering and Scatter classes (should fix #148 ).
Replace all usages of boost::optional<*Ordering*> with function overloads.
compiles and passes tests, but some potentially code-breaking changes in:
factorization
has a default valueboost::none
as a placeholder to specify later argumentsNotes:
orderingType
is no longer needed in function overloads that specify ordering, but I left it for the time being to avoid potential code breakingThis change is