From c508ccd5c1115c51b2a29f95d0cd8777e6fddd25 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 22 May 2022 21:48:19 -0700 Subject: [PATCH 1/2] Add complex number support to `round`, `ceil`, `floor`, and `trunc` --- .../array_api/elementwise_functions.py | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/spec/API_specification/array_api/elementwise_functions.py b/spec/API_specification/array_api/elementwise_functions.py index f72af2089..d6cb370f2 100644 --- a/spec/API_specification/array_api/elementwise_functions.py +++ b/spec/API_specification/array_api/elementwise_functions.py @@ -378,8 +378,16 @@ def ceil(x: array, /) -> array: """ Rounds each element ``x_i`` of the input array ``x`` to the smallest (i.e., closest to ``-infinity``) integer-valued number that is not less than ``x_i``. + .. note:: + For complex floating-point operands, real and imaginary components must be independently rounded to the smallest integer-valued number that is not less than the component value. + + Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued ``x``, ``real(ceil(x))`` must equal ``ceil(real(x)))`` and ``imag(ceil(x))`` must equal ``ceil(imag(x))``). + **Special cases** + .. note:: + For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if ``real(x_i)`` is ``NaN``, the rounded real component is ``NaN``). + - If ``x_i`` is already integer-valued, the result is ``x_i``. For floating-point operands, @@ -393,7 +401,7 @@ def ceil(x: array, /) -> array: Parameters ---------- x: array - input array. Should have a real-valued data type. + input array. Should have a numeric data type. Returns ------- @@ -574,8 +582,16 @@ def floor(x: array, /) -> array: """ Rounds each element ``x_i`` of the input array ``x`` to the greatest (i.e., closest to ``+infinity``) integer-valued number that is not greater than ``x_i``. + .. note:: + For complex floating-point operands, real and imaginary components must be independently rounded to the greatest integer-valued number that is not greater than the component value. + + Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued ``x``, ``real(floor(x))`` must equal ``floor(real(x)))`` and ``imag(floor(x))`` must equal ``floor(imag(x))``). + **Special cases** + .. note:: + For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if ``real(x_i)`` is ``NaN``, the rounded real component is ``NaN``). + - If ``x_i`` is already integer-valued, the result is ``x_i``. For floating-point operands, @@ -589,7 +605,7 @@ def floor(x: array, /) -> array: Parameters ---------- x: array - input array. Should have a real-valued data type. + input array. Should have a numeric data type. Returns ------- @@ -1163,8 +1179,16 @@ def round(x: array, /) -> array: """ Rounds each element ``x_i`` of the input array ``x`` to the nearest integer-valued number. + .. note:: + For complex floating-point operands, real and imaginary components must be independently rounded to the nearest integer-valued number. + + Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued ``x``, ``real(round(x))`` must equal ``round(real(x)))`` and ``imag(round(x))`` must equal ``round(imag(x))``). + **Special cases** + .. note:: + For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if ``real(x_i)`` is ``NaN``, the rounded real component is ``NaN``). + - If ``x_i`` is already integer-valued, the result is ``x_i``. For floating-point operands, @@ -1179,7 +1203,7 @@ def round(x: array, /) -> array: Parameters ---------- x: array - input array. Should have a real-valued data type. + input array. Should have a numeric data type. Returns ------- @@ -1367,8 +1391,16 @@ def trunc(x: array, /) -> array: """ Rounds each element ``x_i`` of the input array ``x`` to the integer-valued number that is closest to but no greater than ``x_i``. + .. note:: + For complex floating-point operands, real and imaginary components must be independently rounded to the integer-valued number that is closest to but no greater than the component value. + + Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued ``x``, ``real(trunc(x))`` must equal ``trunc(real(x)))`` and ``imag(trunc(x))`` must equal ``trunc(imag(x))``). + **Special cases** + .. note:: + For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if ``real(x_i)`` is ``NaN``, the rounded real component is ``NaN``). + - If ``x_i`` is already integer-valued, the result is ``x_i``. For floating-point operands, @@ -1382,7 +1414,7 @@ def trunc(x: array, /) -> array: Parameters ---------- x: array - input array. Should have a real-valued data type. + input array. Should have a numeric data type. Returns ------- From f817ae04a02245677b5a58df6a0440805c578d0f Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 29 May 2022 23:59:32 -0700 Subject: [PATCH 2/2] Remove complex dtype support for `floor`, `ceil`, and `trunc` --- .../array_api/elementwise_functions.py | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/spec/API_specification/array_api/elementwise_functions.py b/spec/API_specification/array_api/elementwise_functions.py index d6cb370f2..c4dabf1d2 100644 --- a/spec/API_specification/array_api/elementwise_functions.py +++ b/spec/API_specification/array_api/elementwise_functions.py @@ -378,16 +378,8 @@ def ceil(x: array, /) -> array: """ Rounds each element ``x_i`` of the input array ``x`` to the smallest (i.e., closest to ``-infinity``) integer-valued number that is not less than ``x_i``. - .. note:: - For complex floating-point operands, real and imaginary components must be independently rounded to the smallest integer-valued number that is not less than the component value. - - Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued ``x``, ``real(ceil(x))`` must equal ``ceil(real(x)))`` and ``imag(ceil(x))`` must equal ``ceil(imag(x))``). - **Special cases** - .. note:: - For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if ``real(x_i)`` is ``NaN``, the rounded real component is ``NaN``). - - If ``x_i`` is already integer-valued, the result is ``x_i``. For floating-point operands, @@ -401,7 +393,7 @@ def ceil(x: array, /) -> array: Parameters ---------- x: array - input array. Should have a numeric data type. + input array. Should have a real-valued data type. Returns ------- @@ -582,16 +574,8 @@ def floor(x: array, /) -> array: """ Rounds each element ``x_i`` of the input array ``x`` to the greatest (i.e., closest to ``+infinity``) integer-valued number that is not greater than ``x_i``. - .. note:: - For complex floating-point operands, real and imaginary components must be independently rounded to the greatest integer-valued number that is not greater than the component value. - - Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued ``x``, ``real(floor(x))`` must equal ``floor(real(x)))`` and ``imag(floor(x))`` must equal ``floor(imag(x))``). - **Special cases** - .. note:: - For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if ``real(x_i)`` is ``NaN``, the rounded real component is ``NaN``). - - If ``x_i`` is already integer-valued, the result is ``x_i``. For floating-point operands, @@ -605,7 +589,7 @@ def floor(x: array, /) -> array: Parameters ---------- x: array - input array. Should have a numeric data type. + input array. Should have a real-valued data type. Returns ------- @@ -1391,16 +1375,8 @@ def trunc(x: array, /) -> array: """ Rounds each element ``x_i`` of the input array ``x`` to the integer-valued number that is closest to but no greater than ``x_i``. - .. note:: - For complex floating-point operands, real and imaginary components must be independently rounded to the integer-valued number that is closest to but no greater than the component value. - - Rounded real and imaginary components must be equal to their equivalent rounded real-valued floating-point counterparts (i.e., for complex-valued ``x``, ``real(trunc(x))`` must equal ``trunc(real(x)))`` and ``imag(trunc(x))`` must equal ``trunc(imag(x))``). - **Special cases** - .. note:: - For complex floating-point operands, the following special cases apply to real and imaginary components independently (e.g., if ``real(x_i)`` is ``NaN``, the rounded real component is ``NaN``). - - If ``x_i`` is already integer-valued, the result is ``x_i``. For floating-point operands, @@ -1414,7 +1390,7 @@ def trunc(x: array, /) -> array: Parameters ---------- x: array - input array. Should have a numeric data type. + input array. Should have a real-valued data type. Returns -------