Skip to content

MatrixLieGroup implementation and traits#2187

Merged
dellaert merged 22 commits intodevelopfrom
feature/MatrixLieGroup.h
Jul 6, 2025
Merged

MatrixLieGroup implementation and traits#2187
dellaert merged 22 commits intodevelopfrom
feature/MatrixLieGroup.h

Conversation

@dellaert
Copy link
Copy Markdown
Member

@dellaert dellaert commented Jul 4, 2025

UPDATE: took timing and new vecs out of this PR for easier review, avoid segafult in #2191 .

This PR introduces a significant refactoring of how matrix Lie groups are handled in GTSAM, aiming to reduce code duplication and improve consistency:

  • New MatrixLieGroup Concept: A new CRTP helper class MatrixLieGroup has been introduced in gtsam/base/MatrixLieGroup.h. This class provides generic implementations for common matrix Lie group operations like vec() (vectorization of the matrix representation) and AdjointMap().
  • Refactoring of Lie.h: Existing MatrixLieGroup related definitions and functions have been moved from gtsam/base/Lie.h to the new gtsam/base/MatrixLieGroup.h. The AdjointMap assignment in IsLieGroup concept check in Lie.h was also corrected.
  • Migration of Geometry Classes: Numerous geometry classes (e.g., Gal3, Pose2, Pose3, Rot2, SO3, SO4, SO, Similarity2, Similarity3, NavState) have been updated to inherit from MatrixLieGroup instead of LieGroup.
  • Removal of Redundant Implementations: Individual vec() and AdjointMap() implementations in various geometry classes have been removed, as they now leverage the generic implementations provided by MatrixLieGroup.
  • Updated traits Specializations: The traits specializations for the migrated classes have been updated to use internal::MatrixLieGroup.
  • New Tests: Added tests verify the correctness of the generic AdjointMap() and vec() implementations for various matrix Lie groups.
  • FrobeniusFactor Updates: FrobeniusFactor and FrobeniusBetweenFactor now utilize the generic traits::Vec and traits::AdjointMap methods.

@dellaert dellaert requested a review from Copilot July 4, 2025 10:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors how matrix Lie groups are implemented by introducing a generic MatrixLieGroup CRTP helper and migrating existing geometry and dynamics classes to use it, removing duplicate vectorization and adjoint implementations, and updating dependent factors and tests.

  • Introduce MatrixLieGroup concept in gtsam/base/MatrixLieGroup.h with default implementations of vec() and AdjointMap().
  • Migrate geometry classes (SO3, Pose2, Pose3, Gal3, NavState, etc.) to inherit from MatrixLieGroup instead of LieGroup, removing their specialized vec() and AdjointMap() code.
  • Update FrobeniusFactor and FrobeniusBetweenFactor to assert IsMatrixLieGroup<T> and use traits<T>::Vec / traits<T>::AdjointMap for vectorization and adjoint computations.

Reviewed Changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated no comments.

Show a summary per file
File Description
gtsam/base/MatrixLieGroup.h Added CRTP helper MatrixLieGroup with generic vec() and AdjointMap()
gtsam/slam/FrobeniusFactor.h Added IsMatrixLieGroup asserts and switched to traits<T>::Vec/AdjointMap
gtsam/geometry/SO3.h Changed SO3 to inherit from MatrixLieGroup<SO3,3,3> and removed old code
gtsam/geometry/Pose3.h Switched Pose3 to MatrixLieGroup<Pose3,6,4> and removed vec() override
gtsam/navigation/NavState.h Switched NavState to MatrixLieGroup<NavState,9,5> and updated traits
Comments suppressed due to low confidence (3)

gtsam/geometry/tests/testGal3.cpp:1202

  • [nitpick] The test name uses lowercase 'vec' whereas other vec tests (e.g., TEST(Pose3, Vec)) use uppercase 'Vec' for consistency. Consider renaming to TEST(Gal3, Vec).
TEST(Gal3, AdjointMap) {

gtsam/geometry/SOn.h:54

  • The generic implementation for SOn via MatrixLieGroup is introduced here, but there are no corresponding unit tests for SOn< N > (especially for N>4 or dynamic N). Consider adding tests for vec() and AdjointMap() to validate the generic code.
class SO : public MatrixLieGroup<SO<N>, internal::DimensionSO(N), N> {

gtsam/geometry/SOn.cpp:102

  • [nitpick] There are large blocks of commented-out legacy vec() implementations across geometry sources (e.g., SOn.cpp). Since MatrixLieGroup now provides the generic implementation, these commented sections can be removed to improve code clarity.
  return result;

@dellaert dellaert requested a review from ProfFan July 4, 2025 10:15
@dellaert dellaert changed the base branch from develop to feature/timing July 5, 2025 09:16
@dellaert dellaert requested a review from mkielo3 July 5, 2025 09:22
@dellaert
Copy link
Copy Markdown
Member Author

dellaert commented Jul 5, 2025

@mkielo3 adding you to look at Gal3 changes. After this PR merges you should probably rebase your changes on this.

@dellaert dellaert changed the base branch from feature/timing to develop July 5, 2025 13:35
@dellaert dellaert force-pushed the feature/MatrixLieGroup.h branch from f5cdd48 to daa86fe Compare July 5, 2025 13:36
@dellaert dellaert merged commit a16dff3 into develop Jul 6, 2025
78 checks passed
@dellaert dellaert deleted the feature/MatrixLieGroup.h branch July 6, 2025 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants