Skip to content

COMP: Wrap ESMDemonsRegistrationFunction only with matching vector dim#6591

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix/esm-demons-wrap-vector-dim
Jul 13, 2026
Merged

COMP: Wrap ESMDemonsRegistrationFunction only with matching vector dim#6591
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix/esm-demons-wrap-vector-dim

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Restrict itkESMDemonsRegistrationFunction.wrap to vector dimension == image dimension, matching the sibling DiffeomorphicDemonsRegistrationFilter wrapping. This removes the root cause of the recurring GCC 11.4 nightly -Waggressive-loop-optimizations warnings in itkWarpImageFilter.hxx and itkESMDemonsRegistrationFunction.hxx.

Root cause

The wrap file generated cross products such as
ESMDemonsRegistrationFunction<Image<float,3>, Image<float,3>, Image<Vector<float,2>,3>>.
Those instantiations index a 2-component displacement vector with loops bound by
ImageDimension — undefined behavior if ever executed, and provably out of bounds
to GCC's unroller (iteration 2 invokes undefined behavior). Because
ESMDemonsRegistrationFunction holds a WarpImageFilter member, one bad combination
warns in both headers.

Reproduced locally with conda-forge gcc 11.4 (same as the Ubuntu-22.04-gcc11.4-Rel-Python
nightly): a single mismatched explicit instantiation emits exactly the four dashboard
warning sites; matched-dimension instantiations are clean.

Two earlier attempts patched the loop code instead of the instantiation: PR #6367
switched to a runtime GetLength bound, then commit d4a40cb reverted to
ImageDimension because the runtime bound traded one warning for another. Neither
addressed the mismatched instantiation, so the warning returned on the nightly.

The removed Python types (e.g. itkESMDemonsRegistrationFunctionIF3IF3IVF23) were
broken by construction: NumericTraits::SetLength(update, ImageDimension) cannot
resize a fixed Vector<float,2>, so any use was UB.

The wrap file generated cross products such as
ESMDemonsRegistrationFunction<Image<float,3>,Image<float,3>,
Image<Vector<float,2>,3>>. Those instantiations index a 2-component
displacement vector with loops bound by ImageDimension, which GCC 11.4
diagnoses as -Waggressive-loop-optimizations in itkWarpImageFilter.hxx
and itkESMDemonsRegistrationFunction.hxx on the nightly dashboard, and
which is undefined behavior if ever executed. Restrict the wrapped
combinations to vector dimension == image dimension, matching the
sibling DiffeomorphicDemonsRegistrationFilter wrapping.
@github-actions github-actions Bot added type:Compiler Compiler support or related warnings area:Python wrapping Python bindings for a class labels Jul 12, 2026
@hjmjohnson hjmjohnson marked this pull request as ready for review July 12, 2026 22:35
@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR narrows the Python wrapping for ESMDemonsRegistrationFunction. The main changes are:

  • Replaces broad image-filter wrapping combinations with explicit template registrations.
  • Iterates over configured image dimensions and scalar/vector pixel types.
  • Keeps only displacement vector component counts that match the image dimension.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

No files need attention.

T-Rex T-Rex Logs

What T-Rex did

  • Validated the esmdemons contract by inspecting the initial tool availability and before-state, confirming missing cmake, ninja, pixi, ctest, swig, and castxml while GCC/G++ and Python were available.
  • Executed the after-state validation and verified all eight checks passed, with no cross-product helper remaining and matching-dimension placeholders aligned.
  • Ran the validation script esmdemons_validate_wrap.py and reviewed repository diffs, confirming the working tree had no diff for the file relative to HEAD while the before comparison used HEAD^.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
Modules/Nonunit/Review/wrapping/itkESMDemonsRegistrationFunction.wrap Generates matched image/vector dimension wrappers for ESMDemonsRegistrationFunction; no actionable issue found.

Reviews (1): Last reviewed commit: "COMP: Wrap ESMDemonsRegistrationFunction..." | Re-trigger Greptile

@hjmjohnson hjmjohnson merged commit 28da458 into InsightSoftwareConsortium:main Jul 13, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Python wrapping Python bindings for a class type:Compiler Compiler support or related warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants