Skip to content

Commit eab417a

Browse files
committed
chore: wip
1 parent c38bda2 commit eab417a

File tree

4 files changed

+525
-4
lines changed

4 files changed

+525
-4
lines changed

src/array_api/_2023_12.py

Lines changed: 172 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6683,6 +6683,172 @@ class any[TArray: _array](Protocol):
66836683
def __call__(self, x: TArray, /, *, axis: Optional[Union[int, tuple[int, ...]]] = None, keepdims: bool = False) -> TArray: ...
66846684

66856685

6686+
@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.
6754+
6755+
Returns
6756+
-------
6757+
out: DefaultDataTypes
6758+
a dictionary containing the default data type for respective data type kinds.
6759+
6760+
Notes
6761+
-----
6762+
6763+
.. versionadded: 2023.12
6764+
6765+
"""
6766+
6767+
@abstractmethod
6768+
def __call__(self, /, *, device: Optional[TDevice] = None) -> TDefaultdatatypes: ...
6769+
6770+
6771+
@runtime_checkable
6772+
class dtypes[TDatatypes, TDevice](Protocol):
6773+
"""
6774+
Returns a dictionary of supported *Array API* data types.
6775+
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.
6807+
6808+
Returns
6809+
-------
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`.
6815+
6816+
Notes
6817+
-----
6818+
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.
6836+
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+
-----
6843+
6844+
.. versionadded: 2023.12
6845+
6846+
"""
6847+
6848+
@abstractmethod
6849+
def __call__(self, /) -> list[TDevice]: ...
6850+
6851+
66866852
@runtime_checkable
66876853
class take[TArray: _array](Protocol):
66886854
"""
@@ -8218,7 +8384,7 @@ class FftNamespace[TArray: _array, TDevice](Protocol):
82188384

82198385

82208386
@runtime_checkable
8221-
class ArrayNamespace[TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](Protocol):
8387+
class ArrayNamespace[TCapabilities, TDatatypes, TDefaultdatatypes, TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](Protocol):
82228388
astype: astype[TArray, TDevice, TDtype]
82238389
can_cast: can_cast[TArray, TDtype]
82248390
finfo: finfo[TArray, TDtype]
@@ -8323,6 +8489,11 @@ class ArrayNamespace[TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](P
83238489
where: where[TArray,]
83248490
all: all[TArray,]
83258491
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,]
83268497
take: take[TArray,]
83278498
array: TArray
83288499
matmul: matmul[TArray,]

src/array_api/_2024_12.py

Lines changed: 176 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7110,6 +7110,176 @@ class diff[TArray: _array](Protocol):
71107110
def __call__(self, x: TArray, /, *, axis: int = -1, n: int = 1, prepend: Optional[TArray] = None, append: Optional[TArray] = None) -> TArray: ...
71117111

71127112

7113+
@runtime_checkable
7114+
class capabilities[TCapabilities](Protocol):
7115+
"""
7116+
Returns a dictionary of array library capabilities.
7117+
7118+
The dictionary must contain the following keys:
7119+
7120+
- `"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``.
7121+
- `"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``.
7122+
- `"max dimensions"`: maximum number of supported dimensions. If a conforming implementation supports arrays having an arbitrary number of dimensions (potentially infinite), the corresponding dictionary value must be ``None``; otherwise, the value must be a finite integer.
7123+
7124+
Returns
7125+
-------
7126+
out: Capabilities
7127+
a dictionary of array library capabilities.
7128+
7129+
Notes
7130+
-----
7131+
7132+
.. versionadded: 2023.12
7133+
7134+
.. versionchanged:: 2024.12
7135+
Added support for querying the maximum number of supported dimensions.
7136+
7137+
"""
7138+
7139+
@abstractmethod
7140+
def __call__(self, /) -> TCapabilities: ...
7141+
7142+
7143+
@runtime_checkable
7144+
class default_device[TDevice](Protocol):
7145+
"""
7146+
Returns the default device.
7147+
7148+
Returns
7149+
-------
7150+
out: device
7151+
an object corresponding to the default device.
7152+
7153+
Notes
7154+
-----
7155+
7156+
.. versionadded: 2023.12
7157+
7158+
"""
7159+
7160+
@abstractmethod
7161+
def __call__(self, /) -> TDevice: ...
7162+
7163+
7164+
@runtime_checkable
7165+
class default_dtypes[TDatatypes, TDefaultdatatypes, TDevice](Protocol):
7166+
"""
7167+
Returns a dictionary containing default data types.
7168+
7169+
The dictionary must have the following keys:
7170+
7171+
- `"real floating"`: default real floating-point data type.
7172+
- `"complex floating"`: default complex floating-point data type.
7173+
- `"integral"`: default integral data type.
7174+
- `"indexing"`: default array index data type.
7175+
7176+
Dictionary values must be the corresponding data type object.
7177+
7178+
Parameters
7179+
----------
7180+
device: Optional[device]
7181+
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``.
7182+
7183+
.. note::
7184+
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.
7185+
7186+
Returns
7187+
-------
7188+
out: DefaultDataTypes
7189+
a dictionary containing the default data type for respective data type kinds.
7190+
7191+
Notes
7192+
-----
7193+
7194+
.. versionadded: 2023.12
7195+
7196+
"""
7197+
7198+
@abstractmethod
7199+
def __call__(self, /, *, device: Optional[TDevice] = None) -> TDefaultdatatypes: ...
7200+
7201+
7202+
@runtime_checkable
7203+
class dtypes[TDatatypes, TDevice](Protocol):
7204+
"""
7205+
Returns a dictionary of supported *Array API* data types.
7206+
7207+
.. note::
7208+
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.
7209+
7210+
.. note::
7211+
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.
7212+
7213+
Parameters
7214+
----------
7215+
kind: Optional[Union[str, Tuple[str, ...]]]
7216+
data type kind.
7217+
7218+
- If ``kind`` is ``None``, the function must return a dictionary containing all supported Array API data types.
7219+
7220+
- 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:
7221+
7222+
- ``'bool'``: boolean data types (e.g., ``bool``).
7223+
- ``'signed integer'``: signed integer data types (e.g., ``int8``, ``int16``, ``int32``, ``int64``).
7224+
- ``'unsigned integer'``: unsigned integer data types (e.g., ``uint8``, ``uint16``, ``uint32``, ``uint64``).
7225+
- ``'integral'``: integer data types. Shorthand for ``('signed integer', 'unsigned integer')``.
7226+
- ``'real floating'``: real-valued floating-point data types (e.g., ``float32``, ``float64``).
7227+
- ``'complex floating'``: complex floating-point data types (e.g., ``complex64``, ``complex128``).
7228+
- ``'numeric'``: numeric data types. Shorthand for ``('integral', 'real floating', 'complex floating')``.
7229+
7230+
- 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.
7231+
7232+
Default: ``None``.
7233+
device: Optional[device]
7234+
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``.
7235+
7236+
.. note::
7237+
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.
7238+
7239+
Returns
7240+
-------
7241+
out: DataTypes
7242+
a dictionary containing supported data types.
7243+
7244+
.. note::
7245+
Dictionary keys must only consist of canonical names as defined in :ref:`data-types`.
7246+
7247+
Notes
7248+
-----
7249+
7250+
.. versionadded: 2023.12
7251+
7252+
"""
7253+
7254+
@abstractmethod
7255+
def __call__(self, /, *, device: Optional[TDevice] = None, kind: Optional[Union[str, tuple[str, ...]]] = None) -> TDatatypes: ...
7256+
7257+
7258+
@runtime_checkable
7259+
class devices[TDevice](Protocol):
7260+
"""
7261+
Returns a list of supported devices which are available at runtime.
7262+
7263+
Returns
7264+
-------
7265+
out: List[device]
7266+
a list of supported devices.
7267+
7268+
Notes
7269+
-----
7270+
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.
7271+
7272+
Notes
7273+
-----
7274+
7275+
.. versionadded: 2023.12
7276+
7277+
"""
7278+
7279+
@abstractmethod
7280+
def __call__(self, /) -> list[TDevice]: ...
7281+
7282+
71137283
@runtime_checkable
71147284
class take[TArray: _array](Protocol):
71157285
"""
@@ -8691,7 +8861,7 @@ class FftNamespace[TArray: _array, TDevice, TDtype](Protocol):
86918861

86928862

86938863
@runtime_checkable
8694-
class ArrayNamespace[TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](Protocol):
8864+
class ArrayNamespace[TCapabilities, TDatatypes, TDefaultdatatypes, TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](Protocol):
86958865
astype: astype[TArray, TDevice, TDtype]
86968866
can_cast: can_cast[TArray, TDtype]
86978867
finfo: finfo[TArray, TDtype]
@@ -8801,6 +8971,11 @@ class ArrayNamespace[TSupportsbufferprotocol, TArray: _array, TDevice, TDtype](P
88018971
all: all[TArray,]
88028972
any: any[TArray,]
88038973
diff: diff[TArray,]
8974+
capabilities: capabilities[TCapabilities,]
8975+
default_device: default_device[TDevice,]
8976+
default_dtypes: default_dtypes[TDatatypes, TDefaultdatatypes, TDevice]
8977+
dtypes: dtypes[TDatatypes, TDevice]
8978+
devices: devices[TDevice,]
88048979
take: take[TArray,]
88058980
take_along_axis: take_along_axis[TArray,]
88068981
array: TArray

0 commit comments

Comments
 (0)