Replace NoiseModelFactor1
in with NoiseModelFactorN
in pre-made factors
#1344
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow-up to #947 which applies this "new style"
NoiseModelFactorN
to existing factors in GTSAM (e.g.PriorFactor
,BetweenFactor
, ...) which, after #947 is merged, they will be using deprecated versions ofNoiseModelFactor123456
.I decided to separate this into a separate PR to keep file changes cleaner and because I think it might warrant more discussion (*sigh) and I don't want to drag out the other one if it doesn't have to.
Hiccup
In the process, I realized that this will introduce some backward compatibility issues. Specifically:
NoiseModelFactor2
(deprecated) toNoiseModelFactorN
, users will lose access to thekey2()
functions and the::X2
type aliases (inherited fromNoiseModelFactor2
) since the new usage is nowkey<2>()
and::ValueType<2>
.So, for example (I will use this example for the rest of this description, but all pre-made factors in GTSAM have similar issues):
Proposed Solutions
Allowing backward compatible access to
key2()
is not too ugly, so I just moved those intoNoiseModelFactorN
and deprecated them (fully backward compatible, but deprecated).But allowing backward compatible access to
::X2
is quite ugly (see here and below), so I just left these out (implemented inNoiseModelFactor2
, but not accessible fromBetweenFactor
anymore). I see 3 most reasonable options:BetweenFactor::X2
, they should change toBetweenFactor::ValueType<2>
. Use of::X2
seems pretty uncommon and didn't appear ever inside gtsam codebase including examples & tests (all unit tests pass).X1
andX2
insideBetweenFactor
(and for every pre-made factor in GTSAM). This is fine, but will just take a while and might add a lot of clutter.NoiseModelFactorN
(see below).gtsam/gtsam/nonlinear/NonlinearFactor.h
Lines 401 to 411 in 84e873e
Changes / notes:
NoiseModelFactor123456
->NoiseModelFactorN
X2
is nowValueType<2>
. e.g. any instances ofBetweenFactor<Pose3>::X2
need to be changed toBetweenFactor::ValueType<2>
. This applies to all pre-made factors in GTSAM.key1()
functions fromNoiseModelFactor1
toNoiseModelFactorN
. Although we had previously discussed that it would be cleaner to be inNoiseModelFactor1
, this will avoid breaking backward compatibility when changing pre-made factors to inherit fromNoiseModelFactorN
.NoiseModelFactorN
, some calls (inside the class only) get ugly due to dependent types. e.g.template
keyword is required here:gtsam/gtsam/slam/BetweenFactor.h
Lines 91 to 92 in a3e314f
This only affects calls inside the class and is similar to why we need to sometimes use
typename
. More details here. I know this is standard template syntax, but I do remember a couple years ago the first time I saw this syntax reading code I was really confused because it looks so weird, so I would like to minimize its use if possible to avoid confusing people.