From 3a1fa0e4c70a6c3f7eb0756ff1b3c764415e80d4 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Thu, 12 Dec 2024 03:12:06 -0800 Subject: [PATCH] feat: add support for scalars in `result_type` Closes: https://github.com/data-apis/array-api/issues/805 --- .../_draft/data_type_functions.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/array_api_stubs/_draft/data_type_functions.py b/src/array_api_stubs/_draft/data_type_functions.py index e12d349c6..f953f0596 100644 --- a/src/array_api_stubs/_draft/data_type_functions.py +++ b/src/array_api_stubs/_draft/data_type_functions.py @@ -209,20 +209,25 @@ def isdtype( """ -def result_type(*arrays_and_dtypes: Union[array, dtype]) -> dtype: +def result_type( + *arrays_and_dtypes: Union[array, int, float, complex, bool, dtype] +) -> dtype: """ - Returns the dtype that results from applying the type promotion rules (see :ref:`type-promotion`) to the arguments. - - .. note:: - If provided mixed dtypes (e.g., integer and floating-point), the returned dtype will be implementation-specific. + Returns the dtype that results from applying type promotion rules (see :ref:`type-promotion`) to the arguments. Parameters ---------- - arrays_and_dtypes: Union[array, dtype] - an arbitrary number of input arrays and/or dtypes. + arrays_and_dtypes: Union[array, int, float, complex, bool, dtype] + an arbitrary number of input arrays, scalars, and/or dtypes. Returns ------- out: dtype - the dtype resulting from an operation involving the input arrays and dtypes. + the dtype resulting from an operation involving the input arrays, scalars, and/or dtypes. + + Notes + ----- + + - At least one argument must be an array or a dtype. + - If provided array and/or dtype arguments having mixed data type kinds (e.g., integer and floating-point), the returned dtype is unspecified and is implementation-dependent. """