From dcaf1934ed9ccfd4e17efe8a8260962380264093 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Thu, 9 Jan 2025 01:00:05 -0800 Subject: [PATCH 1/2] docs: clarify type promotion behavior in `diff` Closes: https://github.com/data-apis/array-api/issues/852 --- src/array_api_stubs/_draft/utility_functions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/array_api_stubs/_draft/utility_functions.py b/src/array_api_stubs/_draft/utility_functions.py index cdbe4a0f8..494981fb6 100644 --- a/src/array_api_stubs/_draft/utility_functions.py +++ b/src/array_api_stubs/_draft/utility_functions.py @@ -125,4 +125,5 @@ def diff( ----- - The first-order differences are given by ``out[i] = x[i+1] - x[i]`` along a specified axis. Higher-order differences must be calculated recursively (e.g., by calling ``diff(out, axis=axis, n=n-1)``). + - If a conforming implementation chooses to support ``prepend`` and ``append`` arrays which have a different data type than ``x``, the ``prepend`` and ``append`` arrays should promote to the same data type as ``x`` (see :ref:`type-promotion`). If ``prepend`` and ``append`` do not promote to the same data type as ``x`` or are of a different data type "kind" (integer, real-valued floating-point, or complex floating-point), behavior is unspecified and thus implementation-defined. """ From e09b14e09af42a2399df54dc3a9406cf7be93d7e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Thu, 9 Jan 2025 01:09:34 -0800 Subject: [PATCH 2/2] refactor: loosen restrictions to allow type promotion (ala NumPy) --- src/array_api_stubs/_draft/utility_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array_api_stubs/_draft/utility_functions.py b/src/array_api_stubs/_draft/utility_functions.py index 494981fb6..7a234efbb 100644 --- a/src/array_api_stubs/_draft/utility_functions.py +++ b/src/array_api_stubs/_draft/utility_functions.py @@ -125,5 +125,5 @@ def diff( ----- - The first-order differences are given by ``out[i] = x[i+1] - x[i]`` along a specified axis. Higher-order differences must be calculated recursively (e.g., by calling ``diff(out, axis=axis, n=n-1)``). - - If a conforming implementation chooses to support ``prepend`` and ``append`` arrays which have a different data type than ``x``, the ``prepend`` and ``append`` arrays should promote to the same data type as ``x`` (see :ref:`type-promotion`). If ``prepend`` and ``append`` do not promote to the same data type as ``x`` or are of a different data type "kind" (integer, real-valued floating-point, or complex floating-point), behavior is unspecified and thus implementation-defined. + - If a conforming implementation chooses to support ``prepend`` and ``append`` arrays which have a different data type than ``x``, behavior is unspecified and thus implementation-defined. Implementations may choose to type promote (:ref:`type-promotion`), cast ``prepend`` and/or ``append`` to the same data type as ``x``, or raise an exception. """