Skip to content

Commit a52285e

Browse files
authored
docs: move notes below the fold and highlight RFC 2119 keywords
PR-URL: #956 Ref: #397
1 parent b4d28f0 commit a52285e

File tree

1 file changed

+33
-43
lines changed

1 file changed

+33
-43
lines changed

src/array_api_stubs/_draft/info.py

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ def __array_namespace_info__() -> Info:
2525
"""
2626
Returns a namespace with Array API namespace inspection utilities.
2727
28-
See :ref:`inspection` for a list of inspection APIs.
29-
3028
Returns
3129
-------
3230
out: Info
33-
An object containing Array API namespace inspection utilities.
31+
an object containing Array API namespace inspection utilities.
3432
3533
Notes
3634
-----
3735
38-
The returned object may be either a namespace or a class, so long as an Array API user can access inspection utilities as follows:
36+
- See :ref:`inspection` for a list of inspection APIs.
37+
38+
- The returned object **may** be either a namespace or a class, as long as an Array API user can access inspection utilities as follows:
3939
4040
::
4141
@@ -54,16 +54,14 @@ def capabilities() -> Capabilities:
5454
"""
5555
Returns a dictionary of array library capabilities.
5656
57-
The dictionary must contain the following keys:
58-
59-
- `"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``.
60-
- `"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``.
61-
- `"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.
62-
6357
Returns
6458
-------
6559
out: Capabilities
66-
a dictionary of array library capabilities.
60+
a dictionary of array library capabilities. The returned dictionary **must** contain the following keys:
61+
62+
- `"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``.
63+
- `"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``.
64+
- `"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.
6765
6866
Notes
6967
-----
@@ -98,31 +96,28 @@ def default_dtypes(
9896
"""
9997
Returns a dictionary containing default data types.
10098
101-
The dictionary must have the following keys:
102-
103-
- `"real floating"`: default real floating-point data type.
104-
- `"complex floating"`: default complex floating-point data type.
105-
- `"integral"`: default integral data type.
106-
- `"indexing"`: default array index data type.
107-
108-
Dictionary values must be the corresponding data type object.
109-
11099
Parameters
111100
----------
112101
device: Optional[device]
113-
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``.
114-
115-
.. note::
116-
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.
102+
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``.
117103
118104
Returns
119105
-------
120106
out: DefaultDataTypes
121-
a dictionary containing the default data type for respective data type kinds.
107+
a dictionary containing the default data type for respective data type kinds. The returned dictionary **must** have the following keys:
108+
109+
- `"real floating"`: default real floating-point data type.
110+
- `"complex floating"`: default complex floating-point data type.
111+
- `"integral"`: default integral data type.
112+
- `"indexing"`: default array index data type.
113+
114+
Dictionary values **must** be the corresponding data type object.
122115
123116
Notes
124117
-----
125118
119+
- 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 **must** return the default data types for the current device. For libraries without a context manager or supporting only a single device, those libraries **must** return the default data types for the default device.
120+
126121
.. versionadded: 2023.12
127122
"""
128123

@@ -135,20 +130,14 @@ def dtypes(
135130
"""
136131
Returns a dictionary of supported *Array API* data types.
137132
138-
.. note::
139-
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.
140-
141-
.. note::
142-
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.
143-
144133
Parameters
145134
----------
146135
kind: Optional[Union[str, Tuple[str, ...]]]
147136
data type kind.
148137
149-
- If ``kind`` is ``None``, the function must return a dictionary containing all supported Array API data types.
138+
- If ``kind`` is ``None``, the function **must** return a dictionary containing all supported Array API data types.
150139
151-
- 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:
140+
- 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:
152141
153142
- ``'bool'``: boolean data types (e.g., ``bool``).
154143
- ``'signed integer'``: signed integer data types (e.g., ``int8``, ``int16``, ``int32``, ``int64``).
@@ -158,26 +147,27 @@ def dtypes(
158147
- ``'complex floating'``: complex floating-point data types (e.g., ``complex64``, ``complex128``).
159148
- ``'numeric'``: numeric data types. Shorthand for ``('integral', 'real floating', 'complex floating')``.
160149
161-
- 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.
150+
- 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.
162151
163152
Default: ``None``.
164-
device: Optional[device]
165-
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``.
166153
167-
.. note::
168-
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.
154+
device: Optional[device]
155+
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``.
169156
170157
Returns
171158
-------
172159
out: DataTypes
173-
a dictionary containing supported data types.
174-
175-
.. note::
176-
Dictionary keys must only consist of canonical names as defined in :ref:`data-types`.
160+
a dictionary containing supported data types. The returned dictionary **must** only contain keys corresponding to the canonical names as defined in :ref:`data-types`.
177161
178162
Notes
179163
-----
180164
165+
- 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 **must not** be included in the returned dictionary.
166+
167+
- 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.
168+
169+
- 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 **must** return the supported data types for the current device. For libraries without a context manager or supporting only a single device, those libraries **must** return the supported data types for the default device.
170+
181171
.. versionadded: 2023.12
182172
"""
183173

@@ -194,7 +184,7 @@ def devices() -> List[device]:
194184
Notes
195185
-----
196186
197-
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.
187+
- 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.
198188
199189
Notes
200190
-----

0 commit comments

Comments
 (0)