Skip to content

feat: add support for scalars in result_type #873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/array_api_stubs/_draft/data_type_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Loading