Skip to content

Commit 1d7b4d1

Browse files
committed
chore: wip
1 parent eab417a commit 1d7b4d1

File tree

4 files changed

+70
-489
lines changed

4 files changed

+70
-489
lines changed

src/array_api/_2023_12.py

Lines changed: 23 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -6684,169 +6684,51 @@ def __call__(self, x: TArray, /, *, axis: Optional[Union[int, tuple[int, ...]]]
66846684

66856685

66866686
@runtime_checkable
6687-
class capabilities[TCapabilities](Protocol):
6688-
"""
6689-
Returns a dictionary of array library capabilities.
6690-
6691-
The dictionary must contain the following keys:
6692-
6693-
- `"boolean indexing"`: boolean indicating whether an array library supports boolean indexing. If a conforming implementation fully supports boolean indexing in compliance with this specification (see :ref:`indexing`), the corresponding dictionary value must be ``True``; otherwise, the value must be ``False``.
6694-
- `"data-dependent shapes"`: boolean indicating whether an array library supports data-dependent output shapes. If a conforming implementation fully supports all APIs included in this specification (excluding boolean indexing) which have data-dependent output shapes, as explicitly demarcated throughout the specification, the corresponding dictionary value must be ``True``; otherwise, the value must be ``False``.
6695-
6696-
Returns
6697-
-------
6698-
out: Capabilities
6699-
a dictionary of array library capabilities.
6700-
6701-
Notes
6702-
-----
6703-
6704-
.. versionadded: 2023.12
6705-
6706-
"""
6707-
6708-
@abstractmethod
6709-
def __call__(self, /) -> TCapabilities: ...
6710-
6711-
6712-
@runtime_checkable
6713-
class default_device[TDevice](Protocol):
6714-
"""
6715-
Returns the default device.
6716-
6717-
Returns
6718-
-------
6719-
out: device
6720-
an object corresponding to the default device.
6721-
6722-
Notes
6723-
-----
6724-
6725-
.. versionadded: 2023.12
6726-
6727-
"""
6728-
6729-
@abstractmethod
6730-
def __call__(self, /) -> TDevice: ...
6731-
6732-
6733-
@runtime_checkable
6734-
class default_dtypes[TDatatypes, TDefaultdatatypes, TDevice](Protocol):
6735-
"""
6736-
Returns a dictionary containing default data types.
6737-
6738-
The dictionary must have the following keys:
6739-
6740-
- `"real floating"`: default real floating-point data type.
6741-
- `"complex floating"`: default complex floating-point data type.
6742-
- `"integral"`: default integral data type.
6743-
- `"indexing"`: default array index data type.
6744-
6745-
Dictionary values must be the corresponding data type object.
6746-
6747-
Parameters
6748-
----------
6749-
device: Optional[device]
6750-
device for which to return default data types. If ``device`` is ``None``, the returned data types must be the default data types for the current device; otherwise, the returned data types must be default data types specific to the specified device. Default: ``None``.
6751-
6752-
.. note::
6753-
Some array libraries have the concept of a device context manager, allowing library consumers to manage the current device context. When ``device`` is ``None``, libraries supporting a device context should return the default data types for the current device. For libraries without a context manager or supporting only a single device, those libraries should return the default data types for the default device.
6687+
class Info[TCapabilities, TDatatypes, TDefaultdatatypes, TArray: _array, TDevice, TDtype](Protocol):
6688+
"""Namespace returned by `__array_namespace_info__`."""
67546689

6755-
Returns
6756-
-------
6757-
out: DefaultDataTypes
6758-
a dictionary containing the default data type for respective data type kinds.
6690+
def capabilities(self) -> TCapabilities: ...
67596691

6760-
Notes
6761-
-----
6692+
def default_device(self) -> TDevice: ...
67626693

6763-
.. versionadded: 2023.12
6694+
def default_dtypes(self, *, device: Optional[TDevice]) -> TDefaultdatatypes: ...
67646695

6765-
"""
6696+
def devices(self) -> list[TDevice]: ...
67666697

6767-
@abstractmethod
6768-
def __call__(self, /, *, device: Optional[TDevice] = None) -> TDefaultdatatypes: ...
6698+
def dtypes(self, *, device: Optional[TDevice], kind: Optional[Union[str, tuple[str, ...]]]) -> TDatatypes: ...
67696699

67706700

67716701
@runtime_checkable
6772-
class dtypes[TDatatypes, TDevice](Protocol):
6702+
class __array_namespace_info__(Protocol):
67736703
"""
6774-
Returns a dictionary of supported *Array API* data types.
6704+
Returns a namespace with Array API namespace inspection utilities.
67756705
6776-
.. note::
6777-
While specification-conforming array libraries may support additional data types which are not present in this specification, data types which are not present in this specification should not be included in the returned dictionary.
6778-
6779-
.. note::
6780-
Specification-conforming array libraries must only return supported data types having expected properties as described in :ref:`data-types`. For example, if a library decides to alias ``float32`` as ``float64``, that library must not include ``float64`` in the dictionary of supported data types.
6781-
6782-
Parameters
6783-
----------
6784-
kind: Optional[Union[str, Tuple[str, ...]]]
6785-
data type kind.
6786-
6787-
- If ``kind`` is ``None``, the function must return a dictionary containing all supported Array API data types.
6788-
6789-
- If ``kind`` is a string, the function must return a dictionary containing the data types belonging to the specified data type kind. The following data type kinds must be supported:
6790-
6791-
- ``'bool'``: boolean data types (e.g., ``bool``).
6792-
- ``'signed integer'``: signed integer data types (e.g., ``int8``, ``int16``, ``int32``, ``int64``).
6793-
- ``'unsigned integer'``: unsigned integer data types (e.g., ``uint8``, ``uint16``, ``uint32``, ``uint64``).
6794-
- ``'integral'``: integer data types. Shorthand for ``('signed integer', 'unsigned integer')``.
6795-
- ``'real floating'``: real-valued floating-point data types (e.g., ``float32``, ``float64``).
6796-
- ``'complex floating'``: complex floating-point data types (e.g., ``complex64``, ``complex128``).
6797-
- ``'numeric'``: numeric data types. Shorthand for ``('integral', 'real floating', 'complex floating')``.
6798-
6799-
- If ``kind`` is a tuple, the tuple specifies a union of data type kinds, and the function must return a dictionary containing the data types belonging to at least one of the specified data type kinds.
6800-
6801-
Default: ``None``.
6802-
device: Optional[device]
6803-
device for which to return supported data types. If ``device`` is ``None``, the returned data types must be the supported data types for the current device; otherwise, the returned data types must be supported data types specific to the specified device. Default: ``None``.
6804-
6805-
.. note::
6806-
Some array libraries have the concept of a device context manager, allowing library consumers to manage the current device context. When ``device`` is ``None``, libraries supporting a device context should return the supported data types for the current device. For libraries without a context manager or supporting only a single device, those libraries should return the supported data types for the default device.
6706+
See :ref:`inspection` for a list of inspection APIs.
68076707
68086708
Returns
68096709
-------
6810-
out: DataTypes
6811-
a dictionary containing supported data types.
6812-
6813-
.. note::
6814-
Dictionary keys must only consist of canonical names as defined in :ref:`data-types`.
6710+
out: Info
6711+
An object containing Array API namespace inspection utilities.
68156712
68166713
Notes
68176714
-----
6715+
The returned object may be either a namespace or a class, so long as an Array API user can access inspection utilities as follows:
68186716
6819-
.. versionadded: 2023.12
6820-
6821-
"""
6822-
6823-
@abstractmethod
6824-
def __call__(self, /, *, device: Optional[TDevice] = None, kind: Optional[Union[str, tuple[str, ...]]] = None) -> TDatatypes: ...
6825-
6826-
6827-
@runtime_checkable
6828-
class devices[TDevice](Protocol):
6829-
"""
6830-
Returns a list of supported devices which are available at runtime.
6831-
6832-
Returns
6833-
-------
6834-
out: List[device]
6835-
a list of supported devices.
6717+
::
68366718
6837-
Notes
6838-
-----
6839-
Each device object (see :ref:`device-support`) in the list of returned devices must be an object which can be provided as a valid keyword-argument to array creation functions.
6840-
6841-
Notes
6842-
-----
6719+
info = xp.__array_namespace_info__()
6720+
info.capabilities()
6721+
info.devices()
6722+
info.dtypes()
6723+
info.default_dtypes()
6724+
# ...
68436725
68446726
.. versionadded: 2023.12
68456727
68466728
"""
68476729

68486730
@abstractmethod
6849-
def __call__(self, /) -> list[TDevice]: ...
6731+
def __call__(self, /) -> Info: ...
68506732

68516733

68526734
@runtime_checkable
@@ -8124,21 +8006,6 @@ class unstack[TArray: _array](Protocol):
81248006
def __call__(self, x: TArray, /, *, axis: int = 0) -> tuple[TArray, ...]: ...
81258007

81268008

8127-
@runtime_checkable
8128-
class Info[TCapabilities, TDatatypes, TDefaultdatatypes, TArray: _array, TDevice, TDtype](Protocol):
8129-
"""Namespace returned by `__array_namespace_info__`."""
8130-
8131-
def capabilities(self) -> TCapabilities: ...
8132-
8133-
def default_device(self) -> TDevice: ...
8134-
8135-
def default_dtypes(self, *, device: Optional[TDevice]) -> TDefaultdatatypes: ...
8136-
8137-
def devices(self) -> list[TDevice]: ...
8138-
8139-
def dtypes(self, *, device: Optional[TDevice], kind: Optional[Union[str, tuple[str, ...]]]) -> TDatatypes: ...
8140-
8141-
81428009
@runtime_checkable
81438010
class unique_all[TArray: _array](Protocol):
81448011
"""
@@ -8384,7 +8251,7 @@ class FftNamespace[TArray: _array, TDevice](Protocol):
83848251

83858252

83868253
@runtime_checkable
8387-
class ArrayNamespace[TCapabilities, TDatatypes, TDefaultdatatypes, TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](Protocol):
8254+
class ArrayNamespace[TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](Protocol):
83888255
astype: astype[TArray, TDevice, TDtype]
83898256
can_cast: can_cast[TArray, TDtype]
83908257
finfo: finfo[TArray, TDtype]
@@ -8489,11 +8356,7 @@ class ArrayNamespace[TCapabilities, TDatatypes, TDefaultdatatypes, TSupportsbuff
84898356
where: where[TArray,]
84908357
all: all[TArray,]
84918358
any: any[TArray,]
8492-
capabilities: capabilities[TCapabilities,]
8493-
default_device: default_device[TDevice,]
8494-
default_dtypes: default_dtypes[TDatatypes, TDefaultdatatypes, TDevice]
8495-
dtypes: dtypes[TDatatypes, TDevice]
8496-
devices: devices[TDevice,]
8359+
__array_namespace_info__: __array_namespace_info__[()]
84978360
take: take[TArray,]
84988361
array: TArray
84998362
matmul: matmul[TArray,]

0 commit comments

Comments
 (0)