Skip to content

STYLE: Replace ULL with IT as index type in itkPyVectorContainerTest.py - #6807

Open
N-Dekker wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:Replace-ULL-with-IT-in-itkPyVectorContainerTest
Open

STYLE: Replace ULL with IT as index type in itkPyVectorContainerTest.py#6807
N-Dekker wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:Replace-ULL-with-IT-in-itkPyVectorContainerTest

Conversation

@N-Dekker

Copy link
Copy Markdown
Contributor

Removed the check for sufficient wrapping from "Modules/Bridge/NumPy/wrapping/test/itkPyVectorContainerTest.py". itk.VectorContainer is always sufficiently wrapped for itk.IT.

Removed the check for sufficient wrapping from
"Modules/Bridge/NumPy/wrapping/test/itkPyVectorContainerTest.py".
`itk.VectorContainer` is always sufficiently wrapped for `itk.IT`.

Follow-up to pull request InsightSoftwareConsortium#6800
commit 0939d4c
"STYLE: Replace UL with IT as index type in itkPyVectorContainerTest.py",
(which was about the other "itkPyVectorContainerTest.py" file, in
"Filtering/MeshToPolyData/wrapping/test").
@github-actions github-actions Bot added area:Python wrapping Python bindings for a class type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Bridge Issues affecting the Bridge module type:Style Style changes: no logic impact (indentation, comments, naming) labels Aug 26, 2026

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on a glance.

@N-Dekker
N-Dekker marked this pull request as ready for review August 26, 2026 21:17
@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This change updates the NumPy VectorContainer test to use ITK's IT index type. The test remains registered for every Python-wrapping build even though it requires float wrapping and both 2-D and 3-D Point container specializations. Reduced supported wrapping configurations therefore fail template lookup instead of skipping an unavailable test.

Confidence Score: 4/5

The change is not ready to merge because reduced Python-wrapping configurations register a test that requires templates they do not generate.

One actionable non-security failure remains. N-Dekker stated that an amend had been force-pushed, but the current test still unconditionally constructs VectorContainer[itk.IT, itk.F] and float Point containers for dimensions 2 and 3 without checking their availability.

Files Needing Attention: Modules/Bridge/NumPy/wrapping/test/itkPyVectorContainerTest.py; Modules/Bridge/NumPy/wrapping/test/CMakeLists.txt

T-Rex T-Rex Logs

What T-Rex did

  • Generated a proof for the posted P1 finding and linked it to the review comment.
  • Filed a second finding-proof to corroborate another P1 finding with additional context.
  • Validated contract behavior by reproducing two root scenarios and noted the exact runtime blockers encountered.
  • Collected and reviewed supporting outputs from proofs 0 and 2 to verify the overall proof-of-work narrative.

View all artifacts

T-Rex Ran code and verified through T-Rex

Comments Outside Diff (1)

  1. General comment

    P1 PyVectorContainer test is registered for configurations that do not wrap its required templates

    • Bug
      • itkPyVectorContainerTest.py unconditionally instantiates float scalar VectorContainer and float Point VectorContainers for both dimensions 2 and 3. itkPyVectorContainer.wrap only emits float templates when float wrapping is enabled and only emits Point container templates for ITK_WRAP_IMAGE_DIMS. The CMake registration is guarded solely by ITK_WRAP_PYTHON, so reduced supported configurations still register a test that reaches an unavailable template.
    • Cause
      • The test's fixed float/2-D/3-D assumptions are not represented in its CMake registration condition.
    • Fix
      • Do not register this test unless float wrapping is enabled and ITK_WRAP_IMAGE_DIMS contains both 2 and 3, or make the Python test select and exercise only templates available in the configured wrapping set.

    T-Rex Ran code and verified through T-Rex

Reviews (3): Last reviewed commit: "STYLE: Replace ULL with IT as index type..." | Re-trigger Greptile

Comment thread Modules/Bridge/NumPy/wrapping/test/itkPyVectorContainerTest.py
@N-Dekker
N-Dekker marked this pull request as draft August 27, 2026 09:33
@N-Dekker
N-Dekker force-pushed the Replace-ULL-with-IT-in-itkPyVectorContainerTest branch from 8d73416 to 8570293 Compare August 27, 2026 11:01
@N-Dekker
N-Dekker marked this pull request as ready for review August 27, 2026 11:03
and hasattr(itk.Point, "F2")
and hasattr(itk.VectorContainer, "ULLPF2")
):
if not (hasattr(itk.Point, "F2") and hasattr(itk.Point, "F3")):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Point-only guard misses container specializations

Point.F2 and Point.F3 are generated from incremented image dimensions, but the VectorContainer[IT, Point] and PyVectorContainer[IT, Point] specializations used below are generated only for direct ITK_WRAP_IMAGE_DIMS. With ITK_WRAP_IMAGE_DIMS=1;2, the Point checks pass while the required 3D ITPF3 specialization is absent, so template lookup fails instead of the test skipping. Restore checks for the exact VectorContainer and PyVectorContainer specializations exercised by this test, or register the test only when those direct specializations exist.

Context Used: AGENTS.md (source)

Artifacts

Focused reproduction source

  • This review-authored executable reads the current sources and models the valid `1;2` wrapping configuration, showing the guard and template sets used in the comparison.

Before (current guard)

  • Ran the focused reproduction against current code; F2/F3 pass the guard but missing ITPF3 raises the expected template lookup failure, confirming the defect.

After (full specialization guard)

  • Ran the same reproduction with the guard requiring ITPF2 and ITPF3; it skips cleanly instead of attempting the missing lookup, demonstrating the correction.

Runtime availability

  • Attempted to import the generated ITK Python bindings from the checkout environment; no `itk` module is installed, so an actual generated-binding run was unavailable.

View artifacts

T-Rex Ran code and verified through T-Rex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to directly check ITK_WRAP_IMAGE_DIMS within the Python unit test?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Use the generated wrapping configuration rather than checking os.environ at runtime. itk.support.build_options.DIMS exposes ITK_WRAP_IMAGE_DIMS as a list of integers.

Add:

from itk.support.build_options import DIMS

Then replace the guard with:

Suggested change
if not (hasattr(itk.Point, "F2") and hasattr(itk.Point, "F3")):
if not {2, 3}.issubset(DIMS):

This skips configurations such as ITK_WRAP_IMAGE_DIMS=1;2, where the 3D specialization used later in the test is unavailable. DIMS is populated from itkConfig.ITK_GLOBAL_WRAPPING_BUILD_OPTIONS, so it reflects the build-time CMake setting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Can you please extend your suggestion to also check ITK_WRAP_float?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Import REALS alongside DIMS; it is populated from WRAP_ITK_REAL, so checking itk.F not in REALS reflects whether ITK_WRAP_float is enabled:

from itk.support.build_options import DIMS, REALS
Suggested change
if not (hasattr(itk.Point, "F2") and hasattr(itk.Point, "F3")):
if not {2, 3}.issubset(DIMS) or itk.F not in REALS:

This skips the test when dimensions 2 and 3 are not both wrapped or when ITK_WRAP_float is disabled.

@N-Dekker
N-Dekker marked this pull request as draft August 27, 2026 11:27
@N-Dekker

N-Dekker commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@dzenanz Do you have a preference?

  1. Simply remove all checks for sufficient wrappings (as I originally proposed)
  2. Remove the VectorContainer checks, and just check hasattr(itk.Point, "F2") and hasattr(itk.Point, "F3"), as in my force-pushed amend.
  3. A complete refactoring of the checks, using if not {2, 3}.issubset(DIMS) or itk.F not in REALS as suggested by Greptile.
  4. Restore the original itk.Point checks, and adjust the old PyVectorContainer and VectorContainer checks for itk.IT. (But then, how? I guess hasattr(itk.VectorContainer, "ITF") won't work, right?)

Honestly I feel that option 3 and 4 are beyond the scope of this PR... 🤷

@dzenanz

dzenanz commented Aug 27, 2026

Copy link
Copy Markdown
Member

My preference is:

Simply remove all checks for sufficient wrappings (as I originally proposed)

@dzenanz

dzenanz commented Aug 27, 2026

Copy link
Copy Markdown
Member

If we are going to selectively enable tests, I think it is better to do it via CMake, as in #6804. That way when tests are run, we get a correct count of enabled tests.

@dzenanz

dzenanz commented Aug 27, 2026

Copy link
Copy Markdown
Member

Also, doing this consistently is a lot of effort, and might be well suited for AI. @hjmjohnson what do you think?

@N-Dekker

Copy link
Copy Markdown
Contributor Author

Thanks @dzenanz By the way, is the Python wrapping of ITK ever made without 2D or 3D? Would we really need to check if {2, 3}.issubset(DIMS) ???

@hjmjohnson

Copy link
Copy Markdown
Member

Also, doing this consistently is a lot of effort and might be well suited for AI. @hjmjohnson, what do you think?

This is the type of work I am proposing as needing funding support to do correctly and to test downstream implications. For the moment, an Issue with recommended strategies would be more compelling for the grant than a long-open WIP PR commit that is not intended for merging for many months.

@dzenanz

dzenanz commented Aug 27, 2026

Copy link
Copy Markdown
Member

There is the option to do that, but I assume it would break so many things that only a fuzzer would do that.

@N-Dekker
N-Dekker force-pushed the Replace-ULL-with-IT-in-itkPyVectorContainerTest branch from 8570293 to 8d73416 Compare August 27, 2026 14:08
@N-Dekker
N-Dekker marked this pull request as ready for review August 27, 2026 14:09
@N-Dekker

Copy link
Copy Markdown
Contributor Author

@dzenanz

My preference is:

Simply remove all checks for sufficient wrappings (as I originally proposed)

OK, it's back to the original now (force-pushed): entirely removing the check for sufficient wrapping, just like in the other itkPyVectorContainerTest (in Filtering/MeshToPolyData).

The AI may not like it this way, but it's fine to me, as long as we humans still like it 😸

return

v1 = itk.VectorContainer[itk.ULL, itk.F].New()
v1 = itk.VectorContainer[itk.IT, itk.F].New()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Reduced wrapping configurations fail template lookup

This test is registered whenever Python wrapping is enabled, but it unconditionally instantiates VectorContainer[itk.IT, itk.F] and float Point containers in dimensions 2 and 3. Those specializations are emitted only when float wrapping is enabled and dimensions 2 and 3 are included in ITK_WRAP_IMAGE_DIMS. Supported reduced wrapping builds therefore register this test and fail template lookup rather than skipping it. Gate registration on float plus both dimensions, or add an availability guard before constructing these templates.

Artifacts

Executable source-derived reduced-wrapping harness

  • The executed Python harness reads the test, wrapper, and CMake registration sources and evaluates default plus reduced float/dimension template availability; it demonstrates the configuration mismatch.

Default supported configuration output

  • The default configuration execution reports all required float scalar and 2-D/3-D Point VectorContainer templates as wrapped and the test as registered; it establishes the supported baseline.

Reduced configuration failure-path output

  • The reduced configuration execution reports each required template omitted by float-disabled or dimension-reduced wrapping while CTest registration remains enabled; it reproduces both roots.

Configured ITK runtime and CMake availability check

  • The runtime availability command shows that CMake is absent and Python cannot import itk, preventing a real configured build or CTest invocation; the runtime reproduction is blocked by the environment.

View artifacts

T-Rex Ran code and verified through T-Rex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Bridge Issues affecting the Bridge module area:Python wrapping Python bindings for a class type:Style Style changes: no logic impact (indentation, comments, naming) type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants