From afeb01f7620a2280c946f359065589d8b0d59062 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Fri, 22 Sep 2017 18:30:05 -0700 Subject: [PATCH] Stash --- paddle/pybind/protobuf.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/paddle/pybind/protobuf.cc b/paddle/pybind/protobuf.cc index 67d6252af..345bb02c8 100644 --- a/paddle/pybind/protobuf.cc +++ b/paddle/pybind/protobuf.cc @@ -114,6 +114,14 @@ public: std::string DebugString() { return this->Proto()->DebugString(); } + struct SetAttrDescVisitor : public boost::static_visitor { + explicit SetAttrDescVisitor(OpDesc::Attr *attr) : attr_(attr) {} + OpDesc::Attr *attr_; + void operator()(int v) { attr_->set_i(v); } + void operator()(float v) { attr_->set_f(v); } + void operator()(const std::string &v) { attr_->set_s(v); } + }; + void Sync() { if (need_update_) { this->op_desc_.mutable_inputs()->Clear(); @@ -130,6 +138,13 @@ public: VectorToRepeated(opt.second, output->mutable_arguments()); } + this->op_desc_.mutable_attrs()->Clear(); + for (auto &attr : attrs_) { + auto *attr_desc = op_desc_.add_attrs(); + attr_desc->set_name(attr.first); + attr_desc->set_type(static_cast(attr.second.which() - 1)); + } + need_update_ = false; } } -- GitLab