Skip to content

Commit

Permalink
Update TestSpacing and TestTensordot (#2251)
Browse files Browse the repository at this point in the history
This PR suggests using `assert_allclose` instead of `assert_equal` with
a resolution-based tolerance in `TestSpacing::test_zeros` to fix test
failures on CUDA caused by excessive precision for float32.

And updates `TestTensordot::test_axes` and `TestTensordot::test_linalg`
to increase a factor parameter in `assert_dtype_allclose` for scaling
tolerance
  • Loading branch information
vlad-perevezentsev authored Jan 10, 2025
1 parent 1bed3bd commit e8c088c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dpnp/tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2111,14 +2111,15 @@ def test_zeros(self, dt):

result = dpnp.spacing(ia)
expected = numpy.spacing(a)
tol = numpy.finfo(expected.dtype).resolution
if numpy.lib.NumpyVersion(numpy.__version__) < "2.0.0":
assert_equal(result, expected)
assert_allclose(result, expected, rtol=tol, atol=tol)
else:
# numpy.spacing(-0.0) == numpy.spacing(0.0), i.e. NumPy returns
# positive value (looks as a bug in NumPy), because for any other
# negative input the NumPy result will be also a negative value.
expected[1] *= -1
assert_equal(result, expected)
assert_allclose(result, expected, rtol=tol, atol=tol)

@pytest.mark.parametrize("dt", get_float_dtypes(no_float16=False))
@pytest.mark.parametrize("val", [1, 1e-5, 1000])
Expand Down
4 changes: 2 additions & 2 deletions dpnp/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def test_axes(self, dtype, axes):

result = dpnp.tensordot(ia, ib, axes=axes)
expected = numpy.tensordot(a, b, axes=axes)
assert_dtype_allclose(result, expected)
assert_dtype_allclose(result, expected, factor=9)

@pytest.mark.parametrize("dtype1", get_all_dtypes())
@pytest.mark.parametrize("dtype2", get_all_dtypes())
Expand Down Expand Up @@ -844,7 +844,7 @@ def test_linalg(self, axes):

result = dpnp.linalg.tensordot(ia, ib, axes=axes)
expected = numpy.linalg.tensordot(a, b, axes=axes)
assert_dtype_allclose(result, expected)
assert_dtype_allclose(result, expected, factor=9)

def test_error(self):
a = 5
Expand Down

0 comments on commit e8c088c

Please sign in to comment.