Repository navigation
Description
Describe the issue:
I'm currently working on adapting skimage for NumPy 2.0 during which I was told to replace our usages of the former np.core.numerictypes.obj2sctype(x) with the equivalent np.dtype(x).type. However, it seems that if x is an generic dtype (I think that's what they are called) the result differs. The example below shows the difference on the current nightly wheel of NumPy.
Reproduce the code example:
import numpy as np
from numpy._core.numerictypes import obj2sctype
assert obj2sctype(np.floating), np.dtype(np.floating).typeError message:
(numpy.floating, numpy.float64)Python and NumPy Versions:
2.0.0.dev0+git20240109.6e3b923
3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0]
Runtime Environment:
Details
[{'numpy_version': '2.0.0.dev0+git20240109.6e3b923',
'python': '3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) '
'[GCC 12.3.0]',
'uname': uname_result(system='Linux', node='hue', release='6.6.10-arch1-1', version='#1 SMP PREEMPT_DYNAMIC Fri, 05 Jan 2024 16:20:41 +0000', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'Haswell',
'filepath': '/home/lg/.local/lib/micromamba/envs/skimagedev312/lib/python3.12/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so',
'internal_api': 'openblas',
'num_threads': 8,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.23.dev'}]
None
Context for the issue:
I guess this is kind of an obscure edge case we are hitting in skimage, and I think I can figure out a way around it. But I still wanted to raise the issue in case this was something that was missed. Feel free to close this, if this isn't something to worry about. Though, I'd be curious if there is an alternative in NumPy 2.0 with which the original output can be revoverd.
Slightly related #17325.
Activity
Use np.dtype(...).char
seberg commentedon Jan 13, 2024
Could you link to the context/code? It doesn't work for the abstract scalar types indeed, but then the abstract scalar types rarely do what you want them to do, except for that odd
issubdtypeI guess...lagru commentedon Jan 13, 2024
Sure, have a look at skimage/util/dtype.py#L277. If I replace it with just
dtype(...).typea test checking fornp.float32passthrough would fail becausedtype(np.floating).typeis turned intonp.float64.Though, it seems that we can get by with just passing
dtypetonp.issubdtype(...)directly (see this diff). The tests still pass and as far as I can see,np.issubdtypeappliesdtype(arg2).typeautomatically if an argument isn't a subclass of generic...numpy/numpy/_core/numerictypes.py
Lines 514 to 515 in e429f52