From 0dd904529b796bf089af645cc9c4d3feebc73b28 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 15 Feb 2021 15:51:00 -0700 Subject: [PATCH 1/4] Add __int__, __float__, and __bool__ to the array object These are only required for dimension-0 arrays of a matching dtype. --- spec/API_specification/array_object.md | 54 +++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md index a187ed8e1..d2095b3b6 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -274,7 +274,7 @@ Transpose of the array. 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). #### Special Cases - + For floating-point operands, - If `x_i` is `NaN`, the result is `NaN`. @@ -377,6 +377,23 @@ Evaluates `x1_i & x2_i` for each element `x1_i` of an array instance `x1` with t Element-wise results must equal the results returned by the equivalent element-wise function [`bitwise_and(x1, x2)`](elementwise_functions.md#logical_andx1-x2-). ``` +(method-__bool__)= +### \_\_int\_\_(x, /) + +Converts a dimension-0 integer array into a Python `bool` object. + +#### Parameters + +- **x**: _<array>_ + + - dimension 0 array. Must have boolean data type. + +#### Returns + +- **out**: _<int>_ + + - a Python `bool` object representing the single element of the array `x`. + (method-__eq__)= ### \_\_eq\_\_(x1, x2, /) @@ -403,6 +420,23 @@ Computes the truth value of `x1_i == x2_i` for each element `x1_i` of an array i Element-wise results must equal the results returned by the equivalent element-wise function [`equal(x1, x2)`](elementwise_functions.md#equalx1-x2-). ``` +(method-__float__)= +### \_\_int\_\_(x, /) + +Converts a dimension-0 integer array into a Python `float` object. + +#### Parameters + +- **x**: _<array>_ + + - dimension 0 array. Must have an floating-point data type. + +#### Returns + +- **out**: _<float>_ + + - a Python `float` object representing the single element of the array `x`. + (method-__floordiv__)= ### \_\_floordiv\_\_(x1, x2, /) @@ -486,6 +520,24 @@ Computes the truth value of `x1_i > x2_i` for each element `x1_i` of an array in Element-wise results must equal the results returned by the equivalent element-wise function [`greater(x1, x2)`](elementwise_functions.md#greaterx1-x2-). ``` +(method-__int__)= +### \_\_int\_\_(x, /) + +Converts a dimension-0 integer array into a Python `int` object. + +#### Parameters + +- **x**: _<array>_ + + - dimension 0 array. Must have an integer data type. + +#### Returns + +- **out**: _<int>_ + + - a Python `int` object representing the single element of the array `x`. + + (method-__invert__)= ### \_\_invert\_\_(x, /) From 4577f759a5f4bdf0a3389bc4f800a1b09df892e4 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 15 Feb 2021 15:53:15 -0700 Subject: [PATCH 2/4] Fix typo --- spec/API_specification/array_object.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md index d2095b3b6..6dd21fc54 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -390,7 +390,7 @@ Converts a dimension-0 integer array into a Python `bool` object. #### Returns -- **out**: _<int>_ +- **out**: _<bool>_ - a Python `bool` object representing the single element of the array `x`. From 4e83e450ec8b0d1d179d42295411ae3758e91d84 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Mon, 15 Feb 2021 15:53:43 -0700 Subject: [PATCH 3/4] Fix typos --- spec/API_specification/array_object.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md index 6dd21fc54..647d361e6 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -380,7 +380,7 @@ Element-wise results must equal the results returned by the equivalent element-w (method-__bool__)= ### \_\_int\_\_(x, /) -Converts a dimension-0 integer array into a Python `bool` object. +Converts a dimension-0 boolean array into a Python `bool` object. #### Parameters @@ -423,7 +423,7 @@ Element-wise results must equal the results returned by the equivalent element-w (method-__float__)= ### \_\_int\_\_(x, /) -Converts a dimension-0 integer array into a Python `float` object. +Converts a dimension-0 floating-point array into a Python `float` object. #### Parameters From 889ef21d2c0e2298197081fd4e491b9088c2b6f2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 18 Feb 2021 11:03:47 -0700 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Athan --- spec/API_specification/array_object.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md index 647d361e6..efa510673 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -378,15 +378,15 @@ Element-wise results must equal the results returned by the equivalent element-w ``` (method-__bool__)= -### \_\_int\_\_(x, /) +### \_\_bool\_\_(x, /) -Converts a dimension-0 boolean array into a Python `bool` object. +Converts a zero-dimensional boolean array to a Python `bool` object. #### Parameters - **x**: _<array>_ - - dimension 0 array. Must have boolean data type. + - zero-dimensional array instance. Must have a boolean data type. #### Returns @@ -421,15 +421,15 @@ Element-wise results must equal the results returned by the equivalent element-w ``` (method-__float__)= -### \_\_int\_\_(x, /) +### \_\_float\_\_(x, /) -Converts a dimension-0 floating-point array into a Python `float` object. +Converts a zero-dimensional floating-point array to a Python `float` object. #### Parameters - **x**: _<array>_ - - dimension 0 array. Must have an floating-point data type. + - zero-dimensional array instance. Must have a floating-point data type. #### Returns @@ -523,13 +523,13 @@ Element-wise results must equal the results returned by the equivalent element-w (method-__int__)= ### \_\_int\_\_(x, /) -Converts a dimension-0 integer array into a Python `int` object. +Converts a zero-dimensional integer array to a Python `int` object. #### Parameters - **x**: _<array>_ - - dimension 0 array. Must have an integer data type. + - zero-dimensional array instance. Must have an integer data type. #### Returns @@ -537,7 +537,6 @@ Converts a dimension-0 integer array into a Python `int` object. - a Python `int` object representing the single element of the array `x`. - (method-__invert__)= ### \_\_invert\_\_(x, /)