Update eigen support calling conventions#598
Merged
patkenneally merged 4 commits intoMay 1, 2026
Merged
Conversation
The conventions used throughout this header (compile-time shape enforcement, row-major C-array layout, MatrixBase<Derived> on output side, raw const pointers on input side, etc.) were already in force but only implicit. State them explicitly so future contributions stay consistent and so the deliberate FSW vs simulation tradeoff between fixed-size and dynamic-size variants is recorded in source.
The previous signature took `const Eigen::Vector<ScalarT, size>&`, which rejected Eigen expression types like `Vector3f::Zero()` and `block<>()` even though every other output-side function in this header already accepts `MatrixBase<Derived>`. The destination is also tightened from a raw `ScalarT*` to a sized array reference `Scalar (&)[size]`, matching `eigenMatrixToCArray` and giving the same compile-time bounds guarantee. All existing call sites pass fixed-size message struct fields or stack arrays, so none need to change. Add EigenVectorToCArrayAcceptsExpression covering both `Zero()` and a block expression (the PlainObject evaluation path).
The previous parameter `ScalarT in2DArray[3][3]` decays to a non-const `ScalarT (*)[3]` pointer, so the outer dimension was unenforced and const-qualified callers could not bind. Switching to `const ScalarT (&in2DArray)[3][3]` enforces both dimensions at compile time and matches the const-input convention used elsewhere in this header. All existing call sites pass non-const `[3][3]` lvalues, which still bind to the const reference, so no caller needs to change. Add C2DArrayToEigenMatrix3AcceptsConstInput as a regression test in the same style as the other AcceptsConstInput tests - it will fail to compile if the const qualifier is ever removed.
eigenTilde previously read vec(0)/(1)/(2) from any vector-shaped
input, so a 4-vector or a 1x3 row would silently produce a
meaningless skew matrix. Add shape enforcement consistent with the
header's fixed-vs-dynamic split:
- Fixed-size types are validated at compile time with static_assert
on RowsAtCompileTime == 3 and ColsAtCompileTime == 1.
- Dynamic-size types (e.g. MatrixXd state property refs in
GravityGradientEffector and spacecraft) are still accepted at
compile time and validated at runtime via std::terminate() on
shape mismatch.
No call sites need updating. The relaxation to admit dynamic-size
inputs preserves behavior for the two real callers that pass a
runtime-sized state property.
JulianHammerl
approved these changes
May 1, 2026
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.
Eigen::Vector3f::Zero()toeigenVectorToCArraydoesn't compile #597Description
This PR fixes the issue that compilation failes when passing an
Eigen::Vector3f::Zero()(an Eigen expressionConstantReturnType), toeigenVectorToCArray. Every other output-side function in the suite already accepts MatrixBase and would have compiled.The PR also adds design goals to the top of
eigenSupport.hto make clear why the function signatures are the way they are. And two other inconsistencies in call conventions are fixed.Verification
Additional tests are added. Specifically,
EigenVectorToCArrayAcceptsExpressiontest which coversZero()and a block expression. AlsoC2DArrayToEigenMatrix3AcceptsConstInputregression test to ensure compilation would fail should someone change the calling signatures in a way contrary to the documented design goals.Documentation
Added design goals into the file for future reference.
Future work
None