Skip to content

Commit 584d141

Browse files
committed
Add testing
1 parent 804a367 commit 584d141

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

dpnp/tests/test_binary_ufuncs.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ def test_inplace_dtype(self, dtype1, dtype2):
8787
with pytest.raises(ValueError):
8888
ia += ib
8989

90+
@pytest.mark.parametrize("dtype1", ALL_DTYPES)
91+
@pytest.mark.parametrize("dtype2", ALL_DTYPES)
92+
def test_inplace_dtype_explicit(self, dtype1, dtype2):
93+
a = numpy.array([[-7, 6, -3, 2, -1], [0, -3, 4, 5, -6]], dtype=dtype1)
94+
b = numpy.array([5, -2, 0, 1, 0], dtype=dtype2)
95+
ia, ib = dpnp.array(a), dpnp.array(b)
96+
97+
if numpy.can_cast(dtype2, dtype1, casting="same_kind"):
98+
result = dpnp.add(ia, ib, out=ia)
99+
expected = numpy.add(a, b, out=a)
100+
assert_dtype_allclose(result, expected)
101+
else:
102+
assert_raises(TypeError, numpy.add, a, b, out=a)
103+
assert_raises(ValueError, dpnp.add, ia, ib, out=ia)
104+
90105
@pytest.mark.parametrize("shape", [(0,), (15,), (2, 2)])
91106
def test_invalid_shape(self, shape):
92107
a, b = dpnp.arange(10), dpnp.arange(10)
@@ -229,6 +244,21 @@ def test_inplace_dtype(self, dtype1, dtype2):
229244
with pytest.raises(ValueError):
230245
ia /= ib
231246

247+
@pytest.mark.parametrize("dtype1", get_all_dtypes(no_none=True))
248+
@pytest.mark.parametrize("dtype2", get_float_complex_dtypes())
249+
def test_inplace_dtype_explicit(self, dtype1, dtype2):
250+
a = numpy.array([[-7, 6, -3, 2, -1], [0, -3, 4, 5, -6]], dtype=dtype1)
251+
b = numpy.array([5, -2, -10, 1, 10], dtype=dtype2)
252+
ia, ib = dpnp.array(a), dpnp.array(b)
253+
254+
if numpy.can_cast(dtype2, dtype1, casting="same_kind"):
255+
result = dpnp.divide(ia, ib, out=ia)
256+
expected = numpy.divide(a, b, out=a)
257+
assert_dtype_allclose(result, expected)
258+
else:
259+
assert_raises(TypeError, numpy.divide, a, b, out=a)
260+
assert_raises(ValueError, dpnp.divide, ia, ib, out=ia)
261+
232262
@pytest.mark.parametrize("shape", [(0,), (15,), (2, 2)])
233263
def test_invalid_shape(self, shape):
234264
a, b = dpnp.arange(10), dpnp.arange(10)

0 commit comments

Comments
 (0)