STYLE: Replace ULL with IT as index type in itkPyVectorContainerTest.py - #6807
Conversation
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").
|
8d73416 to
8570293
Compare
| and hasattr(itk.Point, "F2") | ||
| and hasattr(itk.VectorContainer, "ULLPF2") | ||
| ): | ||
| if not (hasattr(itk.Point, "F2") and hasattr(itk.Point, "F3")): |
There was a problem hiding this comment.
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
- 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.
- 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.
- 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.
There was a problem hiding this comment.
Is there a way to directly check ITK_WRAP_IMAGE_DIMS within the Python unit test?
There was a problem hiding this comment.
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 DIMSThen replace the guard with:
| 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.
There was a problem hiding this comment.
Thanks! Can you please extend your suggestion to also check ITK_WRAP_float?
There was a problem hiding this comment.
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| 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.
|
@dzenanz Do you have a preference?
Honestly I feel that option 3 and 4 are beyond the scope of this PR... 🤷 |
|
My preference is:
|
|
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. |
|
Also, doing this consistently is a lot of effort, and might be well suited for AI. @hjmjohnson what do you think? |
|
Thanks @dzenanz By the way, is the Python wrapping of ITK ever made without 2D or 3D? Would we really need to check if |
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. |
|
There is the option to do that, but I assume it would break so many things that only a fuzzer would do that. |
8570293 to
8d73416
Compare
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() |
There was a problem hiding this comment.
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.
Removed the check for sufficient wrapping from "Modules/Bridge/NumPy/wrapping/test/itkPyVectorContainerTest.py".
itk.VectorContaineris always sufficiently wrapped foritk.IT.