Skip to content

ENH: Add ctype aliases for numeric types of specific sizes to Python - #6762

Open
N-Dekker wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:ctype-aliases-for-numeric-types-of-specific-sizes
Open

ENH: Add ctype aliases for numeric types of specific sizes to Python#6762
N-Dekker wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
N-Dekker:ctype-aliases-for-numeric-types-of-specific-sizes

Conversation

@N-Dekker

@N-Dekker N-Dekker commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Added the following aliases:

float32_ctype
float64_ctype
uint8_ctype
uint16_ctype
uint32_ctype
uint64_ctype
int8_ctype
int16_ctype
int32_ctype
int64_ctype

Aims to provide a more human-readable alternative to F, D, UC, US, UI, ULL, SC, SS, SI, and SLL. Eases writing code for which the specific size of numeric types should be platform-independent.

Typical use cases, specifying the pixel type of an image:

  • itk.Image[itk.uint8_ctype, 2] (equivalent to itk.Image[itk.UC, 2])
  • itk.Image[itk.float64_ctype, 2] (equivalent to itk.Image[itk.D, 2])

@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Enhancement Improvement of existing methods or implementation 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 12, 2026
@N-Dekker
N-Dekker force-pushed the ctype-aliases-for-numeric-types-of-specific-sizes branch 2 times, most recently from 30289a6 to bbffc33 Compare August 12, 2026 22:27
@N-Dekker N-Dekker changed the title ENH: Aliases ctype aliases for numeric types of specific sizes to Python ENH: Add ctype aliases for numeric types of specific sizes to Python Aug 12, 2026
@N-Dekker
N-Dekker marked this pull request as ready for review August 13, 2026 08:19
@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This change adds top-level Python aliases for fixed-width integer and floating-point ITK C types, with regression coverage registered for their NumPy dtype mappings.

Confidence Score: 5/5

No blocking failure remains.

No accepted blocking findings remain.

T-Rex T-Rex Logs

What T-Rex did

  • The team attempted the documented Pixi build command and observed it could not progress because the Pixi package manager was not installed.
  • The team attempted the registered focused test with the build-tree using PYTHONPATH and observed a ModuleNotFoundError for itk, indicating that ITK Python is not built or installed in the environment.
  • The blockers were captured and a path forward was outlined: install Pixi, build the declared Python 3.13 ITK wrapper environment, then re-run the build commands and the ctest suite.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (2): Last reviewed commit: "ENH: Add ctype aliases for numeric types..." | Re-trigger Greptile

Comment thread Wrapping/Generators/Python/itk/support/types.py Outdated
@N-Dekker
N-Dekker marked this pull request as draft August 13, 2026 14:39
@N-Dekker
N-Dekker force-pushed the ctype-aliases-for-numeric-types-of-specific-sizes branch from bbffc33 to faaacd4 Compare August 13, 2026 15:53
@N-Dekker
N-Dekker marked this pull request as ready for review August 13, 2026 15:57
@thewtex

thewtex commented Aug 13, 2026

Copy link
Copy Markdown
Member

@N-Dekker

N-Dekker commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

How about using uint8, etc per:
https://github.com/InsightSoftwareConsortium/ITK/blob/main/Wrapping/Generators/Python/itk/support/extras.py#L266-L295
?

Thanks Matt, can you please elaborate a little bit? For example, how would you define a 2D itk Image of int64 pixels? With the proposed PR, it would be itk.Image[itk.int64_ctype, 2].


P.S. It looks like there is a bug at

np.dtype(np.int64): itk.SL,

    # This is a Mapping from numpy array types to itk pixel types. (Bug?)
    _np_itk = {
        ...
        np.dtype(np.int64): itk.SL,
        ...
     }

itk.SL is not int64, on Windows. Once this pull request is merged, it can be fixed by doing:

    # This is a Mapping from numpy array types to itk pixel types. (Fixed!)
    _np_itk = {
        ...
        np.dtype(np.int64): itk.int64_ctype,
        ...
     }

Is that what you meant to say?

@thewtex

thewtex commented Aug 14, 2026

Copy link
Copy Markdown
Member

itk.Image[itk.int64_ctype, 2].

I think it would be easier to write, easier to read, and more expected names if we had itk.Image[itk.int64, 2] or itk.Image[np.int64, 2].

np.dtype(np.int64): itk.SL,

Good catch!

@N-Dekker
N-Dekker force-pushed the ctype-aliases-for-numeric-types-of-specific-sizes branch from faaacd4 to 1d06a17 Compare August 15, 2026 09:01
@N-Dekker

Copy link
Copy Markdown
Contributor Author

Update: Inspired by Matt's comments, I just renamed the proposed aliases (with this force-pushed amend) to:

float32_t
float64_t
uint8_t
uint16_t
uint32_t
uint64_t
int8_t
int16_t
int32_t
int64_t

Under the hood, they are still simply aliases of itk.F, itk.D, itk.UC, etc.

The PR will now allow users to write (for example) itk.Image[itk.int64_t, 2], which looks very similar to the C++ equivalent, itk::Image<std::int64_t, 2>.

Hope that it's good enough now!

Added the following aliases:

    float32_t
    float64_t
    uint8_t
    uint16_t
    uint32_t
    uint64_t
    int8_t
    int16_t
    int32_t
    int64_t

Aims to provide a more human-readable alternative to F, D, UC, US, UI, UL, ULL,
SC, SS, SI, SL, SLL, etc. Eases writing code for which the specific size of
numeric types should be platform-independent.
@N-Dekker
N-Dekker force-pushed the ctype-aliases-for-numeric-types-of-specific-sizes branch from 1d06a17 to dc0ea28 Compare August 15, 2026 21:29
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:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots 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.

4 participants