Skip to content

Commit

Permalink
Test choose with non-overlapping out and choose with invalid choice o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
ndgrigorian committed Dec 11, 2024
1 parent 12f4ccf commit 70a85c3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion dpnp/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,19 @@ def test_choose_0d_inputs(self):
r = dpnp.choose(inds, [chc])
assert r == chc

def test_choose_out_keyword(self):
inds = dpnp.tile(dpnp.array([0, 1, 2], dtype="i4"), (5, 3))
inds_np = dpnp.asnumpy(inds)
chc1 = dpnp.zeros(9, dtype="f4")
chc2 = dpnp.ones(9, dtype="f4")
chc3 = dpnp.full(9, 2, dtype="f4")
chcs = [chc1, chc2, chc3]
chcs_np = [dpnp.asnumpy(chc) for chc in chcs]
out = dpnp.empty_like(inds, dtype="f4")
dpnp.choose(inds, chcs, out=out)
expected = numpy.choose(inds_np, chcs_np)
assert_array_equal(out, expected)

def test_choose_in_overlaps_out(self):
# overlap with inds
inds = dpnp.zeros(6, dtype="i4")
Expand Down Expand Up @@ -1568,8 +1581,10 @@ def test_choose_modes(self, indices, mode):
assert_array_equal(expected, result)

def test_choose_arg_validation(self):
# invalid choices
with pytest.raises(TypeError):
dpnp.choose(dpnp.zeros(()), 1)
dpnp.choose(dpnp.zeros((), dtype="i4"), 1)
# invalid mode keyword
with pytest.raises(ValueError):
dpnp.choose(dpnp.zeros(()), dpnp.ones(()), mode="err")

Expand Down

0 comments on commit 70a85c3

Please sign in to comment.