File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,38 @@ static Tensor* GetMutableTensorFromVar(Variable* var) {
293
293
}
294
294
}
295
295
296
+ bool ExecutionContext::HasInput (const std::string& name) const {
297
+ if (!op_.HasInputs (name)) {
298
+ return false ;
299
+ }
300
+ auto & ins = Inputs (name);
301
+ size_t length = ins.size ();
302
+ if (length == 0 ) {
303
+ return false ;
304
+ }
305
+ PADDLE_ENFORCE_EQ (length, 1UL ,
306
+ " Input %s should not have more than one inputs" , name);
307
+ auto arg = ins[0 ];
308
+ auto * var = arg == kEmptyVarName ? nullptr : scope_.FindVar (arg);
309
+ return var != nullptr ;
310
+ }
311
+
312
+ bool ExecutionContext::HasOutput (const std::string& name) const {
313
+ if (!op_.HasOutputs (name)) {
314
+ return false ;
315
+ }
316
+ auto & outs = Outputs (name);
317
+ size_t length = outs.size ();
318
+ if (length == 0 ) {
319
+ return false ;
320
+ }
321
+ PADDLE_ENFORCE_EQ (length, 1UL ,
322
+ " Output %s should not have more than one inputs" , name);
323
+ auto arg = outs[0 ];
324
+ auto * var = arg == kEmptyVarName ? nullptr : scope_.FindVar (arg);
325
+ return var != nullptr ;
326
+ }
327
+
296
328
template <>
297
329
const Tensor* ExecutionContext::Input<Tensor>(const std::string& name) const {
298
330
auto * var = InputVar (name);
Original file line number Diff line number Diff line change @@ -191,9 +191,9 @@ class ExecutionContext {
191
191
return op_.Attr <T>(name);
192
192
}
193
193
194
- bool HasInput (const std::string& name) const { return op_. HasInputs (name); }
194
+ bool HasInput (const std::string& name) const ;
195
195
196
- bool HasOutput (const std::string& name) const { return op_. HasOutputs (name); }
196
+ bool HasOutput (const std::string& name) const ;
197
197
198
198
size_t InputSize (const std::string& name) const {
199
199
return op_.Inputs (name).size ();
You can’t perform that action at this time.
0 commit comments