Fix MATLAB wrapper virtual class downcasting for namespaced types#187
Merged
ProfFan merged 1 commit intoJun 30, 2026
Merged
Conversation
7dccf51 to
29d4073
Compare
Contributor
Author
|
CI is passing. Verified end-to-end on Windows x64, MSVC 19.51, MATLAB R2026a. |
Collaborator
|
Cool I'll review today |
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.
Problem
gtsam.noiseModel.Gaussian.Information(Q)with a scalar/diagonal matrix correctly downcasts toIsotropicin C++, but the MATLAB wrapper always returned agtsam.noiseModel.Gaussianobject. This causedJacobianFactorand similar functions that require a diagonal noise model to fail.Root cause (two bugs)
_collector_returnandwrap_collector_function_return_typesalways passedisVirtual=falsetowrap_shared_ptr, bypassing the RTTI registry entirely even for classes declaredvirtualin the.ifile.generate_preamblestored flat concatenated names (e.g.gtsamnoiseModelIsotropic) in the RTTI registry instead of dot-separated MATLAB package names (e.g.gtsam.noiseModel.Isotropic), causingmexCallMATLABto fail for any namespaced virtual class.Fix
Check
cls.is_virtualagainstself.classesin both return codegen functions and passtruetowrap_shared_ptrfor virtual classes.Use
_format_class_name(cls, separator='.')for RTTI registry entries.Testing
Verified end-to-end on Windows x64, MSVC 19.51, MATLAB R2026a:
All 10 existing wrap Python tests pass. Added virtual base/derived fixture to
tests/fixtures/inheritance.ito cover theisVirtual=truecodegen case.Fixes borglab/gtsam#605