Skip to content

Commit

Permalink
Use sized aliases for supported integer types
Browse files Browse the repository at this point in the history
in _convert. These should be more explicit and should be more reliable
in ensuring that for example int32 is available on all platforms.
  • Loading branch information
lagru committed Feb 19, 2024
1 parent 5cf77cb commit d1712b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
1 change: 1 addition & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ Post numpy 2
minimal required version): consider re-adding matplotlib to the test
dependencies. Also remove temporary assert for NumPy 2.0 in
`nightly_wheel_build.yml`.
- Remove references to `numpy.bool8` once NumPy 2.0 is minimal required version.
32 changes: 11 additions & 21 deletions skimage/util/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,18 @@
'dtype_limits',
]

# For integers Numpy uses `_integer_types` basis internally, and builds a leaky
# `np.XintYY` abstraction on top of it. This leads to situations when, for
# example, there are two np.Xint64 dtypes with the same attributes but
# different object references. In order to avoid any potential issues,
# we use the basis dtypes here. For more information, see:
# - https://github.com/scikit-image/scikit-image/issues/3043
# For convenience, for these dtypes we indicate also the possible bit depths
# (some of them are platform specific). For the details, see:
# http://www.unix.org/whitepapers/64bit.html
_integer_types = (
np.byte,
np.ubyte, # 8 bits
np.short,
np.ushort, # 16 bits
np.intc,
np.uintc, # 16 or 32 or 64 bits
int,
np.int_,
np.uint, # 32 or 64 bits
np.longlong,
np.ulonglong,
) # 64 bits
np.int8,
np.int16,
np.int32,
np.int64,
np.intp,
np.uint8,
np.uint16,
np.uint32,
np.uint64,
np.uintp,
)
_integer_ranges = {t: (np.iinfo(t).min, np.iinfo(t).max) for t in _integer_types}
dtype_range = {
bool: (False, True),
Expand Down

0 comments on commit d1712b5

Please sign in to comment.