From fe915901cdb7c0d55fe13890e3afafcce4cddbf9 Mon Sep 17 00:00:00 2001 From: luotao1 Date: Wed, 28 Nov 2018 20:54:46 +0800 Subject: [PATCH] update Opdesc's HasAttr test=develop --- paddle/fluid/framework/op_desc.cc | 11 +++++++++++ paddle/fluid/framework/op_desc.h | 4 +--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/framework/op_desc.cc b/paddle/fluid/framework/op_desc.cc index e8ecd905029..a31c5336a1a 100644 --- a/paddle/fluid/framework/op_desc.cc +++ b/paddle/fluid/framework/op_desc.cc @@ -237,6 +237,17 @@ void OpDesc::SetOutput(const std::string ¶m_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); diff --git a/paddle/fluid/framework/op_desc.h b/paddle/fluid/framework/op_desc.h index 30c8a26c3d2..3da7cdcef39 100644 --- a/paddle/fluid/framework/op_desc.h +++ b/paddle/fluid/framework/op_desc.h @@ -61,9 +61,7 @@ class OpDesc { void SetOutput(const std::string ¶m_name, const std::vector &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; -- GitLab