Skip to content
New issue

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

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

Already on GitHub? # to your account

Add support for scalar arguments to xp.where #78

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

betatim
Copy link
Member

@betatim betatim commented Oct 31, 2024

This is related to data-apis/array-api#807

This only adds support for scalars to where(). If the second or third argument is a scalar it is turned into an array on the same device as condition.

I added 2024.12 as next_supported_version. This means we can use it in the tests. Not sure if we use some kind of dummy value instead of 2024.12?

@asmeurer
Copy link
Member

asmeurer commented Nov 5, 2024

Some of this overlaps with the stuff I've done over at #82, although I haven't implemented any scalar stuff there yet because it isn't in the standard yet.

Copy link
Contributor

@ev-br ev-br left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd think it should allow complex x1 and x2, too. Here and in the annotation.

LGTM otherwise!

"""
Array API compatible wrapper for :py:func:`np.where <numpy.where>`.

See its docstring for more information.
"""
if get_array_api_strict_flags()['api_version'] > '2023.12':
if isinstance(x1, (bool, float, int)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isinstance(x1, (bool, float, int)):
if isinstance(x1, (bool, float, complex, int)):

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants