Skip to content

use a seed for random input numbers in tests #1716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions tests/test_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@


class TestDot:
def setup_method(self):
numpy.random.seed(42)

@pytest.mark.parametrize("dtype", get_all_dtypes())
def test_dot_ones(self, dtype):
n = 10**5
Expand Down Expand Up @@ -355,6 +358,9 @@ def test_multi_dot(type):


class TestTensordot:
def setup_method(self):
numpy.random.seed(87)

@pytest.mark.parametrize("dtype", get_all_dtypes())
def test_tensordot_scalar(self, dtype):
a = 2
Expand Down Expand Up @@ -383,8 +389,7 @@ def test_tensordot(self, dtype, axes):

result = dpnp.tensordot(ia, ib, axes=axes)
expected = numpy.tensordot(a, b, axes=axes)
# TODO: investigate the effect of factor, see SAT-6700
assert_dtype_allclose(result, expected, factor=24)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize("dtype", get_complex_dtypes())
@pytest.mark.parametrize("axes", [-3, -2, -1, 0, 1, 2])
Expand All @@ -400,8 +405,7 @@ def test_tensordot_complex(self, dtype, axes):

result = dpnp.tensordot(ia, ib, axes=axes)
expected = numpy.tensordot(a, b, axes=axes)
# TODO: investigate the effect of factor, see SAT-6700
assert_dtype_allclose(result, expected, factor=24)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
@pytest.mark.parametrize(
Expand All @@ -426,8 +430,7 @@ def test_tensordot_axes(self, dtype, axes):

result = dpnp.tensordot(ia, ib, axes=axes)
expected = numpy.tensordot(a, b, axes=axes)
# TODO: investigate the effect of factor, see SAT-6700
assert_dtype_allclose(result, expected, factor=24)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize("dtype1", get_all_dtypes())
@pytest.mark.parametrize("dtype2", get_all_dtypes())
Expand All @@ -443,8 +446,7 @@ def test_tensordot_input_dtype_matrix(self, dtype1, dtype2):

result = dpnp.tensordot(ia, ib)
expected = numpy.tensordot(a, b)
# TODO: investigate the effect of factor, see SAT-6700
assert_dtype_allclose(result, expected, factor=24)
assert_dtype_allclose(result, expected)

def test_tensordot_strided(self):
for dim in [1, 2, 3, 4]:
Expand Down Expand Up @@ -500,6 +502,9 @@ def test_tensordot_error(self):


class TestVdot:
def setup_method(self):
numpy.random.seed(42)

@pytest.mark.parametrize("dtype", get_all_dtypes())
def test_vdot_scalar(self, dtype):
a = numpy.array([3.5], dtype=dtype)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,9 @@ def test_inplace_floor_divide(dtype):


class TestMatmul:
def setup_method(self):
numpy.random.seed(42)

@pytest.mark.parametrize(
"order_pair", [("C", "C"), ("C", "F"), ("F", "C"), ("F", "F")]
)
Expand Down Expand Up @@ -2655,8 +2658,7 @@ def test_matmul_axes_ND_ND(self, dtype, axes):

result = dpnp.matmul(ia, ib, axes=axes)
expected = numpy.matmul(a, b, axes=axes)
# TODO: investigate the effect of factor, see SAT-6700
assert_dtype_allclose(result, expected, factor=24)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize(
"axes",
Expand Down Expand Up @@ -2726,8 +2728,7 @@ def test_matmul_axes_out(self, dtype, axes, out_shape):
result = dpnp.matmul(ia, ib, axes=axes, out=out_dp)
assert result is out_dp
expected = numpy.matmul(a, b, axes=axes)
# TODO: investigate the effect of factor, see SAT-6700
assert_dtype_allclose(result, expected, factor=24)
assert_dtype_allclose(result, expected)

@pytest.mark.parametrize(
"axes, b_shape, out_shape",
Expand Down