Skip to content

Update eigen support calling conventions#598

Merged
patkenneally merged 4 commits into
developfrom
feature/update-eigen-support-calling-conventions
May 1, 2026
Merged

Update eigen support calling conventions#598
patkenneally merged 4 commits into
developfrom
feature/update-eigen-support-calling-conventions

Conversation

@patkenneally

Copy link
Copy Markdown
Collaborator

Description

This PR fixes the issue that compilation failes when passing an Eigen::Vector3f::Zero() (an Eigen expression ConstantReturnType), to eigenVectorToCArray. 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.h to 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, EigenVectorToCArrayAcceptsExpression test which covers Zero() and a block expression. Also C2DArrayToEigenMatrix3AcceptsConstInput regression 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

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.
@patkenneally patkenneally merged commit 2bf8f12 into develop May 1, 2026
5 checks passed
@patkenneally patkenneally deleted the feature/update-eigen-support-calling-conventions branch May 1, 2026 19:40
@github-project-automation github-project-automation Bot moved this to Done in Xmera May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Passing Eigen::Vector3f::Zero() to eigenVectorToCArray doesn't compile

2 participants