Skip to content

Fix some issues #181

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 2 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions array_api_tests/test_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def make_param(method_name: str, dtype: DataType, stype: ScalarType) -> Param:
@pytest.mark.parametrize(
"method_name, dtype, stype",
[make_param("__bool__", xp.bool, bool)]
+ [make_param("__int__", d, int) for d in dh.all_int_dtypes]
+ [make_param("__index__", d, int) for d in dh.all_int_dtypes]
+ [make_param("__int__", d, int) for d in dh._filter_stubs(*dh.all_int_dtypes)]
+ [make_param("__index__", d, int) for d in dh._filter_stubs(*dh.all_int_dtypes)]
Copy link
Member Author

Choose a reason for hiding this comment

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

Let me know if there's a better way to do this. I'm not sure if this internal function is supposed to be used outside of the dtype_helpers module. I'm a little unclear why all_int_dtype isn't just filtered to begin with?

Copy link
Member

Choose a reason for hiding this comment

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

Alternative approach which skips undefined stubs

def test_scalar_casting(method_name, dtype, stype, data):
+    if isinstance(dtype, xp._UndefinedStub):
+        pytest.skip(f"{dtype} not in xp namespace")

I could go either way with this. I like the idea of having the test case for uint{16,32,64} just exist as it is expected behaviour in the spec afterall, but I also get its noisy.

I'm a little unclear why all_int_dtype isn't just filtered to begin with?

IIRC it's for the above reason, so it exists for such test cases and we can subsequently skip. Again, could go either way on that now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah skipping is probably better.

+ [make_param("__float__", d, float) for d in dh.float_dtypes],
)
@given(data=st.data())
Expand Down
2 changes: 1 addition & 1 deletion array_api_tests/test_data_type_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_finfo(dtype):
# TODO: test values


@pytest.mark.parametrize("dtype", dh.all_int_dtypes, ids=make_dtype_id)
@pytest.mark.parametrize("dtype", dh._filter_stubs(*dh.all_int_dtypes), ids=make_dtype_id)
def test_iinfo(dtype):
out = xp.iinfo(dtype)
f_func = f"[iinfo({dh.dtype_to_name[dtype]})]"
Expand Down
22 changes: 12 additions & 10 deletions array_api_tests/test_indexing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ def test_take(x, data):

out = xp.take(x, indices, axis=axis)

ph.assert_dtype("take", x.dtype, out.dtype)
ph.assert_dtype("take", in_dtype=x.dtype, out_dtype=out.dtype)
ph.assert_shape(
"take",
out.shape,
x.shape[:axis] + (len(_indices),) + x.shape[axis + 1 :],
x=x,
indices=indices,
axis=axis,
out_shape=out.shape,
expected=x.shape[:axis] + (len(_indices),) + x.shape[axis + 1 :],
kw=dict(
x=x,
indices=indices,
axis=axis,
),
)
out_indices = sh.ndindex(out.shape)
axis_indices = list(sh.axis_ndindex(x.shape, axis))
Expand All @@ -52,10 +54,10 @@ def test_take(x, data):
out_idx = next(out_indices)
ph.assert_0d_equals(
"take",
sh.fmt_idx(f_take_idx, at_idx),
indexed_x[at_idx],
sh.fmt_idx("out", out_idx),
out[out_idx],
x_repr=sh.fmt_idx(f_take_idx, at_idx),
x_val=indexed_x[at_idx],
out_repr=sh.fmt_idx("out", out_idx),
out_val=out[out_idx],
)
# sanity check
with pytest.raises(StopIteration):
Expand Down