From 5032ce141f12f6e0ab326a3fb6ea24e8ea3097ec Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 5 Dec 2022 01:44:58 -0800 Subject: [PATCH 1/2] Update copy and add TODO --- spec/API_specification/array_api/elementwise_functions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/API_specification/array_api/elementwise_functions.py b/spec/API_specification/array_api/elementwise_functions.py index e76be8d65..0ab01338f 100644 --- a/spec/API_specification/array_api/elementwise_functions.py +++ b/spec/API_specification/array_api/elementwise_functions.py @@ -1356,14 +1356,20 @@ def sign(x: array, /) -> array: **Special cases** + For real-valued operands, + - If ``x_i`` is less than ``0``, the result is ``-1``. - If ``x_i`` is either ``-0`` or ``+0``, the result is ``0``. - If ``x_i`` is greater than ``0``, the result is ``+1``. + For complex floating-point operands, + + TODO + Parameters ---------- x: array - input array. Should have a real-valued data type. + input array. Should have a numeric data type. Returns ------- From 914e33d92314e08a14f9d10a5bc02c0e37afea24 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sun, 11 Dec 2022 23:28:13 -0800 Subject: [PATCH 2/2] Add equations and special cases --- .../array_api/elementwise_functions.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/API_specification/array_api/elementwise_functions.py b/spec/API_specification/array_api/elementwise_functions.py index 0ab01338f..34484162d 100644 --- a/spec/API_specification/array_api/elementwise_functions.py +++ b/spec/API_specification/array_api/elementwise_functions.py @@ -1351,9 +1351,19 @@ def round(x: array, /) -> array: """ def sign(x: array, /) -> array: - """ + r""" Returns an indication of the sign of a number for each element ``x_i`` of the input array ``x``. + The sign function (also known as the **signum function**) of a number :math:`x_i` is defined as + + .. math:: + \operatorname{sign}(x_i) = \begin{cases} + 0 & \textrm{if } x_i = 0 \\ + \frac{x}{|x|} & \textrm{otherwise} + \end{cases} + + where :math:`|x_i|` is the absolute value of :math:`x_i`. + **Special cases** For real-valued operands, @@ -1361,10 +1371,13 @@ def sign(x: array, /) -> array: - If ``x_i`` is less than ``0``, the result is ``-1``. - If ``x_i`` is either ``-0`` or ``+0``, the result is ``0``. - If ``x_i`` is greater than ``0``, the result is ``+1``. + - If ``x_i`` is ``NaN``, the result is ``NaN``. - For complex floating-point operands, + For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and - TODO + - If ``a`` is either ``-0`` or ``+0`` and ``b`` is either ``-0`` or ``+0``, the result is ``0 + 0j``. + - If ``a`` is ``NaN`` or ``b`` is ``NaN``, the result is ``NaN + NaN j``. + - In the remaining cases, special cases must be handled according to the rules of complex number division (see :func:`~array_api.divide`). Parameters ----------