Skip to content

Commit 68808cd

Browse files
Add dpnp tests
1 parent 9e274fd commit 68808cd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_mathematical.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,40 @@ def test_power_scalar(shape, dtype):
13701370
assert_allclose(result, expected, rtol=1e-6)
13711371

13721372

1373+
class TestNanToNum:
1374+
@pytest.mark.parametrize("dtype", get_all_dtypes())
1375+
@pytest.mark.parametrize("shape", [(3,), (2, 3), (3, 2, 2)])
1376+
def test_nan_to_num(self, dtype, shape):
1377+
a = numpy.random.randn(*shape).astype(dtype)
1378+
if not dpnp.issubdtype(dtype, dpnp.integer):
1379+
a.flat[1] = numpy.nan
1380+
a_dp = dpnp.array(a)
1381+
1382+
result = dpnp.nan_to_num(a_dp)
1383+
expected = numpy.nan_to_num(a)
1384+
assert_allclose(result, expected)
1385+
1386+
@pytest.mark.parametrize(
1387+
"data", [[], [numpy.nan], [numpy.inf], [-numpy.inf]]
1388+
)
1389+
@pytest.mark.parametrize("dtype", get_float_complex_dtypes())
1390+
def test_empty_and_single_value_arrays(self, data, dtype):
1391+
a = numpy.array(data, dtype)
1392+
ia = dpnp.array(a)
1393+
1394+
result = dpnp.nan_to_num(ia)
1395+
expected = numpy.nan_to_num(a)
1396+
assert_allclose(result, expected)
1397+
1398+
def test_boolean_array(self):
1399+
a = numpy.array([True, False, numpy.nan], dtype=bool)
1400+
ia = dpnp.array(a)
1401+
1402+
result = dpnp.nan_to_num(ia)
1403+
expected = numpy.nan_to_num(a)
1404+
assert_allclose(result, expected)
1405+
1406+
13731407
@pytest.mark.parametrize(
13741408
"data",
13751409
[[[1.0, -1.0], [0.1, -0.1]], [-2, -1, 0, 1, 2]],

0 commit comments

Comments
 (0)