ENH: Add ctype aliases for numeric types of specific sizes to Python - #6762
Conversation
30289a6 to
bbffc33
Compare
|
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! |
faaacd4 to
1d06a17
Compare
|
Update: Inspired by Matt's comments, I just renamed the proposed aliases (with this force-pushed amend) to: Under the hood, they are still simply aliases of The PR will now allow users to write (for example) 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.
1d06a17 to
dc0ea28
Compare
|
Does |
|
Thanks for your approval, @blowekamp
No, import itk
import numpy as np
image_type = itk.Image[np.int64, 2]It said: |
|
As a follow-up, it might be nice to add support for using a NumPy type to specify the pixel type of an |
|
Thanks for your approval, @thewtex, @dzenanz, @blowekamp When it's merged, I'm considering a style PR to replace code of the form:
With simply just: use |
Replaced `if os.name == "nt"` statements which used `itk.SL`, `itk.SLL`, `itk.UL`, or `itk.ULL` with the equivalent code, using just `itk.int64_t` or `itk.uint64_t`. Aims to improve code readability and remove OS-specific code. Follow-up to pull request InsightSoftwareConsortium#6762 commit dc0ea28 "ENH: Add CType aliases for numeric types of specific sizes to Python"
Made the mapping from NumPy to ITK types clearer, by using the itkCType aliases with the specified number of bits (`itk.uint8_t`, `itk.uint16_t`, etc.), which were introduced by pull request InsightSoftwareConsortium#6762 commit dc0ea28
Made the mapping from NumPy to ITK types clearer, by using the itkCType aliases with the specified number of bits (`itk.uint8_t`, `itk.uint16_t`, etc.), which were introduced by pull request InsightSoftwareConsortium#6762 commit dc0ea28
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_t, 2](equivalent toitk.Image[itk.UC, 2])itk.Image[itk.float64_t, 2](equivalent toitk.Image[itk.D, 2])itk.Image[itk.int64_t, 2](equivalent toitk.Image[itk.SL, 2]on Linux anditk.Image[itk.SLL, 2]on Windows)For the record, this comment is updated, following the replacement of the
_ctypepostfixes with_t(see #6762 (comment) and this force-pushed amend)