|
| 1 | +__all__ = [ |
| 2 | + "__array_namespace_info__", |
| 3 | + "capabilities", |
| 4 | + "default_device", |
| 5 | + "default_dtypes", |
| 6 | + "devices", |
| 7 | + "dtypes", |
| 8 | +] |
| 9 | + |
| 10 | +from ._types import ( |
| 11 | + Optional, |
| 12 | + Union, |
| 13 | + Tuple, |
| 14 | + List, |
| 15 | + device, |
| 16 | + dtype, |
| 17 | + DefaultDataTypes, |
| 18 | + DataTypes, |
| 19 | + Capabilities, |
| 20 | + Info, |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +def __array_namespace_info__() -> Info: |
| 25 | + """ |
| 26 | + Returns a namespace with Array API namespace inspection utilities. |
| 27 | +
|
| 28 | + Returns |
| 29 | + ------- |
| 30 | + out: Info |
| 31 | + Namespace with Array API namespace inspection utilities. |
| 32 | + """ |
| 33 | + |
| 34 | + |
| 35 | +def capabilities() -> Capabilities: |
| 36 | + """ |
| 37 | + Returns a dictionary of array library capabilities. |
| 38 | +
|
| 39 | + The dictionary should contain the following keys: |
| 40 | +
|
| 41 | + - **boolean_indexing**: boolean indicating whether an array library supports boolean indexing. |
| 42 | + - **data_dependent_shapes**: boolean indicating whether an array library supports data-dependent output shapes. |
| 43 | +
|
| 44 | + Returns |
| 45 | + ------- |
| 46 | + out: Capabilities |
| 47 | + a dictionary of array library capabilities. |
| 48 | + """ |
| 49 | + |
| 50 | + |
| 51 | +def default_device() -> device: |
| 52 | + """ |
| 53 | + Returns an object for the default device. |
| 54 | +
|
| 55 | + Returns |
| 56 | + ------- |
| 57 | + out: device |
| 58 | + an object corresponding to the default device. |
| 59 | + """ |
| 60 | + |
| 61 | + |
| 62 | +def default_dtypes( |
| 63 | + *, |
| 64 | + device: Optional[device] = None, |
| 65 | +) -> DefaultDataTypes: |
| 66 | + """ |
| 67 | + Returns a dictionary containing default data types. |
| 68 | +
|
| 69 | + The dictionary should have the following keys: |
| 70 | +
|
| 71 | + - **real floating**: default real floating-point data type. |
| 72 | + - **complex floating**: default complex floating-point data type. |
| 73 | + - **integral**: default integral data type. |
| 74 | + - **indexing**: default index data type. |
| 75 | +
|
| 76 | + Parameters |
| 77 | + ---------- |
| 78 | + device: Optional[device] |
| 79 | + 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. If ``device`` is not ``None``, the returned data types must be default data types specific to the specified device. Default: ``None``. |
| 80 | +
|
| 81 | + .. note:: |
| 82 | + 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. |
| 83 | +
|
| 84 | + Returns |
| 85 | + ------- |
| 86 | + out: DefaultDataTypes |
| 87 | + a dictionary containing the default data type for respective data type kinds. |
| 88 | + """ |
| 89 | + |
| 90 | + |
| 91 | +def dtypes( |
| 92 | + *, |
| 93 | + device: Optional[device] = None, |
| 94 | + kind: Optional[Union[str, Tuple[str, ...]]] = None, |
| 95 | +) -> DataTypes: |
| 96 | + """ |
| 97 | + Returns a dictionary of supported *Array API* data types. |
| 98 | +
|
| 99 | + .. note:: |
| 100 | + 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. |
| 101 | +
|
| 102 | + Parameters |
| 103 | + ---------- |
| 104 | + kind: Optional[Union[str, Tuple[str, ...]]] |
| 105 | + data type kind. |
| 106 | +
|
| 107 | + - If ``kind`` is ``None``, the function must return a dictionary containing all supported Array API data types. |
| 108 | +
|
| 109 | + - 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: |
| 110 | +
|
| 111 | + - ``'bool'``: boolean data types (e.g., ``bool``). |
| 112 | + - ``'signed integer'``: signed integer data types (e.g., ``int8``, ``int16``, ``int32``, ``int64``). |
| 113 | + - ``'unsigned integer'``: unsigned integer data types (e.g., ``uint8``, ``uint16``, ``uint32``, ``uint64``). |
| 114 | + - ``'integral'``: integer data types. Shorthand for ``('signed integer', 'unsigned integer')``. |
| 115 | + - ``'real floating'``: real-valued floating-point data types (e.g., ``float32``, ``float64``). |
| 116 | + - ``'complex floating'``: complex floating-point data types (e.g., ``complex64``, ``complex128``). |
| 117 | + - ``'numeric'``: numeric data types. Shorthand for ``('integral', 'real floating', 'complex floating')``. |
| 118 | +
|
| 119 | + - 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. |
| 120 | +
|
| 121 | + Default: ``None``. |
| 122 | + device: Optional[device] |
| 123 | + 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``. |
| 124 | +
|
| 125 | + .. note:: |
| 126 | + 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. |
| 127 | +
|
| 128 | + Returns |
| 129 | + ------- |
| 130 | + out: DataTypes |
| 131 | + a dictionary containing supported data types. |
| 132 | + """ |
| 133 | + |
| 134 | + |
| 135 | +def devices() -> List[device]: |
| 136 | + """ |
| 137 | + Returns a list of supported devices. |
| 138 | +
|
| 139 | + Returns |
| 140 | + ------- |
| 141 | + out: List[device] |
| 142 | + a list of supported devices. |
| 143 | + """ |
0 commit comments