Skip to content

Commit 2870d30

Browse files
author
Vahid Tavanashad
committed
update test_mathematical.py
1 parent 5173289 commit 2870d30

File tree

1 file changed

+25
-43
lines changed

1 file changed

+25
-43
lines changed

dpnp/tests/test_mathematical.py

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,10 +3599,10 @@ def setup_method(self):
35993599
numpy.random.seed(42)
36003600

36013601
@pytest.mark.parametrize(
3602-
"order_pair", [("C", "C"), ("C", "F"), ("F", "C"), ("F", "F")]
3602+
"order1, order2", [("C", "C"), ("C", "F"), ("F", "C"), ("F", "F")]
36033603
)
36043604
@pytest.mark.parametrize(
3605-
"shape_pair",
3605+
"shape1, shape2",
36063606
[
36073607
((4,), (4,)),
36083608
((1, 4), (4, 1)),
@@ -3651,9 +3651,7 @@ def setup_method(self):
36513651
((1, 3, 3, 1), (4, 1, 1, 2)),
36523652
],
36533653
)
3654-
def test_matmul(self, order_pair, shape_pair):
3655-
order1, order2 = order_pair
3656-
shape1, shape2 = shape_pair
3654+
def test_matmul(self, order1, order2, shape1, shape2):
36573655
# input should be float type otherwise they are copied to c-contigous array
36583656
# so testing order becomes meaningless
36593657
dtype = dpnp.default_float_type()
@@ -3669,10 +3667,10 @@ def test_matmul(self, order_pair, shape_pair):
36693667
assert_dtype_allclose(result, expected)
36703668

36713669
@pytest.mark.parametrize(
3672-
"order_pair", [("C", "C"), ("C", "F"), ("F", "C"), ("F", "F")]
3670+
"order1, order2", [("C", "C"), ("C", "F"), ("F", "C"), ("F", "F")]
36733671
)
36743672
@pytest.mark.parametrize(
3675-
"shape_pair",
3673+
"shape1, shape2",
36763674
[
36773675
((2, 0), (0, 3)),
36783676
((0, 4), (4, 3)),
@@ -3695,15 +3693,12 @@ def test_matmul(self, order_pair, shape_pair):
36953693
((7, 4, 3), (0, 7, 3, 5)),
36963694
],
36973695
)
3698-
def test_matmul_empty(self, order_pair, shape_pair):
3699-
order1, order2 = order_pair
3700-
shape1, shape2 = shape_pair
3696+
def test_matmul_empty(self, order1, order2, shape1, shape2):
37013697
dtype = dpnp.default_float_type()
37023698
a1 = numpy.arange(numpy.prod(shape1), dtype=dtype).reshape(shape1)
37033699
a2 = numpy.arange(numpy.prod(shape2), dtype=dtype).reshape(shape2)
37043700
a1 = numpy.array(a1, order=order1)
37053701
a2 = numpy.array(a2, order=order2)
3706-
37073702
b1 = dpnp.asarray(a1)
37083703
b2 = dpnp.asarray(a2)
37093704

@@ -3712,7 +3707,7 @@ def test_matmul_empty(self, order_pair, shape_pair):
37123707
assert_dtype_allclose(result, expected)
37133708

37143709
@pytest.mark.parametrize(
3715-
"shape_pair",
3710+
"shape1, shape2",
37163711
[
37173712
((2, 4), (4, 3)),
37183713
((4, 2, 3), (4, 3, 5)),
@@ -3724,15 +3719,10 @@ def test_matmul_empty(self, order_pair, shape_pair):
37243719
"((6, 7, 4, 3), (6, 7, 3, 5))",
37253720
],
37263721
)
3727-
def test_matmul_bool(self, shape_pair):
3728-
shape1, shape2 = shape_pair
3729-
a1 = numpy.resize(
3730-
numpy.arange(2, dtype=numpy.bool_), numpy.prod(shape1)
3731-
).reshape(shape1)
3732-
a2 = numpy.resize(
3733-
numpy.arange(2, dtype=numpy.bool_), numpy.prod(shape2)
3734-
).reshape(shape2)
3735-
3722+
def test_matmul_bool(self, shape1, shape2):
3723+
x = numpy.arange(2, dtype=numpy.bool_)
3724+
a1 = numpy.resize(x, numpy.prod(shape1)).reshape(shape1)
3725+
a2 = numpy.resize(x, numpy.prod(shape2)).reshape(shape2)
37363726
b1 = dpnp.asarray(a1)
37373727
b2 = dpnp.asarray(a2)
37383728

@@ -3742,7 +3732,7 @@ def test_matmul_bool(self, shape_pair):
37423732

37433733
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True))
37443734
@pytest.mark.parametrize(
3745-
"shape_pair",
3735+
"shape1, shape2",
37463736
[
37473737
((2, 4), (4, 3)),
37483738
((4, 2, 3), (4, 3, 5)),
@@ -3754,11 +3744,9 @@ def test_matmul_bool(self, shape_pair):
37543744
"((6, 7, 4, 3), (6, 7, 3, 5))",
37553745
],
37563746
)
3757-
def test_matmul_dtype(self, dtype, shape_pair):
3758-
shape1, shape2 = shape_pair
3747+
def test_matmul_dtype(self, dtype, shape1, shape2):
37593748
a1 = numpy.arange(numpy.prod(shape1)).reshape(shape1)
37603749
a2 = numpy.arange(numpy.prod(shape2)).reshape(shape2)
3761-
37623750
b1 = dpnp.asarray(a1)
37633751
b2 = dpnp.asarray(a2)
37643752

@@ -3892,7 +3880,7 @@ def test_matmul_axes_out_1D(self, axes, b_shape, out_shape):
38923880
"dtype2", get_all_dtypes(no_bool=True, no_none=True)
38933881
)
38943882
@pytest.mark.parametrize(
3895-
"shape_pair",
3883+
"shape1, shape2",
38963884
[
38973885
((2, 4), (4, 3)),
38983886
((4, 2, 3), (4, 3, 5)),
@@ -3904,11 +3892,9 @@ def test_matmul_axes_out_1D(self, axes, b_shape, out_shape):
39043892
"((6, 7, 4, 3), (6, 7, 3, 5))",
39053893
],
39063894
)
3907-
def test_matmul_dtype_matrix_inout(self, dtype1, dtype2, shape_pair):
3908-
shape1, shape2 = shape_pair
3895+
def test_matmul_dtype_matrix_inout(self, dtype1, dtype2, shape1, shape2):
39093896
a1 = numpy.arange(numpy.prod(shape1), dtype=dtype1).reshape(shape1)
39103897
a2 = numpy.arange(numpy.prod(shape2), dtype=dtype1).reshape(shape2)
3911-
39123898
b1 = dpnp.asarray(a1)
39133899
b2 = dpnp.asarray(a2)
39143900

@@ -3923,7 +3909,7 @@ def test_matmul_dtype_matrix_inout(self, dtype1, dtype2, shape_pair):
39233909
@pytest.mark.parametrize("dtype1", get_all_dtypes(no_bool=True))
39243910
@pytest.mark.parametrize("dtype2", get_all_dtypes(no_bool=True))
39253911
@pytest.mark.parametrize(
3926-
"shape_pair",
3912+
"shape1, shape2",
39273913
[
39283914
((2, 4), (4, 3)),
39293915
((4, 2, 3), (4, 3, 5)),
@@ -3935,11 +3921,9 @@ def test_matmul_dtype_matrix_inout(self, dtype1, dtype2, shape_pair):
39353921
"((6, 7, 4, 3), (6, 7, 3, 5))",
39363922
],
39373923
)
3938-
def test_matmul_dtype_matrix_inputs(self, dtype1, dtype2, shape_pair):
3939-
shape1, shape2 = shape_pair
3924+
def test_matmul_dtype_matrix_inputs(self, dtype1, dtype2, shape1, shape2):
39403925
a1 = numpy.arange(numpy.prod(shape1), dtype=dtype1).reshape(shape1)
39413926
a2 = numpy.arange(numpy.prod(shape2), dtype=dtype2).reshape(shape2)
3942-
39433927
b1 = dpnp.asarray(a1)
39443928
b2 = dpnp.asarray(a2)
39453929

@@ -3951,7 +3935,7 @@ def test_matmul_dtype_matrix_inputs(self, dtype1, dtype2, shape_pair):
39513935
@pytest.mark.parametrize("order2", ["C", "F", "A"])
39523936
@pytest.mark.parametrize("order", ["C", "F", "K", "A"])
39533937
@pytest.mark.parametrize(
3954-
"shape_pair",
3938+
"shape1, shape2",
39553939
[
39563940
((2, 4), (4, 3)),
39573941
((4, 2, 3), (4, 3, 5)),
@@ -3963,21 +3947,20 @@ def test_matmul_dtype_matrix_inputs(self, dtype1, dtype2, shape_pair):
39633947
"((6, 7, 4, 3), (6, 7, 3, 5))",
39643948
],
39653949
)
3966-
def test_matmul_order(self, order1, order2, order, shape_pair):
3967-
shape1, shape2 = shape_pair
3950+
def test_matmul_order(self, order1, order2, order, shape1, shape2):
39683951
a1 = numpy.arange(numpy.prod(shape1)).reshape(shape1, order=order1)
39693952
a2 = numpy.arange(numpy.prod(shape2)).reshape(shape2, order=order2)
3970-
39713953
b1 = dpnp.asarray(a1)
39723954
b2 = dpnp.asarray(a2)
39733955

39743956
result = dpnp.matmul(b1, b2, order=order)
39753957
expected = numpy.matmul(a1, a2, order=order)
3976-
# For the special case of shape_pair == ((6, 7, 4, 3), (6, 7, 3, 5))
3977-
# and order1 == "F" and order2 == "F", NumPy result is not c-contiguous
3958+
# For the special case of shape1 = (6, 7, 4, 3), shape2 = (6, 7, 3, 5)
3959+
# and order1 = "F" and order2 = "F", NumPy result is not c-contiguous
39783960
# nor f-contiguous, while dpnp (and cupy) results are c-contiguous
39793961
if not (
3980-
shape_pair == ((6, 7, 4, 3), (6, 7, 3, 5))
3962+
shape1 == (6, 7, 4, 3)
3963+
and shape2 == (6, 7, 3, 5)
39813964
and order1 == "F"
39823965
and order2 == "F"
39833966
and order == "K"
@@ -4253,15 +4236,14 @@ def test_matmul_out_0D(self, out_shape):
42534236

42544237
@testing.slow
42554238
@pytest.mark.parametrize(
4256-
"shape_pair",
4239+
"shape1, shape2",
42574240
[
42584241
((5000, 5000, 2, 2), (5000, 5000, 2, 2)),
42594242
((2, 2), (5000, 5000, 2, 2)),
42604243
((5000, 5000, 2, 2), (2, 2)),
42614244
],
42624245
)
4263-
def test_matmul_large(self, shape_pair):
4264-
shape1, shape2 = shape_pair
4246+
def test_matmul_large(self, shape1, shape2):
42654247
size1 = numpy.prod(shape1, dtype=int)
42664248
size2 = numpy.prod(shape2, dtype=int)
42674249
a = numpy.array(numpy.random.uniform(-5, 5, size1)).reshape(shape1)

0 commit comments

Comments
 (0)