提交 ec115140 编写于 作者: D Dong Zhihong

"fix findVar logic"

上级 b3df1f4a
...@@ -21,16 +21,19 @@ namespace framework { ...@@ -21,16 +21,19 @@ namespace framework {
VarDescBind *BlockDescBind::Var(const std::string &name) { VarDescBind *BlockDescBind::Var(const std::string &name) {
need_update_ = true; need_update_ = true;
auto it = vars_.find(name); auto it = vars_.find(name);
PADDLE_ENFORCE(it == vars_.end(), "Duplicated variable %s", name); if (it != vars_.end()) {
auto var = new VarDescBind(name); return it->secon.get();
}
auto *var = new VarDescBind(name);
vars_[name].reset(var); vars_[name].reset(var);
return var; return var;
} }
VarDescBind *BlockDescBind::FindVar(const std::string &name) const { VarDescBind *BlockDescBind::FindVar(const std::string &name) const {
auto it = vars_.find(name); auto it = vars_.find(name);
PADDLE_ENFORCE(it != vars_.end(), if (it == vars_.end()) {
"Can not find variable %s in current block.", name); return nullptr;
}
return it->second.get(); return it->second.get();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册