-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make operator Input/Output can return nullptr #3831
Make operator Input/Output can return nullptr #3831
Conversation
paddle/framework/operator.h
Outdated
@@ -238,46 +238,58 @@ class InferShapeContext { | |||
} | |||
|
|||
const Variable* InputVar(const std::string& name) const { | |||
return scope_.FindVar(op_.Input(name)); | |||
auto ipt = op_.Input(name); | |||
if (ipt == kEmptyVarName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果在scope中检查如果name是kEmptyVarName就报个错,是不是不用加这么多代码
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不过现在这种方式比较便于理解代码逻辑
paddle/framework/operator.h
Outdated
@@ -238,46 +238,58 @@ class InferShapeContext { | |||
} | |||
|
|||
const Variable* InputVar(const std::string& name) const { | |||
return scope_.FindVar(op_.Input(name)); | |||
auto ipt = op_.Input(name); | |||
if (ipt == kEmptyVarName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
return ipt == kEmptyVarName ? nullptr : scope_.FindVar(ipt);
can make the code shorter.
paddle/framework/operator.cc
Outdated
PADDLE_THROW("Op %s input %s should contain only one variable", type_, | ||
name); | ||
return ""; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string OperatorBase::Input(const std::string& name) const {
auto& ins = Inputs(name);
PADDLE_ENFORCE(ins.size() <= 1, ".....");
return ins.empty() ? kEmptyVarName : ins[0];
}
The code is much shorter.
paddle/framework/operator.cc
Outdated
PADDLE_THROW("Op %s output %s should contain only one variable", type_, | ||
name); | ||
return ""; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment on OperatorBase::Input()
.
是不是应该在construct op的时候检查input output参数列表是否完整? |
ae85ed2
to
d7a1e40
Compare
@jacquesqiao @Canpio All things done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…nput_and_output Make operator Input/Output can return nullptr
Fix #3822