You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Converts a zero-dimensional boolean array to a Python ``bool`` object.
227
+
Converts a zero-dimensional array to a Python ``bool`` object.
228
+
229
+
.. note::
230
+
When casting a real-valued input array to ``bool``, a value of ``0`` must cast to ``False``, and a non-zero value must cast to ``True``.
228
231
229
232
Parameters
230
233
----------
231
234
self: array
232
-
zero-dimensional array instance. Should have a boolean data type.
235
+
zero-dimensional array instance.
233
236
234
237
Returns
235
238
-------
236
239
out: bool
237
240
a Python ``bool`` object representing the single element of the array.
238
241
"""
239
242
240
-
def__complex__(self: array, /) ->bool:
243
+
def__complex__(self: array, /) ->complex:
241
244
"""
242
-
Converts a zero-dimensional complex array to a Python ``complex`` object.
245
+
Converts a zero-dimensional array to a Python ``complex`` object.
246
+
247
+
.. note::
248
+
When casting a boolean input array, a value of ``True`` must cast to ``1``, and a value of ``False`` must cast to ``0``.
243
249
244
250
Parameters
245
251
----------
246
252
self: array
247
-
zero-dimensional array instance. Should have a complex data type.
253
+
zero-dimensional array instance.
248
254
249
255
Returns
250
256
-------
251
257
out: complex
252
-
a Python ``complex`` object representing the single element of the array.
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.
Converts a zero-dimensional floating-point array to a Python ``float`` object.
365
+
Converts a zero-dimensional array to a Python ``float`` object.
366
+
367
+
.. note::
368
+
Casting integer values outside the representable bounds of Python's float type is not specified and is implementation-dependent.
369
+
370
+
.. 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``.
360
372
361
373
Parameters
362
374
----------
363
375
self: array
364
-
zero-dimensional array instance. Should have a real-valued floating-point data type.
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``.
Element-wise results must equal the results returned by the equivalent element-wise function :func:`~array_api.greater`.
489
501
"""
490
502
491
-
def__index__(self: array, /) ->int:
503
+
def__index__(self: array, /) ->Union[int, bool]:
492
504
"""
493
-
Converts a zero-dimensional integer array to a Python ``int`` object.
505
+
Converts a zero-dimensional array to a Python object used in indexing.
494
506
495
507
.. note::
496
508
This method is called to implement `operator.index() <https://docs.python.org/3/reference/datamodel.html#object.__index__>`_. See also `PEP 357 <https://www.python.org/dev/peps/pep-0357/>`_.
497
509
498
510
Parameters
499
511
----------
500
512
self: array
501
-
zero-dimensional array instance. Should have an integer data type.
513
+
zero-dimensional array instance. Should have an integer or boolean data type. If ``self`` has a floating-point or complex data type, the function must raise a ``TypeError``.
502
514
503
515
Returns
504
516
-------
505
-
out: int
506
-
a Python ``int`` object representing the single element of the array instance.
517
+
out: Union[int, bool]
518
+
a Python object representing the single element of the array instance. If ``self`` has an integer data type, ``out`` must be a Python ``int`` object. If ``self`` has a boolean data type, ``out`` must be a Python ``bool`` object.
507
519
"""
508
520
509
521
def__int__(self: array, /) ->int:
510
522
"""
511
-
Converts a zero-dimensional integer array to a Python ``int`` object.
523
+
Converts a zero-dimensional array to a Python ``int`` object.
524
+
525
+
.. note::
526
+
Casting floating-point values outside the representable bounds of Python's non-arbitary integer type is not specified and is implementation-dependent.
527
+
528
+
.. note::
529
+
When casting a boolean input array, a value of ``True`` must cast to ``1``, and a value of ``False`` must cast to ``0``.
530
+
531
+
**Special cases**
532
+
533
+
For floating-point operands,
534
+
535
+
- If ``self`` is a finite number, the result is the integer part of ``self``.
512
536
513
537
Parameters
514
538
----------
515
539
self: array
516
-
zero-dimensional array instance. Should have an integer data type.
540
+
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``.
517
541
518
542
Returns
519
543
-------
520
544
out: int
521
545
a Python ``int`` object representing the single element of the array instance.
546
+
547
+
548
+
**Raises**
549
+
550
+
For floating-point operands,
551
+
552
+
- If ``self`` is either ``+infinity`` or ``-infinity``, raise ``OverflowError``.
0 commit comments