Skip to content

Commit a51968f

Browse files
committed
Add a test to ufuncs scope to validate the behavior
1 parent 47af401 commit a51968f

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

dpnp/tests/test_mathematical.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,22 +2009,32 @@ def test_out_dtype(self, func):
20092009
):
20102010
fn(*args, out=out, dtype="f4")
20112011

2012+
@pytest.mark.parametrize("xp", [numpy, dpnp])
2013+
@pytest.mark.parametrize("func", ["abs", "add", "frexp"])
2014+
def test_out_wrong_tuple_len(self, xp, func):
2015+
x = xp.array([1, 2, 3])
2016+
2017+
fn = getattr(xp, func)
2018+
args = [x] * fn.nin
2019+
2020+
nout = fn.nout
2021+
outs = [(), tuple(range(nout + 1))]
2022+
if nout > 1:
2023+
outs.append(tuple(range(nout - 1)))
2024+
2025+
for out in outs:
2026+
with pytest.raises(
2027+
ValueError,
2028+
match="'out' tuple must have exactly one entry per ufunc output",
2029+
):
2030+
_ = fn(*args, out=out)
2031+
20122032
@pytest.mark.parametrize("xp", [numpy, dpnp])
20132033
def test_unary_two_outs_out_ndarray(self, xp):
20142034
x = xp.array(0.5)
20152035
with pytest.raises(TypeError, match="'out' must be a tuple of arrays"):
20162036
_ = xp.frexp(x, out=xp.empty(()))
20172037

2018-
@pytest.mark.parametrize("xp", [numpy, dpnp])
2019-
@pytest.mark.parametrize("out", [(), (1,), (1, 2, 3)])
2020-
def test_unary_two_outs_out_wrong_tuple_len(self, xp, out):
2021-
x = xp.array(0.5)
2022-
with pytest.raises(
2023-
ValueError,
2024-
match="'out' tuple must have exactly one entry per ufunc output",
2025-
):
2026-
_ = xp.frexp(x, out=out)
2027-
20282038
@pytest.mark.parametrize("xp", [numpy, dpnp])
20292039
def test_unary_two_outs_out_mixed(self, xp):
20302040
x = xp.array(0.5)

0 commit comments

Comments
 (0)