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