Skip to content

Commit e476516

Browse files
honnokgryte
andauthored
Clearer and spec-consistent language for casting methods
Co-authored-by: Athan <[email protected]>
1 parent d25bcc4 commit e476516

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

spec/API_specification/array_api/array_object.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def __bool__(self: array, /) -> bool:
227227
Converts a zero-dimensional array to a Python ``bool`` object.
228228
229229
.. note::
230-
When casting a numeric input array to ``bool``, a value equal to ``0`` must cast to ``False``, and a value not equal to ``0`` must cast to ``True``.
230+
If ``self`` has a numeric data type, a value equal to ``0`` must cast to ``False``, and a value not equal to ``0`` must cast to ``True``.
231231
232232
Parameters
233233
----------
@@ -245,7 +245,7 @@ def __complex__(self: array, /) -> complex:
245245
Converts a zero-dimensional array to a Python ``complex`` object.
246246
247247
.. note::
248-
When casting a boolean input array, a value of ``True`` must cast to ``1+0j``, and a value of ``False`` must cast to ``0+0j``.
248+
If ``self`` has a boolean data type, a value of ``True`` must cast to ``1+0j``, and a value of ``False`` must cast to ``0+0j``.
249249
250250
Parameters
251251
----------
@@ -255,7 +255,7 @@ def __complex__(self: array, /) -> complex:
255255
Returns
256256
-------
257257
out: complex
258-
a Python ``complex`` object representing the single element of the array. If ``self`` has a real-valued or boolean data type, ``out`` must represent the element of ``self`` in the real component.
258+
a Python ``complex`` object representing the single element of the array instance. If ``self`` has a real-valued or boolean data type, the real component of the return value must equal the element of ``self`` and the imaginary component must be ``0``.
259259
"""
260260

261261
def __dlpack__(self: array, /, *, stream: Optional[Union[int, Any]] = None) -> PyCapsule:
@@ -368,12 +368,12 @@ def __float__(self: array, /) -> float:
368368
Casting integer values outside the representable bounds of Python's float type is not specified and is implementation-dependent.
369369
370370
.. note::
371-
When casting a boolean input array, a value of ``True`` must cast to ``1``, and a value of ``False`` must cast to ``0``.
371+
If ``self`` has a boolean data type, a value of ``True`` must cast to ``1``, and a value of ``False`` must cast to ``0``.
372372
373373
Parameters
374374
----------
375375
self: array
376-
zero-dimensional array instance. Should have a real-valued or boolean data type. If ``self`` has a complex data type, the function must raise a ``TypeError``.
376+
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``.
377377
378378
Returns
379379
-------
@@ -510,7 +510,7 @@ def __index__(self: array, /) -> int:
510510
Parameters
511511
----------
512512
self: array
513-
zero-dimensional array instance. Should have an integer data type. If ``self`` has a floating-point or complex data type, the function must raise a ``TypeError``.
513+
zero-dimensional array instance. Should have an integer data type. If ``self`` has a floating-point data type, the function must raise a ``TypeError``.
514514
515515
Returns
516516
-------
@@ -523,7 +523,7 @@ def __int__(self: array, /) -> int:
523523
Converts a zero-dimensional array to a Python ``int`` object.
524524
525525
.. note::
526-
When casting a boolean input array, a value of ``True`` must cast to ``1``, and a value of ``False`` must cast to ``0``.
526+
If ``self`` has a boolean data type, a value of ``True`` must cast to ``1``, and a value of ``False`` must cast to ``0``.
527527
528528
**Special cases**
529529
@@ -534,7 +534,7 @@ def __int__(self: array, /) -> int:
534534
Parameters
535535
----------
536536
self: array
537-
zero-dimensional array instance. Should have a real-valued or boolean data type. If ``self`` has a complex data type, the function must raise a ``TypeError``.
537+
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``.
538538
539539
Returns
540540
-------

0 commit comments

Comments
 (0)