Skip to content

Add specification for isdtype #503

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

Merged
merged 11 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions spec/API_specification/array_api/data_type_functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._types import Union, array, dtype, finfo_object, iinfo_object
from ._types import Union, Tuple, array, dtype, finfo_object, iinfo_object

def astype(x: array, dtype: dtype, /, *, copy: bool = True) -> array:
"""
Expand Down Expand Up @@ -117,6 +117,36 @@ def iinfo(type: Union[dtype, array], /) -> iinfo_object:
integer data type.
"""

def is_type(dtype: dtype, kind: Union[dtype, str, Tuple[Union[dtype, str], ...]]) -> bool:
"""
Returns a boolean indicating whether a provided dtype is of a specified data type "kind".

Parameters
----------
dtype: dtype
the input dtype.
kind: Union[str, dtype, Tuple[Union[str, dtype], ...]]
data type kind.

- If ``kind`` is a dtype, the function must return a boolean indicating whether the input ``dtype`` is equal to the dtype specified by ``kind``.
- If ``kind`` is a string, the function must return a boolean indicating whether the input ``dtype`` is of a specified data type kind. The following dtype kinds must be supported:

- **bool**: boolean data types (e.g., ``bool``).
- **signed integer**: signed integer data types (e.g., ``int8``, ``int16``, ``int32``, ``int64``).
- **unsigned integer**: unsigned integer data types (e.g., ``uint8``, ``uint16``, ``uint32``, ``uint64``).
- **integer**: integer data types. Shorthand for ``('signed integer', 'unsigned integer')``.
- **real**: real-valued floating-point data types (e.g., ``float32``, ``float64``).
- **complex**: complex floating-point data types (e.g., ``complex64``, ``complex128``).
- **numeric**: numeric data types. Shorthand for ``('integer', 'real', 'complex')``.

- If ``kind`` is a tuple, the tuple specifies a union of dtypes and/or kinds, and the function must return a boolean indicating whether the input ``dtype`` is either equal to a specified dtype or belongs to at least one specified data type kind.

Returns
-------
out: bool
boolean indicating whether a provided dtype is of a specified data type kind.
"""

def result_type(*arrays_and_dtypes: Union[array, dtype]) -> dtype:
"""
Returns the dtype that results from applying the type promotion rules (see :ref:`type-promotion`) to the arguments.
Expand All @@ -135,4 +165,4 @@ def result_type(*arrays_and_dtypes: Union[array, dtype]) -> dtype:
the dtype resulting from an operation involving the input arrays and dtypes.
"""

__all__ = ['astype', 'can_cast', 'finfo', 'iinfo', 'result_type']
__all__ = ['astype', 'can_cast', 'finfo', 'iinfo', 'is_type', 'result_type']
1 change: 1 addition & 0 deletions spec/API_specification/data_type_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Objects in API
can_cast
finfo
iinfo
is_type
result_type