Skip to content

Commit 6f05d36

Browse files
committed
Test special cased empty array behaviour
1 parent a945ca4 commit 6f05d36

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

array_api_tests/test_special_cases.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,28 @@ def test_iop(iop_name, iop, case, oneway_dtypes, oneway_shapes, data):
13381338
assume(good_example)
13391339

13401340

1341+
@pytest.mark.parametrize(
1342+
"func_name, expected",
1343+
[
1344+
("mean", float("nan")),
1345+
("prod", 1),
1346+
("std", float("nan")),
1347+
("sum", 0),
1348+
("var", float("nan")),
1349+
],
1350+
ids=["mean", "prod", "std", "sum", "var"],
1351+
)
1352+
def test_empty_arrays(func_name, expected): # TODO: parse docstrings to get expected
1353+
func = getattr(xp, func_name)
1354+
out = func(xp.asarray([], dtype=dh.default_float))
1355+
ph.assert_shape(func_name, out.shape, ()) # sanity check
1356+
msg = f"{out=!r}, but should be {expected}"
1357+
if math.isnan(expected):
1358+
assert xp.isnan(out), msg
1359+
else:
1360+
assert out == expected, msg
1361+
1362+
13411363
@pytest.mark.parametrize(
13421364
"func_name", [f.__name__ for f in category_to_funcs["statistical"]]
13431365
)

0 commit comments

Comments
 (0)