You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current dtype stubs are too simplistic. Let's see if we can make them work without reproducing the whole story about dtypes [1] vs array scalars [2].
The minimum set of requirements is
np.float32(42) should work. In numpy it creates a scalar, can we get around creating a single-element zero-dimensional array (backed by a zero-dimensional tensor).
(a part of) dtype class hierarchy is needed. This includes common patterns like if np.issubdtype(x.dtype, np.complexfloating). Sadly, there are also isinstance checks in the numpy test suite:
(numpy-dev) br@gonzales:~/repos/numpy$ grep -rn np.inexact .
./doc/source/release/1.19.0-notes.rst:259:or ``np.inexact`` will now give a deprecation warning when converted
./doc/neps/nep-0040-legacy-datatype-impl.rst:254:types such as ``np.inexact`` (see figure below).
./doc/neps/nep-0040-legacy-datatype-impl.rst:256:``issubclass(a.dtype.type, np.inexact)``.
./doc/neps/nep-0042-new-dtypes.rst:330: ``isinstance(np.dtype("float64"), np.inexact)``.
./numpy/random/bit_generator.pyx:139: elif isinstance(x, (float, np.inexact)):
./numpy/linalg/tests/test_linalg.py:1229: if issubclass(x.dtype.type, np.inexact):
./numpy/lib/function_base.py:1208: elif np.issubdtype(otype, np.inexact):
./numpy/lib/function_base.py:3876: if np.issubdtype(a.dtype, np.inexact):
./numpy/lib/function_base.py:3908: if np.issubdtype(a.dtype, np.inexact) and sz > 0:
./numpy/lib/function_base.py:4681: if np.issubdtype(arr.dtype, np.inexact):
./numpy/lib/function_base.py:4733: if np.issubdtype(arr.dtype, np.inexact):
./numpy/lib/function_base.py:4753: if np.issubdtype(arr.dtype, np.inexact):
./numpy/lib/nanfunctions.py:101: elif issubclass(a.dtype.type, np.inexact):
./numpy/lib/nanfunctions.py:1039: if dtype is not None and not issubclass(dtype.type, np.inexact):
./numpy/lib/nanfunctions.py:1041: if out is not None and not issubclass(out.dtype.type, np.inexact):
./numpy/lib/nanfunctions.py:1720: if dtype is not None and not issubclass(dtype.type, np.inexact):
./numpy/lib/nanfunctions.py:1722: if out is not None and not issubclass(out.dtype.type, np.inexact):
./numpy/typing/tests/data/fail/scalars.pyi:56:np.inexact(1) # E: Cannot instantiate abstract class
./numpy/ma/extras.py:742: if np.issubdtype(a.dtype, np.inexact):
./numpy/ma/extras.py:772: if np.issubdtype(asorted.dtype, np.inexact) and asorted.size > 0:
./numpy/ma/extras.py:812: if np.issubdtype(asorted.dtype, np.inexact):
./numpy/core/tests/test_abc.py:12: assert_(issubclass(np.inexact, numbers.Complex))
./numpy/core/tests/test_deprecations.py:426: np.inexact, np.floating, np.complexfloating,
./numpy/core/tests/test_scalar_methods.py:140: np.inexact,
./numpy/core/tests/test_numerictypes.py:381: assert_(np.issubdtype(np.floating, np.inexact))
./numpy/core/tests/test_numerictypes.py:382: assert_(not np.issubdtype(np.inexact, np.floating))
./numpy/core/tests/test_array_coercion.py:261: if isinstance(scalar, np.inexact):
np.float32(42) should work. In numpy it creates a scalar, can we get around creating a single-element zero-dimensional array (backed by a zero-dimensional tensor).
If by "get around" you mean "avoid", then my question is why? At least for the "backed by a 0-D tensor" part I don't see another option.
The current dtype stubs are too simplistic. Let's see if we can make them work without reproducing the whole story about dtypes [1] vs array scalars [2].
The minimum set of requirements is
np.float32(42)
should work. In numpy it creates a scalar, can we get around creating a single-element zero-dimensional array (backed by a zero-dimensional tensor).if np.issubdtype(x.dtype, np.complexfloating)
. Sadly, there are alsoisinstance
checks in the numpy test suite:[1] https://numpy.org/doc/stable/reference/arrays.dtypes.html
[2] https://numpy.org/doc/stable/reference/arrays.scalars.html
The text was updated successfully, but these errors were encountered: