Skip to content

Commit

Permalink
use a seed for random input numbers in tests (IntelPython#1716)
Browse files Browse the repository at this point in the history
* add gen_seed

change seed

* use setup_method

* remove duplicates
  • Loading branch information
vtavana authored Feb 17, 2024
1 parent 3461932 commit f33ef19
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
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

0 comments on commit f33ef19

Please sign in to comment.