1
1
import unittest
2
+ from .helper import skip_or_change_if_dtype_not_supported
2
3
3
4
import dpnp as inp
4
5
7
8
8
9
class TestMatMul (unittest .TestCase ):
9
10
11
+ @classmethod
12
+ def setUpClass (cls ):
13
+ cls .dtype = skip_or_change_if_dtype_not_supported (
14
+ inp .float64 , change_dtype = True
15
+ )
16
+
10
17
def test_matmul (self ):
11
18
array_data = [1. , 2. , 3. , 4. ]
12
19
size = 2
13
20
14
21
# DPNP
15
- array1 = inp .reshape (inp .array (array_data , dtype = inp . float64 ), (size , size ))
16
- array2 = inp .reshape (inp .array (array_data , dtype = inp . float64 ), (size , size ))
22
+ array1 = inp .reshape (inp .array (array_data , dtype = self . dtype ), (size , size ))
23
+ array2 = inp .reshape (inp .array (array_data , dtype = self . dtype ), (size , size ))
17
24
result = inp .matmul (array1 , array2 )
18
25
# print(result)
19
26
20
27
# original
21
- array_1 = numpy .array (array_data , dtype = numpy . float64 ).reshape ((size , size ))
22
- array_2 = numpy .array (array_data , dtype = numpy . float64 ).reshape ((size , size ))
28
+ array_1 = numpy .array (array_data , dtype = self . dtype ).reshape ((size , size ))
29
+ array_2 = numpy .array (array_data , dtype = self . dtype ).reshape ((size , size ))
23
30
expected = numpy .matmul (array_1 , array_2 )
24
31
# print(expected)
25
32
@@ -33,14 +40,14 @@ def test_matmul2(self):
33
40
array_data2 = [1. , 2. , 3. , 4. , 5. , 6. , 7. , 8. ]
34
41
35
42
# DPNP
36
- array1 = inp .reshape (inp .array (array_data1 , dtype = inp . float64 ), (3 , 2 ))
37
- array2 = inp .reshape (inp .array (array_data2 , dtype = inp . float64 ), (2 , 4 ))
43
+ array1 = inp .reshape (inp .array (array_data1 , dtype = self . dtype ), (3 , 2 ))
44
+ array2 = inp .reshape (inp .array (array_data2 , dtype = self . dtype ), (2 , 4 ))
38
45
result = inp .matmul (array1 , array2 )
39
46
# print(result)
40
47
41
48
# original
42
- array_1 = numpy .array (array_data1 , dtype = numpy . float64 ).reshape ((3 , 2 ))
43
- array_2 = numpy .array (array_data2 , dtype = numpy . float64 ).reshape ((2 , 4 ))
49
+ array_1 = numpy .array (array_data1 , dtype = self . dtype ).reshape ((3 , 2 ))
50
+ array_2 = numpy .array (array_data2 , dtype = self . dtype ).reshape ((2 , 4 ))
44
51
expected = numpy .matmul (array_1 , array_2 )
45
52
# print(expected)
46
53
@@ -49,17 +56,17 @@ def test_matmul2(self):
49
56
def test_matmul3 (self ):
50
57
array_data1 = numpy .full ((513 , 513 ), 5 )
51
58
array_data2 = numpy .full ((513 , 513 ), 2 )
52
- out = numpy .empty ((513 , 513 ), dtype = numpy . float64 )
59
+ out = numpy .empty ((513 , 513 ), dtype = self . dtype )
53
60
54
61
# DPNP
55
- array1 = inp .array (array_data1 , dtype = inp . float64 )
56
- array2 = inp .array (array_data2 , dtype = inp . float64 )
57
- out1 = inp .array (out , dtype = inp . float64 )
62
+ array1 = inp .array (array_data1 , dtype = self . dtype )
63
+ array2 = inp .array (array_data2 , dtype = self . dtype )
64
+ out1 = inp .array (out , dtype = self . dtype )
58
65
result = inp .matmul (array1 , array2 , out = out1 )
59
66
60
67
# original
61
- array_1 = numpy .array (array_data1 , dtype = numpy . float64 )
62
- array_2 = numpy .array (array_data2 , dtype = numpy . float64 )
68
+ array_1 = numpy .array (array_data1 , dtype = self . dtype )
69
+ array_2 = numpy .array (array_data2 , dtype = self . dtype )
63
70
expected = numpy .matmul (array_1 , array_2 , out = out )
64
71
65
72
numpy .testing .assert_array_equal (expected , result )
0 commit comments