update Opdesc's HasAttr

test=develop
ce_debug
luotao1 6 years ago
parent 6776e92846
commit fe915901cd

@ -237,6 +237,17 @@ void OpDesc::SetOutput(const std::string &param_name,
this->outputs_[param_name] = args;
}
bool OpDesc::HasAttr(const std::string &name) const {
const proto::OpProto &proto = OpInfoMap::Instance().Get(desc_.type()).Proto();
for (int i = 0; i != proto.attrs_size(); ++i) {
const proto::OpProto::Attr &attr = proto.attrs(i);
if (attr.name() == name) {
return true;
}
}
return false;
}
proto::AttrType OpDesc::GetAttrType(const std::string &name) const {
auto it = attrs_.find(name);
PADDLE_ENFORCE(it != attrs_.end(), "Attribute %s is not found", name);

@ -61,9 +61,7 @@ class OpDesc {
void SetOutput(const std::string &param_name,
const std::vector<std::string> &args);
bool HasAttr(const std::string &name) const {
return attrs_.find(name) != attrs_.end();
}
bool HasAttr(const std::string &name) const;
proto::AttrType GetAttrType(const std::string &name) const;

Loading…
Cancel
Save