Skip to content

Commit 04e82e7

Browse files
committed
add gen_seed
change seed
1 parent 23bd001 commit 04e82e7

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

tests/test_dot.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010

1111
class TestDot:
12+
@pytest.fixture
13+
def gen_seed(self):
14+
numpy.random.seed(42)
15+
1216
@pytest.mark.parametrize("dtype", get_all_dtypes())
1317
def test_dot_ones(self, dtype):
1418
n = 10**5
@@ -35,7 +39,7 @@ def test_dot_arange(self, dtype):
3539
assert_dtype_allclose(result, expected)
3640

3741
@pytest.mark.parametrize("dtype", get_all_dtypes())
38-
def test_dot_scalar(self, dtype):
42+
def test_dot_scalar(self, dtype, gen_seed):
3943
a = 2
4044
b = numpy.array(numpy.random.uniform(-5, 5, 10), dtype=dtype)
4145
ib = dpnp.array(b)
@@ -70,7 +74,7 @@ def test_dot_scalar(self, dtype):
7074
"3d_3d",
7175
],
7276
)
73-
def test_dot(self, dtype, array_info):
77+
def test_dot(self, dtype, array_info, gen_seed):
7478
size1, size2, shape1, shape2 = array_info
7579
a = numpy.array(
7680
numpy.random.uniform(-5, 5, size1), dtype=dtype
@@ -111,7 +115,7 @@ def test_dot(self, dtype, array_info):
111115
"3d_3d",
112116
],
113117
)
114-
def test_dot_complex(self, dtype, array_info):
118+
def test_dot_complex(self, dtype, array_info, gen_seed):
115119
size1, size2, shape1, shape2 = array_info
116120
x11 = numpy.random.uniform(-5, 5, size1)
117121
x12 = numpy.random.uniform(-5, 5, size1)
@@ -152,7 +156,7 @@ def test_dot_complex(self, dtype, array_info):
152156
"3d_3d",
153157
],
154158
)
155-
def test_dot_ndarray(self, dtype, array_info):
159+
def test_dot_ndarray(self, dtype, array_info, gen_seed):
156160
size1, size2, shape1, shape2 = array_info
157161
a = numpy.array(
158162
numpy.random.uniform(-5, 5, size1), dtype=dtype
@@ -191,7 +195,7 @@ def test_dot_strided(self, dtype):
191195
assert_dtype_allclose(result, expected)
192196

193197
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
194-
def test_dot_out_scalar(self, dtype):
198+
def test_dot_out_scalar(self, dtype, gen_seed):
195199
size = 10
196200
a = 2
197201
b = numpy.array(numpy.random.uniform(-5, 5, size), dtype=dtype)
@@ -231,7 +235,7 @@ def test_dot_out_scalar(self, dtype):
231235
"3d_3d",
232236
],
233237
)
234-
def test_dot_out(self, dtype, array_info):
238+
def test_dot_out(self, dtype, array_info, gen_seed):
235239
size1, size2, shape1, shape2, out_shape = array_info
236240
a = numpy.array(
237241
numpy.random.uniform(-5, 5, size1), dtype=dtype
@@ -251,7 +255,7 @@ def test_dot_out(self, dtype, array_info):
251255

252256
@pytest.mark.parametrize("dtype1", get_all_dtypes())
253257
@pytest.mark.parametrize("dtype2", get_all_dtypes())
254-
def test_dot_input_dtype_matrix(self, dtype1, dtype2):
258+
def test_dot_input_dtype_matrix(self, dtype1, dtype2, gen_seed):
255259
a = numpy.array(numpy.random.uniform(-5, 5, 10), dtype=dtype1)
256260
b = numpy.array(numpy.random.uniform(-5, 5, 10), dtype=dtype2)
257261
ia = dpnp.array(a)
@@ -355,8 +359,12 @@ def test_multi_dot(type):
355359

356360

357361
class TestTensordot:
362+
@pytest.fixture
363+
def gen_seed(self):
364+
numpy.random.seed(87)
365+
358366
@pytest.mark.parametrize("dtype", get_all_dtypes())
359-
def test_tensordot_scalar(self, dtype):
367+
def test_tensordot_scalar(self, dtype, gen_seed):
360368
a = 2
361369
b = numpy.array(numpy.random.uniform(-5, 5, 10), dtype=dtype)
362370
ib = dpnp.array(b)
@@ -371,7 +379,7 @@ def test_tensordot_scalar(self, dtype):
371379

372380
@pytest.mark.parametrize("dtype", get_all_dtypes(no_complex=True))
373381
@pytest.mark.parametrize("axes", [-3, -2, -1, 0, 1, 2])
374-
def test_tensordot(self, dtype, axes):
382+
def test_tensordot(self, dtype, axes, gen_seed):
375383
a = numpy.array(numpy.random.uniform(-10, 10, 64), dtype=dtype).reshape(
376384
4, 4, 4
377385
)
@@ -383,12 +391,11 @@ def test_tensordot(self, dtype, axes):
383391

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

389396
@pytest.mark.parametrize("dtype", get_complex_dtypes())
390397
@pytest.mark.parametrize("axes", [-3, -2, -1, 0, 1, 2])
391-
def test_tensordot_complex(self, dtype, axes):
398+
def test_tensordot_complex(self, dtype, axes, gen_seed):
392399
x11 = numpy.random.uniform(-10, 10, 64)
393400
x12 = numpy.random.uniform(-10, 10, 64)
394401
x21 = numpy.random.uniform(-10, 10, 64)
@@ -400,8 +407,7 @@ def test_tensordot_complex(self, dtype, axes):
400407

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

406412
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
407413
@pytest.mark.parametrize(
@@ -414,7 +420,7 @@ def test_tensordot_complex(self, dtype, axes):
414420
((3, 1), (0, 2)),
415421
],
416422
)
417-
def test_tensordot_axes(self, dtype, axes):
423+
def test_tensordot_axes(self, dtype, axes, gen_seed):
418424
a = numpy.array(
419425
numpy.random.uniform(-10, 10, 120), dtype=dtype
420426
).reshape(2, 5, 3, 4)
@@ -426,12 +432,11 @@ def test_tensordot_axes(self, dtype, axes):
426432

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

432437
@pytest.mark.parametrize("dtype1", get_all_dtypes())
433438
@pytest.mark.parametrize("dtype2", get_all_dtypes())
434-
def test_tensordot_input_dtype_matrix(self, dtype1, dtype2):
439+
def test_tensordot_input_dtype_matrix(self, dtype1, dtype2, gen_seed):
435440
a = numpy.array(
436441
numpy.random.uniform(-10, 10, 60), dtype=dtype1
437442
).reshape(3, 4, 5)
@@ -443,10 +448,9 @@ def test_tensordot_input_dtype_matrix(self, dtype1, dtype2):
443448

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

449-
def test_tensordot_strided(self):
453+
def test_tensordot_strided(self, gen_seed):
450454
for dim in [1, 2, 3, 4]:
451455
axes = 1 if dim == 1 else 2
452456
A = numpy.random.rand(*([10] * dim))
@@ -500,6 +504,10 @@ def test_tensordot_error(self):
500504

501505

502506
class TestVdot:
507+
@pytest.fixture
508+
def gen_seed(self):
509+
numpy.random.seed(42)
510+
503511
@pytest.mark.parametrize("dtype", get_all_dtypes())
504512
def test_vdot_scalar(self, dtype):
505513
a = numpy.array([3.5], dtype=dtype)
@@ -536,7 +544,7 @@ def test_vdot_scalar(self, dtype):
536544
"3d_3d",
537545
],
538546
)
539-
def test_vdot(self, dtype, array_info):
547+
def test_vdot(self, dtype, array_info, gen_seed):
540548
size1, size2, shape1, shape2 = array_info
541549
a = numpy.array(
542550
numpy.random.uniform(-5, 5, size1), dtype=dtype
@@ -573,7 +581,7 @@ def test_vdot(self, dtype, array_info):
573581
"3d_3d",
574582
],
575583
)
576-
def test_vdot_complex(self, dtype, array_info):
584+
def test_vdot_complex(self, dtype, array_info, gen_seed):
577585
size1, size2, shape1, shape2 = array_info
578586
x11 = numpy.random.uniform(-5, 5, size1)
579587
x12 = numpy.random.uniform(-5, 5, size1)
@@ -613,7 +621,7 @@ def test_vdot_strided(self, dtype):
613621

614622
@pytest.mark.parametrize("dtype1", get_all_dtypes())
615623
@pytest.mark.parametrize("dtype2", get_all_dtypes())
616-
def test_vdot_input_dtype_matrix(self, dtype1, dtype2):
624+
def test_vdot_input_dtype_matrix(self, dtype1, dtype2, gen_seed):
617625
a = numpy.array(numpy.random.uniform(-5, 5, 10), dtype=dtype1)
618626
b = numpy.array(numpy.random.uniform(-5, 5, 10), dtype=dtype2)
619627
ia = dpnp.array(a)

tests/test_mathematical.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,10 @@ def test_inplace_floor_divide(dtype):
24862486

24872487

24882488
class TestMatmul:
2489+
@pytest.fixture
2490+
def gen_seed(self):
2491+
numpy.random.seed(42)
2492+
24892493
@pytest.mark.parametrize(
24902494
"order_pair", [("C", "C"), ("C", "F"), ("F", "C"), ("F", "F")]
24912495
)
@@ -2643,7 +2647,7 @@ def test_matmul_dtype(self, dtype, shape_pair):
26432647
[(3, 1), (2, 0), (0, 1)],
26442648
],
26452649
)
2646-
def test_matmul_axes_ND_ND(self, dtype, axes):
2650+
def test_matmul_axes_ND_ND(self, dtype, axes, gen_seed):
26472651
a = numpy.array(
26482652
numpy.random.uniform(-10, 10, 120), dtype=dtype
26492653
).reshape(2, 5, 3, 4)
@@ -2655,8 +2659,7 @@ def test_matmul_axes_ND_ND(self, dtype, axes):
26552659

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

26612664
@pytest.mark.parametrize(
26622665
"axes",
@@ -2712,7 +2715,7 @@ def test_matmul_axes_1D_1D(self):
27122715
([(3, 1), (2, 0), (1, 2)], (2, 4, 4, 3)),
27132716
],
27142717
)
2715-
def test_matmul_axes_out(self, dtype, axes, out_shape):
2718+
def test_matmul_axes_out(self, dtype, axes, out_shape, gen_seed):
27162719
a = numpy.array(
27172720
numpy.random.uniform(-10, 10, 120), dtype=dtype
27182721
).reshape(2, 5, 3, 4)
@@ -2726,8 +2729,7 @@ def test_matmul_axes_out(self, dtype, axes, out_shape):
27262729
result = dpnp.matmul(ia, ib, axes=axes, out=out_dp)
27272730
assert result is out_dp
27282731
expected = numpy.matmul(a, b, axes=axes)
2729-
# TODO: investigate the effect of factor, see SAT-6700
2730-
assert_dtype_allclose(result, expected, factor=24)
2732+
assert_dtype_allclose(result, expected)
27312733

27322734
@pytest.mark.parametrize(
27332735
"axes, b_shape, out_shape",

0 commit comments

Comments
 (0)