Skip to content

Dtypes #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ev-br opened this issue Jan 2, 2023 · 2 comments · Fixed by #12
Closed

Dtypes #9

ev-br opened this issue Jan 2, 2023 · 2 comments · Fixed by #12

Comments

@ev-br
Copy link
Collaborator

ev-br commented Jan 2, 2023

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):

[1] https://numpy.org/doc/stable/reference/arrays.dtypes.html
[2] https://numpy.org/doc/stable/reference/arrays.scalars.html

This was referenced Jan 3, 2023
@rgommers
Copy link
Member

rgommers commented Jan 3, 2023

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.

@ev-br
Copy link
Collaborator Author

ev-br commented Jan 3, 2023

Meant "avoid having to distinguish between scalars and zero-dimensional arrays". See gh-13 for one attempt.

@ev-br ev-br closed this as completed in #12 Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants