Skip to content

Fix GetCTypeForDType(itk_ctype.dtype) round-trip - #6783

Merged
hjmjohnson merged 4 commits into
InsightSoftwareConsortium:mainfrom
N-Dekker:GetCTypeForDType-round-trip
Aug 24, 2026
Merged

hjmjohnson merged 4 commits into
InsightSoftwareConsortium:mainfrom
N-Dekker:GetCTypeForDType-round-trip

Conversation

@N-Dekker

@N-Dekker N-Dekker commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Reordered the creation of itkCType objects in initialize_c_types_once, in order to fix the following two issues:

Documented that the order in which these itkCType objects are created is relevant for the mapping from NumPy dtype to itkCType.

Added a Python unit test to check the round-trip itkCType ==> dtype ==> itkCType, for numeric C types with specified sizes ("fixed width types"): int8_t, uint8_t, int16_t, uint16_t, etc.

@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 labels Aug 22, 2026

@hjmjohnson hjmjohnson 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.

This looks good. Will approve once tests pass and ghostflow is message is fixed. Curious why this is a WIP?

@dzenanz

dzenanz commented Aug 22, 2026

Copy link
Copy Markdown
Member

WIP probably because it just adds a test, not a fix.

The order in which these itkCType objects are created appears relevant for the
mapping from NumPy `dtype` to itkCType!
Aims to fix issue InsightSoftwareConsortium#6782
"itkCType.GetCTypeForDType(np.uint32) should return the CType for `unsigned int`"
Fixes issue InsightSoftwareConsortium#6785
"On Linux, GetCTypeForDType(np.uint64) should return UL, and
GetCTypeForDType(np.int64) should return SL"
Tests that GetCTypeForDType(itk_ctype.dtype) is equal to itk_ctype, for the
itkCType aliases with a specified size.
@N-Dekker
N-Dekker force-pushed the GetCTypeForDType-round-trip branch from 802f1ac to b22d58e Compare August 23, 2026 21:07
@N-Dekker N-Dekker changed the title WIP: GetCTypeForDType(itk_ctype.dtype) round-trip Fix GetCTypeForDType(itk_ctype.dtype) round-trip Aug 23, 2026
@N-Dekker
N-Dekker marked this pull request as ready for review August 24, 2026 09:03
@greptile-apps

greptile-apps Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Summary

This change adds a round-trip test for the fixed-width ITK C type aliases exposed to Python.

The executed check loaded the dtype mapping and verified that all ten covered aliases resolve back to the identical itkCType object on both the parent revision and this change. No defects were found.

T-Rex validation blocked

The full wrapped-package test could not run because the required pixi package manager tool is not installed. A prebuilt ITK Python package and build directory were also unavailable.

Confidence Score: 5/5

No functional or security defect was found in the added fixed-width dtype round-trip coverage.

The executed source-level mapping check covered all ten aliases added by the test and observed identical round-trip behavior on both the parent revision and this change. There are no final review findings.

Files Needing Attention: No files require changes. The intended wrapped-package test remains useful to run in an environment with Pixi and a configured ITK Python build.

T-Rex T-Rex Logs

What T-Rex did

  • Ran a Python check that loads Wrapping/Generators/Python/itk/support/types.py and asserts object-identity dtype round trips for ten fixed-width aliases, and the check passed on both the parent revision and the PR head.
  • Collected a reproducible script and before/after logs showing the round-trip results for the ten aliases, and captured both the PR head and parent revision outputs for review.
  • Attempted the Pixi configure/build/CTypeTest flow to validate the built package, but the process could not start because Pixi is unavailable.
  • Documented the built-package validation blocker, noting that the Pixi-based validation could not proceed due to Pixi unavailability.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "ENH: Test `itkCType.GetCTypeForDType(itk..." | Re-trigger Greptile

@N-Dekker

Copy link
Copy Markdown
Contributor Author

This looks good. Will approve once tests pass and ghostflow is message is fixed. Curious why this is a WIP?

Thanks @hjmjohnson! Two days ago, this was still WIP, because I expected the added test to fail. And indeed, it said on Linux-Build16899-PR6783-GetCTypeForDType-round-trip-Python test CTypeTest:

FAIL: test_itk_ctype_numpy_dtype_roundtrip (__main__.CTypeTestCase.test_itk_ctype_numpy_dtype_roundtrip)
Tests round-trip from itkCType to NumPy dtype and back, for the itkCType aliases with a specified size
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vsts/work/1/s/Wrapping/Generators/Python/Tests/test_ctype.py", line 88, in test_itk_ctype_numpy_dtype_roundtrip
    self.assertEqual(itk.itkCType.GetCTypeForDType(itk_ctype.dtype), itk_ctype)
AssertionError: <itkCType unsigned long long> != <itkCType unsigned long>

This was fixed by the commit BUG: Let initialize_c_types_once create ULL and SLL before UL and SL, that I added to this PR.

So it was originally WIP, because I was doing Test Driven Development (TDD) 😇

@N-Dekker
N-Dekker requested a review from hjmjohnson August 24, 2026 09:33
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:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

3 participants