ENH: Add ctype aliases for numeric types of specific sizes to Python - #6762
Conversation
30289a6 to
bbffc33
Compare
|
| uint8_ctype = UC | ||
| uint16_ctype = US | ||
| uint32_ctype = UI | ||
| uint64_ctype = ULL |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good point @blowekamp Converted PR back to Draft, to allow us some more time...
There was a problem hiding this comment.
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. 🤷
There was a problem hiding this comment.
@blowekamp Please check if you like this force-pushed amend.
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.
bbffc33 to
faaacd4
Compare
|
How about using ? |
Thanks Matt, can you please elaborate a little bit? For example, how would you define a 2D itk P.S. It looks like there is a bug at # This is a Mapping from numpy array types to itk pixel types. (Bug?)
_np_itk = {
...
np.dtype(np.int64): itk.SL,
...
}
# 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? |
I think it would be easier to write, easier to read, and more expected names if we had
Good catch! |
Added the following aliases:
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 toitk.Image[itk.UC, 2])itk.Image[itk.float64_ctype, 2](equivalent toitk.Image[itk.D, 2])