-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for scalar arguments to xp.where
- Loading branch information
Showing
2 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
|
||
import array_api_strict as xp | ||
|
||
from array_api_strict import ArrayAPIStrictFlags | ||
from array_api_strict._flags import next_supported_version | ||
|
||
|
||
def test_where_with_scalars(): | ||
x = xp.asarray([1, 2, 3, 1]) | ||
|
||
# Versions up to and including 2023.12 don't support scalar arguments | ||
with pytest.raises(AttributeError, match="object has no attribute 'dtype'"): | ||
xp.where(x == 1, 42, 44) | ||
|
||
# Versions after 2023.12 support scalar arguments | ||
with ArrayAPIStrictFlags(api_version=next_supported_version): | ||
x_where = xp.where(x == 1, 42, 44) | ||
|
||
expected = xp.asarray([42, 44, 44, 42]) | ||
assert xp.all(x_where == expected) |