Skip to content

Commit 54795cd

Browse files
committed
Add tests to cover function
1 parent 0e10a07 commit 54795cd

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

tests/skipped_tests.tbl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_interp_inf_to_nan
245245
tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_heaviside
246246
tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_heaviside_nan_inf
247247

248-
tests/third_party/cupy/math_tests/test_rounding.py::TestRounding::test_fix
249-
250248
tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsBeta_param_0_{a_shape=(), b_shape=(), shape=(4, 3, 2)}::test_beta
251249
tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsBeta_param_1_{a_shape=(), b_shape=(), shape=(3, 2)}::test_beta
252250
tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsBeta_param_2_{a_shape=(), b_shape=(3, 2), shape=(4, 3, 2)}::test_beta

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,6 @@ tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_interp_inf_to_nan
299299
tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_heaviside
300300
tests/third_party/cupy/math_tests/test_misc.py::TestMisc::test_heaviside_nan_inf
301301

302-
tests/third_party/cupy/math_tests/test_rounding.py::TestRounding::test_fix
303-
304302
tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsBeta_param_0_{a_shape=(), b_shape=(), shape=(4, 3, 2)}::test_beta
305303
tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsBeta_param_1_{a_shape=(), b_shape=(), shape=(3, 2)}::test_beta
306304
tests/third_party/cupy/random_tests/test_distributions.py::TestDistributionsBeta_param_2_{a_shape=(), b_shape=(3, 2), shape=(4, 3, 2)}::test_beta

tests/test_mathematical.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,73 @@ def test_prepend_append_axis_error(self, xp):
615615
assert_raises(AxisError, xp.diff, a, axis=3, append=0)
616616

617617

618+
class TestFix:
619+
@pytest.mark.parametrize(
620+
"dt", get_all_dtypes(no_none=True, no_complex=True)
621+
)
622+
def test_basic(self, dt):
623+
a = numpy.array(
624+
[[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]], dtype=dt
625+
)
626+
ia = dpnp.array(a)
627+
628+
result = dpnp.fix(ia)
629+
expected = numpy.fix(a)
630+
assert_array_equal(result, expected)
631+
632+
@pytest.mark.parametrize("xp", [numpy, dpnp])
633+
@pytest.mark.parametrize("dt", get_complex_dtypes())
634+
def test_complex(self, xp, dt):
635+
a = xp.array([1.1, -1.1], dtype=dt)
636+
with pytest.raises((ValueError, TypeError)):
637+
xp.fix(a)
638+
639+
@pytest.mark.parametrize(
640+
"a_dt", get_all_dtypes(no_none=True, no_bool=True, no_complex=True)
641+
)
642+
def test_out(self, a_dt):
643+
a = numpy.array(
644+
[[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]], dtype=a_dt
645+
)
646+
ia = dpnp.array(a)
647+
648+
if a.dtype != numpy.float32 and has_support_aspect64():
649+
out_dt = numpy.float64
650+
else:
651+
out_dt = numpy.float32
652+
out = numpy.zeros_like(a, dtype=out_dt)
653+
iout = dpnp.array(out)
654+
655+
result = dpnp.fix(ia, out=iout)
656+
expected = numpy.fix(a, out=out)
657+
assert_array_equal(result, expected)
658+
659+
@pytest.mark.skipif(not has_support_aspect16(), reason="no fp16 support")
660+
@pytest.mark.parametrize("dt", [bool, numpy.float16])
661+
def test_out_float16(self, dt):
662+
a = numpy.array(
663+
[[1.0, 1.1], [1.5, 1.8], [-1.0, -1.1], [-1.5, -1.8]], dtype=dt
664+
)
665+
out = numpy.zeros_like(a, dtype=numpy.float16)
666+
ia, iout = dpnp.array(a), dpnp.array(out)
667+
668+
result = dpnp.fix(ia, out=iout)
669+
expected = numpy.fix(a, out=out)
670+
assert_array_equal(result, expected)
671+
672+
@pytest.mark.parametrize("xp", [numpy, dpnp])
673+
@pytest.mark.parametrize("dt", [bool] + get_integer_dtypes())
674+
def test_out_invalid_dtype(self, xp, dt):
675+
a = xp.array([[1.5, 1.8], [-1.0, -1.1]])
676+
out = xp.zeros_like(a, dtype=dt)
677+
678+
with pytest.raises((ValueError, TypeError)):
679+
xp.fix(a, out=out)
680+
681+
def test_scalar(self):
682+
assert_raises(TypeError, dpnp.fix, -3.4)
683+
684+
618685
class TestGradient:
619686
@pytest.mark.parametrize("dt", get_all_dtypes(no_none=True, no_bool=True))
620687
def test_basic(self, dt):

tests/test_sycl_queue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ def test_meshgrid(device):
422422
pytest.param("exp2", [0.0, 1.0, 2.0]),
423423
pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]),
424424
pytest.param("fabs", [-1.2, 1.2]),
425+
pytest.param("fix", [2.1, 2.9, -2.1, -2.9]),
425426
pytest.param("flatnonzero", [-2, -1, 0, 1, 2]),
426427
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
427428
pytest.param("gradient", [1.0, 2.0, 4.0, 7.0, 11.0, 16.0]),

tests/test_usm_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ def test_norm(usm_type, ord, axis):
553553
pytest.param("exp2", [0.0, 1.0, 2.0]),
554554
pytest.param("expm1", [1.0e-10, 1.0, 2.0, 4.0, 7.0]),
555555
pytest.param("fabs", [-1.2, 1.2]),
556+
pytest.param("fix", [2.1, 2.9, -2.1, -2.9]),
556557
pytest.param("flatnonzero", [-2, -1, 0, 1, 2]),
557558
pytest.param("floor", [-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]),
558559
pytest.param("gradient", [1, 2, 4, 7, 11, 16]),

0 commit comments

Comments
 (0)