Fix MATLAB Eigen::Ref Jacobian output capture and overload dispatch
- Dominant language
- C++
- Stars
- 37
- Forks
- 17
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 9
Description
@thatdudegrantt This follows up on the Eigen `Ref` Jacobian-output work and [Copilot's review finding in GTSAM PR #2612](https://github.com/borglab/gtsam/pull/2612#discussion_r3681689465).
## Problem
The generated C++ MEX collector correctly writes the primary return value and Jacobians to `out[0]`, `out[1]`, etc., but the generated MATLAB `.m` stubs do not reliably expose those outputs.
Two related problems are present:
1. Jacobian overload calls capture only one MEX result:
```matlab
varargout{1} = (...);
```
This discards the additional Jacobian outputs. Instance and static method generation both need an LHS that captures all requested outputs, such as:
```matlab
[varargout{1:nargout}] = (...);
```
2. A non-Jacobian overload can appear first with the same non-`Ref` `varargin` signature. It has no `nargout` constraint, so it matches and returns before the later `nargout == N` Jacobian overload is reached.
For example, generated `transformFrom` dispatch currently has the ordinary one-argument overload before the one-argument-plus-`nargout == 3` Jacobian overload.
## Expected behavior
Calls such as:
```matlab
[result, Hself, Hpoint] = pose.transformFrom(point);
[result, H] = pose.inverse();
[result, Hxi] = gtsam.Pose3.Expmap(xi);
```
should select the Jacobian overload and return every MEX output.
## Suggested scope
- Generate a multi-output MATLAB LHS for Eigen `Ref` output overloads.
- Apply the behavior consistently to instance and static methods.
- Prioritize Jacobian overload dispatch or constrain the non-Jacobian sibling by `nargout`.
- Extend `test_eigen_ref_jacobians` to assert the generated `.m` assignment and ordering/selection, not only the `nargout` predicate and C++ `out[]` writes.
The existing focused test passes despite the broken generated MATLAB stub because those two properties are not currently asserted.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.