-
Notifications
You must be signed in to change notification settings - Fork 768
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
NoiseModelFactorN - fixed-number of variables >6 #947
Conversation
Dude, I love this! |
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 love this. Is there a way to replace some of the earlier factors with a typedef to this new factor? has to be 100% compatible of course.
Thanks!
I did consider this but decided to wait what you thought first. Glad you feel similarly :) I think the only extra things that wouldn't be possible with the typedef would be:
Because these have literal numbers in their names (and macros are processed before templates so we can't use macro magic to get these names). After fixing the CI failure, I'll draft a potential solution and see what you think. |
We can just add key1 to key6 and have it fail if N< less than six :-) There might even be template magic to only instantiate these methods up to N. |
…ypes/funcs in NoiseModelFactorN
Oh true I forgot about that! I implemented that - it's mostly done, except that the template <class VALUE1, class VALUE2, ...., class VALUE6>
using NoiseModelFactor6 = NoiseModelFactorN<VALUE1, VALUE2, VALUE3, VALUE4, VALUE5, VALUE6>; is causing some serialization issues. Here's a MWE: I'll think about this more later and maybe ask @ProfFan or @varunagrawal for help. |
Ping @gchenfc - I prefer you ask help from someone not Varun or Fan - both racing to deadlines. |
gtsam/nonlinear/NonlinearFactor.h
Outdated
@@ -272,503 +307,306 @@ class GTSAM_EXPORT NoiseModelFactor: public NonlinearFactor { | |||
|
|||
|
|||
/* ************************************************************************* */ | |||
/* We need some helper structs to help us with NoiseModelFactorN - specifically |
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.
A great exercise in meta-programming which I’d love to see disappear, see comment below :-)
Might be doable with the |
Thanks so much for the tip @jlblancoc! Would you mind clarifying which aspects you were thinking to include this? It's currently being used quite a bit here, e.g. gtsam/gtsam/nonlinear/NonlinearFactor.h Lines 404 to 406 in 11fd861
gtsam/gtsam/nonlinear/NonlinearFactor.h Lines 519 to 520 in 11fd861
but I'm hung up on all the "custom" additions for backwards compatibility, e.g. |
@gchenfc Ah, very good job then, IMO you are on the right track! 👍
I'm afraid gtsam is so used, it needs that backwards compatibility, so it should be kept despite the "ugliness" ;-) PS: I can't think of any "elegant" way to circumvent it, neither... |
@jlblancoc Cool, thanks for sharing + advice! much appreciated :) |
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.
@gchenfc this looks great except for some nitpicks. Can you please make the modifications and we can land this?
Thanks @varunagrawal for the review! I'll go through and add DEPRECATED - I think you created that after I had originally made this PR so I'm glad you reminded me of this! Can you also confirm the other 2 items and, if you still want those changes, I'll add those changes too.
I don't think this can directly be used in Matlab since |
@mattking-smith we'll be able to write a C++ class with 8+ variables (which isn't doable in current |
Thanks! Will merge once CI completes, assuming that github lets me; we may still need an approval from @dellaert since he previously requested changes (that have since been fixed I think). |
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 comments. This PR is a year old now :-) Could we meet and put a pin in it ? I really like the idea and want to have it in 4.2.
This reverts commit d62033a.
This is a byproduct of the overload resolution problem when N=1, then it can be hard to differentiate between: NoiseModelFactorN(noise, key) NoiseModelFactorN(noise, {key})
PS, re-reading some above, we definitely need to check that both wrappers (python and matlab) still work. @mattking-smith might be able to help with latter... |
Tested both and all pass! Python is tested by CI and I also ran on my machine, all pass. Matlab I tested on my machine and all pass, after needing to change some instances of Also, I put the "changing gtsam pre-made factors to inherit from |
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 an amazing piece of work, Gerry! Will merge so it’s ready to go into 4.2 :-)
Although this doesn't have an immediate use-case, I just wanted to work on this as a de-stressing exercise. Will not feel bad if it is rejected.
Currently there is
NoiseModelFactor1
,NoiseModelFactor2
, ...,NoiseModelFactor6
but nothing higher, so if you want to implement n-way factors where n is known at compile time but greater than 6, you have to derive fromNoiseModelFactor
and implementunwhitenedError
. This is fine, but I thought it'd be nice to have an n-way version that still has the convenientevaluateError
syntax.This might also be nice to use in place of existing
NoiseModelFactor1-6
classes in the future since, if the number of arguments for a given factor ever changes, it requires fewer changes (N is figured out by the compiler rather than hard-coded).