Clarify JointMarginal::at()/operator() indexing semantics (Key, not position)#2592
Merged
dellaert merged 2 commits intoJul 7, 2026
Merged
Conversation
expanded comment explains confusion within borglab#1305
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
JointMarginal::at(iVariable, jVariable)(and itsoperator()equivalent) ingtsam/linear/JointMarginal.htakes the actual nonlinearKeysused to construct theJointMarginal, not positional/row indices into the underlying block matrix. This wasn't documented, and it caused confusion in #1305, where a user comparedjoint_covs.at(0, key)againstmarginals.marginalCovariance(key)expecting them to match. They don't, andat(0, key)returns the cross-covariance block between variable 0 and variable key, not the diagonal (self-covariance) block for key. The correct call for that comparison isat(key, key).This PR is a comment-only clarification of the existing behavior. No functional/behavioral changes, as
operator()andat()are untouched apart from the docstrings.Fixes #1305
Change
Updated the doc comments on
JointMarginal::operator()andJointMarginal::at()ingtsam/linear/JointMarginal.hto explicitly state that arguments are Keys (not indices), and thatat(key, key)is the call equivalent toMarginals::marginalCovariance(key).Testing
Documentation-only change, so no code paths affected and no new tests are needed. I also verified the existing unit tests
(testMarginals)still pass unmodified, confirming no behavioral change.Environment
OS: Windows 11 x64
Compiler: Visual Studio 2026 Community, MSVC 19.51
CMake: 4.2.3