Skip to content

Commit b9e95ed

Browse files
committed
Fix notes and admonitions
1 parent af981b9 commit b9e95ed

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

spec/API_specification/signatures/creation_functions.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ def arange(start: Union[int, float], /, stop: Optional[Union[int, float]] = None
1818
device: Optional[device]
1919
device on which to place the created array. Default: ``None``.
2020
21+
22+
.. note::
23+
This function cannot guarantee that the interval does not include the ``stop`` value in those cases where ``step`` is not an integer and floating-point rounding errors affect the length of the output array.
24+
2125
Returns
2226
-------
2327
out: array
2428
a one-dimensional array containing evenly spaced values. The length of the output array must be ``ceil((stop-start)/step)`` if ``stop - start`` and ``step`` have the same sign, and length ``0`` otherwise.
25-
26-
Notes
27-
-----
28-
- This function cannot guarantee that the interval does not include the ``stop`` value in those cases where ``step`` is not an integer and floating-point rounding errors affect the length of the output array.
2929
"""
3030

3131
def asarray(obj: Union[array, bool, int, float, NestedSequence, SupportsBufferProtocol], /, *, dtype: Optional[dtype] = None, device: Optional[device] = None, copy: Optional[bool] = None) -> array:
@@ -37,9 +37,11 @@ def asarray(obj: Union[array, bool, int, float, NestedSequence, SupportsBufferPr
3737
obj: Union[array, bool, int, float, NestedSequence[bool | int | float], SupportsBufferProtocol]
3838
object to be converted to an array. May be a Python scalar, a (possibly nested) sequence of Python scalars, or an object supporting the Python buffer protocol.
3939
40-
**Tip**
40+
.. admonition:: Tip
41+
:class: important
42+
43+
An object supporting the buffer protocol can be turned into a memoryview through ``memoryview(obj)``.
4144
42-
An object supporting the buffer protocol can be turned into a memoryview through ``memoryview(obj)``.
4345
dtype: Optional[dtype]
4446
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from the data type(s) in ``obj``. If all input values are Python scalars, then
4547
@@ -48,6 +50,12 @@ def asarray(obj: Union[array, bool, int, float, NestedSequence, SupportsBufferPr
4850
- if one or more values are ``float``\s, the output data type must be the default floating-point data type.
4951
5052
Default: ``None``.
53+
54+
.. admonition:: Note
55+
:class: note
56+
57+
If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library. To perform an explicit cast, use :ref:`function-astype`.
58+
5159
device: Optional[device]
5260
device on which to place the created array. If ``device`` is ``None`` and ``x`` is an array, the output array device must be inferred from ``x``. Default: ``None``.
5361
copy: Optional[bool]
@@ -57,10 +65,6 @@ def asarray(obj: Union[array, bool, int, float, NestedSequence, SupportsBufferPr
5765
-------
5866
out: array
5967
an array containing the data from ``obj``.
60-
61-
Notes
62-
-----
63-
- If ``dtype`` is not ``None``, then array conversions should obey :ref:`type-promotion` rules. Conversions not specified according to :ref:`type-promotion` rules may or may not be permitted by a conforming array library. To perform an explicit cast, use :ref:`function-astype`.
6468
"""
6569

6670
def empty(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
@@ -138,9 +142,10 @@ def from_dlpack(x: object, /) -> array:
138142
out: array
139143
an array containing the data in `x`.
140144
141-
Notes
142-
-----
143-
- The returned array may be either a copy or a view. See :ref:`data-interchange` for details.
145+
.. admonition:: Note
146+
:class: note
147+
148+
The returned array may be either a copy or a view. See :ref:`data-interchange` for details.
144149
"""
145150

146151
def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
@@ -155,17 +160,17 @@ def full(shape: Union[int, Tuple[int, ...]], fill_value: Union[int, float], *, d
155160
fill value.
156161
dtype: Optional[dtype]
157162
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``fill_value``. If the fill value is an ``int``, the output array data type must be the default integer data type. If the fill value is a ``float``, the output array data type must be the default floating-point data type. If the fill value is a ``bool``, the output array must have boolean data type. Default: ``None``.
163+
164+
.. note::
165+
If ``dtype`` is ``None`` and the ``fill_value`` exceeds the precision of the resolved default output array data type, behavior is left unspecified and, thus, implementation-defined.
166+
158167
device: Optional[device]
159168
device on which to place the created array. Default: ``None``.
160169
161170
Returns
162171
-------
163172
out: array
164173
an array where every element is equal to ``fill_value``.
165-
166-
Notes
167-
-----
168-
- If ``dtype`` is ``None`` and the ``fill_value`` exceeds the precision of the resolved default output array data type, behavior is left unspecified and, thus, implementation-defined.
169174
"""
170175

171176
def full_like(x: array, /, fill_value: Union[int, float], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
@@ -180,18 +185,20 @@ def full_like(x: array, /, fill_value: Union[int, float], *, dtype: Optional[dty
180185
fill value.
181186
dtype: Optional[dtype]
182187
output array data type. If ``dtype`` is ``None``, the output array data type must be inferred from ``x``. Default: ``None``.
188+
189+
.. note::
190+
If ``dtype`` is ``None`` and the ``fill_value`` exceeds the precision of the resolved output array data type, behavior is unspecified and, thus, implementation-defined.
191+
192+
.. note::
193+
If ``dtype`` is ``None`` and the ``fill_value`` has a data type (``int`` or ``float``) which is not of the same data type kind as the resolved output array data type (see :ref:`type-promotion`), behavior is unspecified and, thus, implementation-defined.
194+
183195
device: Optional[device]
184196
device on which to place the created array. If ``device`` is ``None``, the output array device must be inferred from ``x``. Default: ``None``.
185197
186198
Returns
187199
-------
188200
out: array
189201
an array having the same shape as ``x`` and where every element is equal to ``fill_value``.
190-
191-
Notes
192-
-----
193-
- If ``dtype`` is ``None`` and the ``fill_value`` exceeds the precision of the resolved output array data type, behavior is unspecified and, thus, implementation-defined.
194-
- If ``dtype`` is ``None`` and the ``fill_value`` has a data type (``int`` or ``float``) which is not of the same data type kind as the resolved output array data type (see :ref:`type-promotion`), behavior is unspecified and, thus, implementation-defined.
195202
"""
196203

197204
def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *, dtype: Optional[dtype] = None, device: Optional[device] = None, endpoint: bool = True) -> array:
@@ -204,6 +211,10 @@ def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *,
204211
the start of the interval.
205212
stop: Union[int, float]
206213
the end of the interval. If ``endpoint`` is ``False``, the function must generate a sequence of ``num+1`` evenly spaced numbers starting with ``start`` and ending with ``stop`` and exclude the ``stop`` from the returned array such that the returned array consists of evenly spaced numbers over the half-open interval ``[start, stop)``. If ``endpoint`` is ``True``, the output array must consist of evenly spaced numbers over the closed interval ``[start, stop]``. Default: ``True``.
214+
215+
.. note::
216+
The step size changes when `endpoint` is `False`.
217+
207218
num: int
208219
number of samples. Must be a non-negative integer value; otherwise, the function must raise an exception.
209220
dtype: Optional[dtype]
@@ -217,10 +228,6 @@ def linspace(start: Union[int, float], stop: Union[int, float], /, num: int, *,
217228
-------
218229
out: array
219230
a one-dimensional array containing evenly spaced values.
220-
221-
Notes
222-
-----
223-
- The step size changes when `endpoint` is `False`.
224231
"""
225232

226233
def meshgrid(*arrays: array, indexing: str = 'xy') -> List[array]:
@@ -291,44 +298,46 @@ def tril(x: array, /, *, k: int = 0) -> array:
291298
"""
292299
Returns the lower triangular part of a matrix (or a stack of matrices) ``x``.
293300
301+
.. note::
302+
The lower triangular part of the matrix is defined as the elements on and below the specified diagonal ``k``.
303+
294304
Parameters
295305
----------
296306
x: array
297307
input array having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices.
298308
k: int
299309
diagonal above which to zero elements. If ``k = 0``, the diagonal is the main diagonal. If ``k < 0``, the diagonal is below the main diagonal. If ``k > 0``, the diagonal is above the main diagonal. Default: ``0``.
300310
311+
.. note::
312+
The main diagonal is defined as the set of indices ``{(i, i)}`` for ``i`` on the interval ``[0, min(M, N) - 1]``.
313+
301314
Returns
302315
-------
303316
out: array
304317
an array containing the lower triangular part(s). The returned array must have the same shape and data type as ``x``. All elements above the specified diagonal ``k`` must be zeroed. The returned array should be allocated on the same device as ``x``.
305-
306-
Notes
307-
-----
308-
- The lower triangular part of the matrix is defined as the elements on and below the specified diagonal ``k``.
309-
- The main diagonal is defined as the set of indices ``{(i, i)}`` for ``i`` on the interval ``[0, min(M, N) - 1]``.
310318
"""
311319

312320
def triu(x: array, /, *, k: int = 0) -> array:
313321
"""
314322
Returns the upper triangular part of a matrix (or a stack of matrices) ``x``.
315323
324+
.. note::
325+
The upper triangular part of the matrix is defined as the elements on and above the specified diagonal ``k``.
326+
316327
Parameters
317328
----------
318329
x: array
319330
input array having shape ``(..., M, N)`` and whose innermost two dimensions form ``MxN`` matrices.
320331
k: int
321332
diagonal below which to zero elements. If ``k = 0``, the diagonal is the main diagonal. If ``k < 0``, the diagonal is below the main diagonal. If ``k > 0``, the diagonal is above the main diagonal. Default: ``0``.
322333
334+
.. note::
335+
The main diagonal is defined as the set of indices ``{(i, i)}`` for ``i`` on the interval ``[0, min(M, N) - 1]``.
336+
323337
Returns
324338
-------
325339
out: array
326340
an array containing the upper triangular part(s). The returned array must have the same shape and data type as ``x``. All elements below the specified diagonal ``k`` must be zeroed. The returned array should be allocated on the same device as ``x``.
327-
328-
Notes
329-
-----
330-
- The upper triangular part of the matrix is defined as the elements on and above the specified diagonal ``k``.
331-
- The main diagonal is defined as the set of indices ``{(i, i)}`` for ``i`` on the interval ``[0, min(M, N) - 1]``.
332341
"""
333342

334343
def zeros(shape: Union[int, Tuple[int, ...]], *, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:

0 commit comments

Comments
 (0)