@thatdudegrantt This follows up on the Eigen Ref<MatrixXd> Jacobian-output work and Copilot's review finding in GTSAM PR #2612.
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:
-
Jacobian overload calls capture only one MEX result:
varargout{1} = <mex>(...);
This discards the additional Jacobian outputs. Instance and static method generation both need an LHS that captures all requested outputs, such as:
[varargout{1:nargout}] = <mex>(...);
-
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:
[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.
@thatdudegrantt This follows up on the Eigen
Ref<MatrixXd>Jacobian-output work and Copilot's review finding in GTSAM PR #2612.Problem
The generated C++ MEX collector correctly writes the primary return value and Jacobians to
out[0],out[1], etc., but the generated MATLAB.mstubs do not reliably expose those outputs.Two related problems are present:
Jacobian overload calls capture only one MEX result:
varargout{1} = <mex>(...);This discards the additional Jacobian outputs. Instance and static method generation both need an LHS that captures all requested outputs, such as:
[varargout{1:nargout}] = <mex>(...);A non-Jacobian overload can appear first with the same non-
Refvararginsignature. It has nonargoutconstraint, so it matches and returns before the laternargout == NJacobian overload is reached.For example, generated
transformFromdispatch currently has the ordinary one-argument overload before the one-argument-plus-nargout == 3Jacobian overload.Expected behavior
Calls such as:
should select the Jacobian overload and return every MEX output.
Suggested scope
Refoutput overloads.nargout.test_eigen_ref_jacobiansto assert the generated.massignment and ordering/selection, not only thenargoutpredicate and C++out[]writes.The existing focused test passes despite the broken generated MATLAB stub because those two properties are not currently asserted.