Skip to content

Commit 247a8e4

Browse files
committed
BUG: work around some names not available in 2022.12
Case in point: np.hypot is only available in 2023.12, and has gotten the support for scalars in 2024.12. The test for scalars is skipped for versions older than 2024.12, but the test parametrization is evaluated _before_ the skip. Therefore we cannot just use `xp.hypot` in `@parametrize`.
1 parent 88b92a0 commit 247a8e4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

array_api_tests/test_operators_and_elementwise_functions.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,19 +1794,26 @@ def _check_binary_with_scalars(func_data, x1x2):
17941794
def _filter_zero(x):
17951795
return x != 0 if dh.is_scalar(x) else (not xp.any(x == 0))
17961796

1797+
# workarounds for xp.copysign etc only available in 2023.12
1798+
# Without it, test suite fails to import with ARRAY_API_VERSION=2022.12
1799+
_xp_copysign = getattr(xp, "copysign", None)
1800+
_xp_hypot = getattr(xp, "hypot", None)
1801+
_xp_maximum = getattr(xp, "maximum", None)
1802+
_xp_minimum = getattr(xp, "minimum", None)
1803+
17971804

17981805
@pytest.mark.min_version("2024.12")
17991806
@pytest.mark.parametrize('func_data',
18001807
# xp_func, name, refimpl, kwargs, expected_dtype
18011808
[
18021809
(xp.add, "add", operator.add, {}, None),
18031810
(xp.atan2, "atan2", math.atan2, {}, None),
1804-
(xp.copysign, "copysign", math.copysign, {}, None),
1811+
(_xp_copysign, "copysign", math.copysign, {}, None),
18051812
(xp.divide, "divide", operator.truediv, {"filter_": lambda s: s != 0}, None),
1806-
(xp.hypot, "hypot", math.hypot, {}, None),
1813+
(_xp_hypot, "hypot", math.hypot, {}, None),
18071814
(xp.logaddexp, "logaddexp", logaddexp_refimpl, {}, None),
1808-
(xp.maximum, "maximum", max, {'strict_check': True}, None),
1809-
(xp.minimum, "minimum", min, {'strict_check': True}, None),
1815+
(_xp_maximum, "maximum", max, {'strict_check': True}, None),
1816+
(_xp_minimum, "minimum", min, {'strict_check': True}, None),
18101817
(xp.multiply, "mul", operator.mul, {}, None),
18111818
(xp.subtract, "sub", operator.sub, {}, None),
18121819

0 commit comments

Comments
 (0)