Skip to content

Fix MATLAB interface boundaries and enum value wrapping - #213

Merged
dellaert merged 1 commit into
masterfrom
fix/matlab-interface-boundaries-and-enums
Oct 18, 2026
Merged

dellaert merged 1 commit into
masterfrom
fix/matlab-interface-boundaries-and-enums

Conversation

@dellaert

Copy link
Copy Markdown
Member

Summary

Fix three MATLAB generator defects found while validating GTSAM's robust noise model wrappers:

  • Separate input interface files with a newline. A final // comment without a newline could swallow the next file's namespace or declarations.
  • Preserve individual namespace components when placing class enums. For example, gtsam::noiseModel::mEstimator::Base::ReweightScheme belongs in +gtsam/+noiseModel/+mEstimator/+Base, rather than +gtsamnoiseModelmEstimator/+Base.
  • Resolve enum types using their declared owners before generating conversions. A method accepting another class's enum previously used unwrap_shared_ptr<Enum>; passing Base.ReweightScheme.Scalar to AsymmetricCauchy.Create crashed MATLAB after the path issue was corrected. Enum arguments now use unwrap_enum, and enum results use the owning MATLAB enum class.

The enum lookup includes declarations appearing later in the input and preserves the MATLAB names of template instantiations. It is shared by arguments, properties, ordinary results, optional values, and pair results. The existing enum fixture changes only to fully qualify two C++ template enum types.

Validation

  • Reproduced the file-boundary and nested-package failures before their fixes, and a failing regression for enum conversion/owner resolution before that fix.
  • python -m pytest -o addopts='' tests: 137 passed on Python 3.12/macOS.
  • Regressions cover missing/LF/CRLF file endings; zero through three namespace levels; template aliases; enums declared on other classes; owner declaration order; and identically named enums.
  • Compiled a standalone MEX for the enum regression fixture with Apple Clang and ran it in MATLAB R2025b. Constructor arguments, static/instance methods, property get/set, global functions, optional values, and pair results passed.
  • Generated all 23 unmodified GTSAM interface files, compiled and linked the full MEX, and verified nested enum lookup and Scalar/Block arguments to AsymmetricCauchy.Create and AsymmetricTukey.Create in MATLAB R2025b. The original crashing call now passes. Final generated C++ was verified byte-identical to the compiled source.

GTSAM follow-up

GTSAM still needs to sync this subtree and adjust the separate explicit std::shared_ptr declarations for Robust.Create and its accessors to the wrapper's supported shared-pointer notation. Those interface declaration changes belong in GTSAM.

@dellaert
dellaert requested review from ProfFan and a balanced review from Copilot October 18, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved findings remain, and targeted regression coverage supports the generator fixes.

No open issues 🎉

What changed in this PR

Fixes MATLAB wrapper generation for interface-file boundaries, nested enum packages, and enum conversions using their declared owners.

Changes:

  • Separates interface files with newlines to prevent trailing comments consuming declarations.
  • Preserves namespace components and template aliases when resolving enum types.
  • Adds regressions for file boundaries, enum ownership, and value conversions.
File Description
tests/​test_matlab_wrapper.py Adds boundary, namespace, alias, and enum conversion regressions.
tests/​fixtures/​matlab_enum_arguments.i Adds cross-class enum coverage with later owner declarations.
tests/​expected/​matlab/​enum_wrapper.cpp Fully qualifies two expected C++ template enum types.
gtwrap/​matlab_wrapper/​wrapper.py Fixes file separation, enum paths, registration, and conversions.
gtwrap/​matlab_wrapper/​mixins.py Resolves declared enum owners while preserving template aliases.

Review effort: Balanced

@dellaert
dellaert merged commit 9c88a5c into master Oct 18, 2026
9 checks passed
@dellaert
dellaert deleted the fix/matlab-interface-boundaries-and-enums branch October 18, 2026 23:31
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.

3 participants