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

uint8_ctype = UC
uint16_ctype = US
uint32_ctype = UI
uint64_ctype = ULL

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.

In common on unix and Mac to just use long for 64-bits. Does ITK Python instantiate long long type for all platforms? These int64 alias may need to be conditional.

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.

Good point @blowekamp Converted PR back to Draft, to allow us some more time...

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.

I just noticed that the following assert fails on GCC:

#include <type_traits> 
#include <cinttypes>
static_assert(std::is_same_v<long long, std::int64_t>);

Output at https://godbolt.org/z/hzE46MnxY :

<source>:7:20: error: static assertion failed
    7 | static_assert(std::is_same_v<long long, std::int64_t>);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • 'long long int' is not the same as 'long int'

The assert passes successfully (no assert failure) on MSVC. So it does support the idea of making the int64 alias conditional.

Honestly I like the simplicity of unconditional uint64_ctype = ULL and int64_ctype = SLL. But I see that there is a choice to make. 🤷

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.

@blowekamp Please check if you like this force-pushed amend.

@N-Dekker
N-Dekker marked this pull request as draft August 13, 2026 14:39
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, UL, ULL,
SC, SS, SI, SL, and SLL. 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 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!

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