Skip to content

Commit ed19a40

Browse files
authored
Add __int__, __float__, and __bool__ to the array object (#127)
1 parent e2474ce commit ed19a40

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

spec/API_specification/array_object.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Transpose of the array.
274274
Calculates the absolute value for each element `x_i` of an array instance `x` (i.e., the element-wise result has the same magnitude as the respective element in `x` but has positive sign).
275275

276276
#### Special Cases
277-
277+
278278
For floating-point operands,
279279

280280
- If `x_i` is `NaN`, the result is `NaN`.
@@ -377,6 +377,24 @@ Evaluates `x1_i & x2_i` for each element `x1_i` of an array instance `x1` with t
377377
Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#logical_andx1-x2-).
378378
```
379379

380+
(method-__bool__)=
381+
### \_\_bool\_\_(x, /)
382+
383+
Converts a zero-dimensional boolean array to a Python `bool` object.
384+
385+
#### Parameters
386+
387+
- **x**: _<array>_
388+
389+
- zero-dimensional array instance. Must have a boolean data type.
390+
391+
#### Returns
392+
393+
- **out**: _<bool>_
394+
395+
- a Python `bool` object representing the single element of the array `x`.
396+
397+
380398
(method-__dlpack__)=
381399
### \_\_dlpack\_\_(/, *, stream=None)
382400

@@ -419,6 +437,7 @@ Exports the array as a DLPack capsule, for consumption by {ref}`function-from_dl
419437
420438
- A DLPack capsule for the array. See {ref}`data-interchange` for details.
421439
440+
422441
(method-__dlpack_device__)=
423442
### \_\_dlpack\_device\_\_()
424443
@@ -467,6 +486,23 @@ Computes the truth value of `x1_i == x2_i` for each element `x1_i` of an array i
467486
Element-wise results must equal the results returned by the equivalent element-wise function [`equal(x1, x2)`](elementwise_functions.md#equalx1-x2-).
468487
```
469488

489+
(method-__float__)=
490+
### \_\_float\_\_(x, /)
491+
492+
Converts a zero-dimensional floating-point array to a Python `float` object.
493+
494+
#### Parameters
495+
496+
- **x**: _<array>_
497+
498+
- zero-dimensional array instance. Must have a floating-point data type.
499+
500+
#### Returns
501+
502+
- **out**: _<float>_
503+
504+
- a Python `float` object representing the single element of the array `x`.
505+
470506
(method-__floordiv__)=
471507
### \_\_floordiv\_\_(x1, x2, /)
472508

@@ -550,6 +586,23 @@ Computes the truth value of `x1_i > x2_i` for each element `x1_i` of an array in
550586
Element-wise results must equal the results returned by the equivalent element-wise function [`greater(x1, x2)`](elementwise_functions.md#greaterx1-x2-).
551587
```
552588

589+
(method-__int__)=
590+
### \_\_int\_\_(x, /)
591+
592+
Converts a zero-dimensional integer array to a Python `int` object.
593+
594+
#### Parameters
595+
596+
- **x**: _<array>_
597+
598+
- zero-dimensional array instance. Must have an integer data type.
599+
600+
#### Returns
601+
602+
- **out**: _<int>_
603+
604+
- a Python `int` object representing the single element of the array `x`.
605+
553606
(method-__invert__)=
554607
### \_\_invert\_\_(x, /)
555608

0 commit comments

Comments
 (0)