Skip to content

Commit 0a2fa71

Browse files
committed
Move special cases to notes section
1 parent 7f4d85b commit 0a2fa71

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

spec/API_specification/array_api/array_object.py

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ def __bool__(self: array, /) -> bool:
206206
"""
207207
Converts a zero-dimensional array to a Python ``bool`` object.
208208
209+
Parameters
210+
----------
211+
self: array
212+
zero-dimensional array instance.
213+
214+
Returns
215+
-------
216+
out: bool
217+
a Python ``bool`` object representing the single element of the array.
218+
219+
Notes
220+
-----
221+
209222
**Special cases**
210223
211224
For real-valued floating-point operands,
@@ -215,6 +228,11 @@ def __bool__(self: array, /) -> bool:
215228
- If ``self`` is either ``+0`` or ``-0``, the result is ``False``.
216229
217230
For complex floating-point operands, special cases must be handled as if the operation is implemented as the logical AND of ``bool(real(self))`` and ``bool(imag(self))``.
231+
"""
232+
233+
def __complex__(self: array, /) -> complex:
234+
"""
235+
Converts a zero-dimensional array to a Python ``complex`` object.
218236
219237
Parameters
220238
----------
@@ -223,13 +241,11 @@ def __bool__(self: array, /) -> bool:
223241
224242
Returns
225243
-------
226-
out: bool
227-
a Python ``bool`` object representing the single element of the array.
228-
"""
244+
out: complex
245+
a Python ``complex`` object representing the single element of the array instance.
229246
230-
def __complex__(self: array, /) -> complex:
231-
"""
232-
Converts a zero-dimensional array to a Python ``complex`` object.
247+
Notes
248+
-----
233249
234250
**Special cases**
235251
@@ -244,16 +260,6 @@ def __complex__(self: array, /) -> complex:
244260
- If ``self`` is ``+infinity``, the result is ``+infinity + 0j``.
245261
- If ``self`` is ``-infinity``, the result is ``-infinity + 0j``.
246262
- If ``self`` is a finite number, the result is ``self + 0j``.
247-
248-
Parameters
249-
----------
250-
self: array
251-
zero-dimensional array instance.
252-
253-
Returns
254-
-------
255-
out: complex
256-
a Python ``complex`` object representing the single element of the array instance.
257263
"""
258264

259265
def __dlpack__(
@@ -376,13 +382,6 @@ def __float__(self: array, /) -> float:
376382
.. note::
377383
Casting integer values outside the representable bounds of Python's float type is not specified and is implementation-dependent.
378384
379-
**Special cases**
380-
381-
For boolean operands,
382-
383-
- If ``self`` is ``True``, the result is ``1``.
384-
- If ``self`` is ``False``, the result is ``0``.
385-
386385
Parameters
387386
----------
388387
self: array
@@ -392,6 +391,16 @@ def __float__(self: array, /) -> float:
392391
-------
393392
out: float
394393
a Python ``float`` object representing the single element of the array instance.
394+
395+
Notes
396+
-----
397+
398+
**Special cases**
399+
400+
For boolean operands,
401+
402+
- If ``self`` is ``True``, the result is ``1``.
403+
- If ``self`` is ``False``, the result is ``0``.
395404
"""
396405

397406
def __floordiv__(self: array, other: Union[int, float, array], /) -> array:
@@ -511,6 +520,19 @@ def __int__(self: array, /) -> int:
511520
"""
512521
Converts a zero-dimensional array to a Python ``int`` object.
513522
523+
Parameters
524+
----------
525+
self: array
526+
zero-dimensional array instance. Should have a real-valued or boolean data type. If ``self`` has a complex floating-point data type, the function must raise a ``TypeError``.
527+
528+
Returns
529+
-------
530+
out: int
531+
a Python ``int`` object representing the single element of the array instance.
532+
533+
Notes
534+
-----
535+
514536
**Special cases**
515537
516538
For boolean operands,
@@ -523,17 +545,6 @@ def __int__(self: array, /) -> int:
523545
- If ``self`` is a finite number, the result is the integer part of ``self``.
524546
- If ``self`` is ``-0``, the result is ``0``.
525547
526-
Parameters
527-
----------
528-
self: array
529-
zero-dimensional array instance. Should have a real-valued or boolean data type. If ``self`` has a complex floating-point data type, the function must raise a ``TypeError``.
530-
531-
Returns
532-
-------
533-
out: int
534-
a Python ``int`` object representing the single element of the array instance.
535-
536-
537548
**Raises**
538549
539550
For floating-point operands,

0 commit comments

Comments
 (0)