@@ -39,11 +39,12 @@ def setUp(self):
39
39
self .op_type = "gather"
40
40
self .config ()
41
41
xnp = np .random .random (self .x_shape ).astype (self .x_type )
42
- self .iintel_hputs = {
42
+ self .inputs = {
43
43
"X" : xnp ,
44
44
"Index" : np .array (self .index ).astype (self .index_type ),
45
45
}
46
- self .outputs = {"Out" : self .iintel_hputs ["X" ][self .iintel_hputs ["Index" ]]}
46
+ self .attrs = {"axis" : self .axis }
47
+ self .outputs = {"Out" : gather_numpy (xnp , self .index , self .axis )}
47
48
48
49
def set_intel_hpu (self ):
49
50
self .__class__ .use_custom_device = True
@@ -52,43 +53,41 @@ def test_check_output(self):
52
53
self .check_output_with_place (self .place )
53
54
54
55
def test_check_grad (self ):
55
- self .check_grad_with_place (
56
- self .place ,
57
- ["X" ],
58
- "Out" ,
59
- max_relative_error = 0.006 ,
60
- )
56
+ pass
61
57
62
58
def config (self ):
63
59
"""
64
- For multi-dimension iintel_hput
60
+ For multi-dimension input
65
61
"""
66
62
self .x_shape = (10 , 20 )
67
63
self .x_type = "float32"
68
64
self .index = [1 , 3 , 5 ]
69
65
self .index_type = "int32"
66
+ self .axis = 0
70
67
71
68
72
69
class TestCase1 (TestGatherOp ):
73
70
def config (self ):
74
71
"""
75
- For one dimension iintel_hput
72
+ For one dimension input
76
73
"""
77
74
self .x_shape = 100
78
75
self .x_type = "float32"
79
76
self .index = [1 , 3 , 5 ]
80
77
self .index_type = "int32"
78
+ self .axis = 0
81
79
82
80
83
81
class TestCase2 (TestGatherOp ):
84
82
def config (self ):
85
83
"""
86
- For one dimension iintel_hput
84
+ For one dimension input
87
85
"""
88
86
self .x_shape = 100
89
87
self .x_type = "int64"
90
88
self .index = [1 , 3 , 5 ]
91
89
self .index_type = "int32"
90
+ self .axis = 0
92
91
93
92
def test_check_grad (self ):
94
93
pass
@@ -97,40 +96,28 @@ def test_check_grad(self):
97
96
class TestCase3 (TestGatherOp ):
98
97
def config (self ):
99
98
"""
100
- For one dimension iintel_hput
99
+ For one dimension input
101
100
"""
102
101
self .x_shape = 100
103
102
self .x_type = "int32"
104
103
self .index = [1 , 3 , 5 ]
105
104
self .index_type = "int32"
105
+ self .axis = 0
106
106
107
107
def test_check_grad (self ):
108
108
pass
109
109
110
110
111
- # class TestCase4(TestGatherOp):
112
- # def config(self):
113
- # """
114
- # For one dimension iintel_hput
115
- # """
116
- # self.x_shape = 100
117
- # self.x_type = "bool"
118
- # self.index = [1, 3, 5]
119
- # self.index_type = "int32"
120
-
121
- # def test_check_grad(self):
122
- # pass
123
-
124
-
125
- class TestCase5 (TestGatherOp ):
111
+ class TestCase4 (TestGatherOp ):
126
112
def config (self ):
127
113
"""
128
- For one dimension iintel_hput
114
+ For multi- dimension input
129
115
"""
130
116
self .x_shape = [4000 , 8192 ]
131
117
self .x_type = "float32"
132
118
self .index = [1 , 3 , 5 ]
133
119
self .index_type = "int32"
120
+ self .axis = 1
134
121
135
122
136
123
class API_TestGather (unittest .TestCase ):
@@ -141,10 +128,10 @@ def test_out1(self):
141
128
out = paddle .gather (data1 , index )
142
129
place = paddle .CustomPlace ("intel_hpu" , 0 )
143
130
exe = base .Executor (place )
144
- iintel_hput = np .array ([[1 , 2 ], [3 , 4 ], [5 , 6 ]]).astype ("float32" )
131
+ input = np .array ([[1 , 2 ], [3 , 4 ], [5 , 6 ]]).astype ("float32" )
145
132
index_1 = np .array ([1 , 2 ]).astype ("int32" )
146
133
(result ,) = exe .run (
147
- feed = {"data1" : iintel_hput , "index" : index_1 }, fetch_list = [out ]
134
+ feed = {"data1" : input , "index" : index_1 }, fetch_list = [out ]
148
135
)
149
136
expected_output = np .array ([[3 , 4 ], [5 , 6 ]])
150
137
self .assertTrue (np .allclose (result , expected_output ))
0 commit comments