|
4 | 4 |
|
5 | 5 | import dpnp as inp
|
6 | 6 |
|
| 7 | +from .helper import get_float_dtypes |
| 8 | + |
7 | 9 |
|
8 | 10 | class TestMatMul(unittest.TestCase):
|
9 | 11 | def test_matmul(self):
|
10 | 12 | array_data = [1.0, 2.0, 3.0, 4.0]
|
11 | 13 | size = 2
|
12 | 14 |
|
13 |
| - # DPNP |
14 |
| - array1 = inp.reshape( |
15 |
| - inp.array(array_data, dtype=inp.float32), (size, size) |
16 |
| - ) |
17 |
| - array2 = inp.reshape( |
18 |
| - inp.array(array_data, dtype=inp.float32), (size, size) |
19 |
| - ) |
20 |
| - result = inp.matmul(array1, array2) |
21 |
| - # print(result) |
22 |
| - |
23 |
| - # original |
24 |
| - array_1 = numpy.array(array_data, dtype=numpy.float32).reshape( |
25 |
| - (size, size) |
26 |
| - ) |
27 |
| - array_2 = numpy.array(array_data, dtype=numpy.float32).reshape( |
28 |
| - (size, size) |
29 |
| - ) |
30 |
| - expected = numpy.matmul(array_1, array_2) |
31 |
| - # print(expected) |
32 |
| - |
33 |
| - # passed |
34 |
| - numpy.testing.assert_array_equal(expected, result) |
35 |
| - # still failed |
36 |
| - # self.assertEqual(expected, result) |
| 15 | + for dtype in get_float_dtypes(): |
| 16 | + # DPNP |
| 17 | + array1 = inp.reshape( |
| 18 | + inp.array(array_data, dtype=dtype), (size, size) |
| 19 | + ) |
| 20 | + array2 = inp.reshape( |
| 21 | + inp.array(array_data, dtype=dtype), (size, size) |
| 22 | + ) |
| 23 | + result = inp.matmul(array1, array2) |
| 24 | + # print(result) |
| 25 | + |
| 26 | + # original |
| 27 | + array_1 = numpy.array(array_data, dtype=dtype).reshape((size, size)) |
| 28 | + array_2 = numpy.array(array_data, dtype=dtype).reshape((size, size)) |
| 29 | + expected = numpy.matmul(array_1, array_2) |
| 30 | + # print(expected) |
| 31 | + |
| 32 | + # passed |
| 33 | + numpy.testing.assert_array_equal(expected, result) |
| 34 | + # still failed |
| 35 | + # self.assertEqual(expected, result) |
37 | 36 |
|
38 | 37 | def test_matmul2(self):
|
39 | 38 | array_data1 = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
|
40 | 39 | array_data2 = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
|
41 | 40 |
|
42 |
| - # DPNP |
43 |
| - array1 = inp.reshape(inp.array(array_data1, dtype=inp.float32), (3, 2)) |
44 |
| - array2 = inp.reshape(inp.array(array_data2, dtype=inp.float32), (2, 4)) |
45 |
| - result = inp.matmul(array1, array2) |
46 |
| - # print(result) |
| 41 | + for dtype in get_float_dtypes(): |
| 42 | + # DPNP |
| 43 | + array1 = inp.reshape(inp.array(array_data1, dtype=dtype), (3, 2)) |
| 44 | + array2 = inp.reshape(inp.array(array_data2, dtype=dtype), (2, 4)) |
| 45 | + result = inp.matmul(array1, array2) |
| 46 | + # print(result) |
47 | 47 |
|
48 |
| - # original |
49 |
| - array_1 = numpy.array(array_data1, dtype=numpy.float32).reshape((3, 2)) |
50 |
| - array_2 = numpy.array(array_data2, dtype=numpy.float32).reshape((2, 4)) |
51 |
| - expected = numpy.matmul(array_1, array_2) |
52 |
| - # print(expected) |
| 48 | + # original |
| 49 | + array_1 = numpy.array(array_data1, dtype=dtype).reshape((3, 2)) |
| 50 | + array_2 = numpy.array(array_data2, dtype=dtype).reshape((2, 4)) |
| 51 | + expected = numpy.matmul(array_1, array_2) |
| 52 | + # print(expected) |
53 | 53 |
|
54 |
| - numpy.testing.assert_array_equal(expected, result) |
| 54 | + numpy.testing.assert_array_equal(expected, result) |
55 | 55 |
|
56 | 56 | def test_matmul3(self):
|
57 | 57 | array_data1 = numpy.full((513, 513), 5)
|
58 | 58 | array_data2 = numpy.full((513, 513), 2)
|
59 |
| - out = numpy.empty((513, 513), dtype=numpy.float32) |
60 | 59 |
|
61 |
| - # DPNP |
62 |
| - array1 = inp.array(array_data1, dtype=inp.float32) |
63 |
| - array2 = inp.array(array_data2, dtype=inp.float32) |
64 |
| - out1 = inp.array(out, dtype=inp.float32) |
65 |
| - result = inp.matmul(array1, array2, out=out1) |
| 60 | + for dtype in get_float_dtypes(): |
| 61 | + out = numpy.empty((513, 513), dtype=dtype) |
| 62 | + |
| 63 | + # DPNP |
| 64 | + array1 = inp.array(array_data1, dtype=dtype) |
| 65 | + array2 = inp.array(array_data2, dtype=dtype) |
| 66 | + out1 = inp.array(out, dtype=dtype) |
| 67 | + result = inp.matmul(array1, array2, out=out1) |
66 | 68 |
|
67 |
| - # original |
68 |
| - array_1 = numpy.array(array_data1, dtype=numpy.float32) |
69 |
| - array_2 = numpy.array(array_data2, dtype=numpy.float32) |
70 |
| - expected = numpy.matmul(array_1, array_2, out=out) |
| 69 | + # original |
| 70 | + array_1 = numpy.array(array_data1, dtype=dtype) |
| 71 | + array_2 = numpy.array(array_data2, dtype=dtype) |
| 72 | + expected = numpy.matmul(array_1, array_2, out=out) |
71 | 73 |
|
72 |
| - numpy.testing.assert_array_equal(expected, result) |
| 74 | + numpy.testing.assert_array_equal(expected, result) |
73 | 75 |
|
74 | 76 |
|
75 | 77 | if __name__ == "__main__":
|
|
0 commit comments