Skip to content

MAINT: simplify API version guards #327

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
Dec 28, 2024
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
44 changes: 21 additions & 23 deletions array_api_tests/test_operators_and_elementwise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,14 +1061,13 @@ def refimpl(_x, _min, _max):
)


if api_version >= "2022.12":

@given(hh.arrays(dtype=hh.complex_dtypes, shape=hh.shapes()))
def test_conj(x):
out = xp.conj(x)
ph.assert_dtype("conj", in_dtype=x.dtype, out_dtype=out.dtype)
ph.assert_shape("conj", out_shape=out.shape, expected=x.shape)
unary_assert_against_refimpl("conj", x, out, operator.methodcaller("conjugate"))
@pytest.mark.min_version("2022.12")
@given(hh.arrays(dtype=hh.complex_dtypes, shape=hh.shapes()))
def test_conj(x):
out = xp.conj(x)
ph.assert_dtype("conj", in_dtype=x.dtype, out_dtype=out.dtype)
ph.assert_shape("conj", out_shape=out.shape, expected=x.shape)
unary_assert_against_refimpl("conj", x, out, operator.methodcaller("conjugate"))


@pytest.mark.min_version("2023.12")
Expand Down Expand Up @@ -1263,14 +1262,14 @@ def test_hypot(x1, x2):
binary_assert_against_refimpl("hypot", x1, x2, out, math.hypot)


if api_version >= "2022.12":

@given(hh.arrays(dtype=hh.complex_dtypes, shape=hh.shapes()))
def test_imag(x):
out = xp.imag(x)
ph.assert_dtype("imag", in_dtype=x.dtype, out_dtype=out.dtype, expected=dh.dtype_components[x.dtype])
ph.assert_shape("imag", out_shape=out.shape, expected=x.shape)
unary_assert_against_refimpl("imag", x, out, operator.attrgetter("imag"))
@pytest.mark.min_version("2022.12")
@given(hh.arrays(dtype=hh.complex_dtypes, shape=hh.shapes()))
def test_imag(x):
out = xp.imag(x)
ph.assert_dtype("imag", in_dtype=x.dtype, out_dtype=out.dtype, expected=dh.dtype_components[x.dtype])
ph.assert_shape("imag", out_shape=out.shape, expected=x.shape)
unary_assert_against_refimpl("imag", x, out, operator.attrgetter("imag"))


@given(hh.arrays(dtype=hh.numeric_dtypes, shape=hh.shapes()))
Expand Down Expand Up @@ -1559,14 +1558,13 @@ def test_pow(ctx, data):
# Values testing pow is too finicky


if api_version >= "2022.12":

@given(hh.arrays(dtype=hh.complex_dtypes, shape=hh.shapes()))
def test_real(x):
out = xp.real(x)
ph.assert_dtype("real", in_dtype=x.dtype, out_dtype=out.dtype, expected=dh.dtype_components[x.dtype])
ph.assert_shape("real", out_shape=out.shape, expected=x.shape)
unary_assert_against_refimpl("real", x, out, operator.attrgetter("real"))
@pytest.mark.min_version("2022.12")
@given(hh.arrays(dtype=hh.complex_dtypes, shape=hh.shapes()))
def test_real(x):
out = xp.real(x)
ph.assert_dtype("real", in_dtype=x.dtype, out_dtype=out.dtype, expected=dh.dtype_components[x.dtype])
ph.assert_shape("real", out_shape=out.shape, expected=x.shape)
unary_assert_against_refimpl("real", x, out, operator.attrgetter("real"))


@pytest.mark.skip(reason="flaky")
Expand Down
Loading