Skip to content

Commit 725527d

Browse files
committed
Test choose with non-overlapping out and choose with invalid choice object
1 parent f2da70a commit 725527d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

dpnp/tests/test_indexing.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,19 @@ def test_choose_0d_inputs(self):
15151515
r = dpnp.choose(inds, [chc])
15161516
assert r == chc
15171517

1518+
def test_choose_out_keyword(self):
1519+
inds = dpnp.tile(dpnp.array([0, 1, 2], dtype="i4"), (5, 3))
1520+
inds_np = dpnp.asnumpy(inds)
1521+
chc1 = dpnp.zeros(9, dtype="f4")
1522+
chc2 = dpnp.ones(9, dtype="f4")
1523+
chc3 = dpnp.full(9, 2, dtype="f4")
1524+
chcs = [chc1, chc2, chc3]
1525+
chcs_np = [dpnp.asnumpy(chc) for chc in chcs]
1526+
out = dpnp.empty_like(inds, dtype="f4")
1527+
dpnp.choose(inds, chcs, out=out)
1528+
expected = numpy.choose(inds_np, chcs_np)
1529+
assert_array_equal(out, expected)
1530+
15181531
def test_choose_in_overlaps_out(self):
15191532
# overlap with inds
15201533
inds = dpnp.zeros(6, dtype="i4")
@@ -1574,8 +1587,10 @@ def test_choose_modes(self, indices, mode):
15741587
assert_array_equal(expected, result)
15751588

15761589
def test_choose_arg_validation(self):
1590+
# invalid choices
15771591
with pytest.raises(TypeError):
1578-
dpnp.choose(dpnp.zeros(()), 1)
1592+
dpnp.choose(dpnp.zeros((), dtype="i4"), 1)
1593+
# invalid mode keyword
15791594
with pytest.raises(ValueError):
15801595
dpnp.choose(dpnp.zeros(()), dpnp.ones(()), mode="err")
15811596

0 commit comments

Comments
 (0)