-
Notifications
You must be signed in to change notification settings - Fork 9
ENH: unary functions overhaul; better input validation #148
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
base: main
Are you sure you want to change the base?
Conversation
@@ -168,9 +231,6 @@ def _array_vals(): | |||
for d in _floating_dtypes: | |||
yield asarray(1.0, dtype=d) | |||
|
|||
# Use the latest version of the standard so all functions are included | |||
set_array_api_strict_flags(api_version="2024.12") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant with auto-applied fixture
@pytest.mark.parametrize("func_name", elementwise_function_input_types) | ||
def test_elementwise_function_vs_numpy_generics(func_name): | ||
""" | ||
Test that NumPy generics are explicitly disallowed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, trivial: instances of np.generic
are typically referred to as numpy scalars. The fact that the type name is np.generic
is... not very well known (for the better IMO). Anyway, this is not worth flushing the CI for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Let keep this PR open for a while though, in case somebody has opinions on generating unary functions from a decorator. I personally think this is a good change, but there were concerns in #100
|
||
_ = func(a, a) | ||
with pytest.raises(TypeError, match="neither Array nor Python scalars"): | ||
func(a, b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to be really thorough, can add also test func(b, a)
: unlike #103, functions we control.
res = xp.where(cond, 1, x2) | ||
assert res.device == device | ||
res = xp.where(cond, x1, 2) | ||
assert res.device == device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the following tests are great. I imaging we'll want to parrot them in array-api-tests at some point.
xref #145
clip
, andwhere
where
is not an Arrayclip
, andwhere
where