@@ -38,6 +38,7 @@ def test_output(self):
38
38
self .check_output ()
39
39
40
40
def test_errors (self ):
41
+ paddle .enable_static ()
41
42
with program_guard (Program (), Program ()):
42
43
x = fluid .layers .data (name = 'x' , shape = [2 ], dtype = 'int32' )
43
44
y = fluid .layers .data (name = 'y' , shape = [2 ], dtype = 'int32' )
@@ -80,6 +81,7 @@ def setUp(self):
80
81
self .place = paddle .CUDAPlace (0 )
81
82
82
83
def test_api (self ):
84
+ paddle .enable_static ()
83
85
with program_guard (Program (), Program ()):
84
86
x = fluid .data (name = 'x' , shape = [4 ], dtype = 'int64' )
85
87
y = fluid .data (name = 'y' , shape = [4 ], dtype = 'int64' )
@@ -92,6 +94,7 @@ def test_api(self):
92
94
self .assertEqual ((res == self .real_result ).all (), True )
93
95
94
96
def test_broadcast_api_1 (self ):
97
+ paddle .enable_static ()
95
98
with program_guard (Program (), Program ()):
96
99
x = paddle .static .data (
97
100
name = 'x' , shape = [1 , 2 , 1 , 3 ], dtype = 'int32' )
@@ -108,6 +111,7 @@ def test_broadcast_api_1(self):
108
111
self .assertEqual ((res == real_result ).all (), True )
109
112
110
113
def test_attr_name (self ):
114
+ paddle .enable_static ()
111
115
with program_guard (Program (), Program ()):
112
116
x = fluid .layers .data (name = 'x' , shape = [4 ], dtype = 'int32' )
113
117
y = fluid .layers .data (name = 'y' , shape = [4 ], dtype = 'int32' )
@@ -130,6 +134,7 @@ def test_attr_name(self):
130
134
131
135
class TestCompareOpError (unittest .TestCase ):
132
136
def test_errors (self ):
137
+ paddle .enable_static ()
133
138
with program_guard (Program (), Program ()):
134
139
# The input x and y of compare_op must be Variable.
135
140
x = fluid .layers .data (name = 'x' , shape = [1 ], dtype = "float32" )
@@ -140,6 +145,7 @@ def test_errors(self):
140
145
141
146
class API_TestElementwise_Equal (unittest .TestCase ):
142
147
def test_api (self ):
148
+ paddle .enable_static ()
143
149
with fluid .program_guard (fluid .Program (), fluid .Program ()):
144
150
label = fluid .layers .assign (np .array ([3 , 3 ], dtype = "int32" ))
145
151
limit = fluid .layers .assign (np .array ([3 , 2 ], dtype = "int32" ))
@@ -159,5 +165,31 @@ def test_api(self):
159
165
self .assertEqual ((res == np .array ([True , True ])).all (), True )
160
166
161
167
168
+ class TestCompareOpPlace (unittest .TestCase ):
169
+ def test_place_1 (self ):
170
+ paddle .enable_static ()
171
+ place = paddle .CPUPlace ()
172
+ if core .is_compiled_with_cuda ():
173
+ place = paddle .CUDAPlace (0 )
174
+ label = fluid .layers .assign (np .array ([3 , 3 ], dtype = "int32" ))
175
+ limit = fluid .layers .assign (np .array ([3 , 2 ], dtype = "int32" ))
176
+ out = fluid .layers .less_than (label , limit , force_cpu = True )
177
+ exe = fluid .Executor (place )
178
+ res , = exe .run (fetch_list = [out ])
179
+ self .assertEqual ((res == np .array ([False , False ])).all (), True )
180
+
181
+ def test_place_2 (self ):
182
+ place = paddle .CPUPlace ()
183
+ data_place = place
184
+ if core .is_compiled_with_cuda ():
185
+ place = paddle .CUDAPlace (0 )
186
+ data_place = paddle .CUDAPinnedPlace ()
187
+ paddle .disable_static (place )
188
+ data = np .array ([9 ], dtype = "int64" )
189
+ data_tensor = paddle .to_tensor (data , place = data_place )
190
+ result = data_tensor == 0
191
+ self .assertEqual ((result .numpy () == np .array ([False ])).all (), True )
192
+
193
+
162
194
if __name__ == '__main__' :
163
195
unittest .main ()
0 commit comments