From be9f4b4c713f7fb703c0aa1c9475e22981da83bd Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 9 Jul 2021 16:08:49 -0600 Subject: [PATCH 1/2] Require __pow__ and __truediv__ to have floating-point inputs Previously it was any numeric dtype, but this was inconsistent with the functions pow() and divide(). Integer inputs are problematic because they would either always have to be cast to float or use value-based casting depending on, e.g., the sign of the exponent for __pow__. Furthermore, in order to properly correspond to Python conventions, __truediv__ should always return a float (integer division should be implemented by __floordiv__). This was discussed in #173. --- spec/API_specification/array_object.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md index 93e806de3..f28cee3af 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -780,7 +780,7 @@ The `matmul` function must implement the same semantics as the built-in `@` oper - **self**: _<array>_ - - array instance. Should have a numeric data type. Must have at least one dimension. If `self` is one-dimensional having shape `(M)` and `other` has more than one dimension, `self` must be promoted to a two-dimensional array by prepending `1` to its dimensions (i.e., must have shape `(1, M)`). After matrix multiplication, the prepended dimensions in the returned array must be removed. If `self` has more than one dimension (including after vector-to-matrix promotion), `self` must be compatible with `other` (see {ref}`broadcasting`). If `self` has shape `(..., M, K)`, the innermost two dimensions form matrices on which to perform matrix multiplication. + - array instance. Should have a numeric data type. Must have at least one dimension. If `self` is one-dimensional having shape `(M)` and `other` has more than one dimension, `self` must be promoted to a two-dimensional array by prepending `1` to its dimensions (i.e., must have shape `(1, M)`). After matrix multiplication, the prepended dimensions in the returned array must be removed. If `self` has more than one dimension (including after vector-to-matrix promotion), `self` must be compatible with `other` (see {ref}`broadcasting`). If `self` has shape `(..., M, K)`, the innermost two dimensions form matrices on which to perform matrix multiplication. - **other**: _<array>_ @@ -809,7 +809,7 @@ The `matmul` function must implement the same semantics as the built-in `@` oper - if either `self` or `other` is a zero-dimensional array. - if `self` is a one-dimensional array having shape `(N)`, `other` is a one-dimensional array having shape `(M)`, and `N != M`. -- if `self` is an array having shape `(..., M, K)`, `other` is an array having shape `(..., L, N)`, and `K != L`. +- if `self` is an array having shape `(..., M, K)`, `other` is an array having shape `(..., L, N)`, and `K != L`. (method-__mod__)= ### \_\_mod\_\_(self, other, /) @@ -1016,11 +1016,11 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`. - **self**: _<array>_ - - array instance whose elements correspond to the exponentiation base. Should have a numeric data type. + - array instance whose elements correspond to the exponentiation base. Should have a floating-point data type. - **other**: _Union\[ int, float, <array> ]_ - - other array whose elements correspond to the exponentiation exponent. Must be compatible with `self` (see {ref}`broadcasting`). Should have a numeric data type. + - other array whose elements correspond to the exponentiation exponent. Must be compatible with `self` (see {ref}`broadcasting`). Should have a floating-point data type. #### Returns @@ -1149,11 +1149,11 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`. - **self**: _<array>_ - - array instance. Should have a numeric data type. + - array instance. Should have a floating-point data type. - **other**: _Union\[ int, float, <array> ]_ - - other array. Must be compatible with `self` (see {ref}`broadcasting`). Should have a numeric data type. + - other array. Must be compatible with `self` (see {ref}`broadcasting`). Should have a floating-point data type. #### Returns From 2330a6dde06ca224fd0e5980a3dcdf1a81bd3efe Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Fri, 9 Jul 2021 16:26:32 -0600 Subject: [PATCH 2/2] Update the type signatures for __pow__ and __truediv__ --- 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 f28cee3af..9754414f1 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -1018,7 +1018,7 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`. - array instance whose elements correspond to the exponentiation base. Should have a floating-point data type. -- **other**: _Union\[ int, float, <array> ]_ +- **other**: _Union\[ float, <array> ]_ - other array whose elements correspond to the exponentiation exponent. Must be compatible with `self` (see {ref}`broadcasting`). Should have a floating-point data type. @@ -1151,7 +1151,7 @@ For floating-point operands, let `self` equal `x1` and `other` equal `x2`. - array instance. Should have a floating-point data type. -- **other**: _Union\[ int, float, <array> ]_ +- **other**: _Union\[ float, <array> ]_ - other array. Must be compatible with `self` (see {ref}`broadcasting`). Should have a floating-point data type.