@@ -1370,6 +1370,40 @@ def test_power_scalar(shape, dtype):
1370
1370
assert_allclose (result , expected , rtol = 1e-6 )
1371
1371
1372
1372
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
+
1373
1407
@pytest .mark .parametrize (
1374
1408
"data" ,
1375
1409
[[[1.0 , - 1.0 ], [0.1 , - 0.1 ]], [- 2 , - 1 , 0 , 1 , 2 ]],
0 commit comments