提交 332369ca 编写于 作者: F fengjiayi

Add `new_var` for BlockDesc

上级 65bec3be
...@@ -321,18 +321,19 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -321,18 +321,19 @@ All parameter, weight, gradient are variables in Paddle.
py::return_value_policy::reference) py::return_value_policy::reference)
.def("append_block", .def("append_block",
[](ProgramDesc &self, BlockDesc &parent) { [](ProgramDesc &self, BlockDesc &parent) {
auto desc = self.mutable_blocks()->Add(); auto desc = self.add_blocks();
desc->set_idx(self.mutable_blocks()->size() - 1); desc->set_idx(self.mutable_blocks()->size() - 1);
desc->set_parent_idx(parent.idx()); desc->set_parent_idx(parent.idx());
return desc; return desc;
}) })
.def("root_block", .def("root_block",
[](ProgramDesc &self) { return self.mutable_blocks()[0]; }); [](ProgramDesc &self) { return self.mutable_blocks()[0]; });
py::class_<BlockDesc>(m, "BlockDesc", "") py::class_<BlockDesc>(m, "BlockDesc", "")
.def("idx", [](BlockDesc &self) { return self.idx(); }) .def("idx", [](BlockDesc &self) { return self.idx(); })
.def("parent", [](BlockDesc &self) { return self.parent_idx(); }) .def("parent", [](BlockDesc &self) { return self.parent_idx(); })
.def("append_op", .def("append_op", [](BlockDesc &self) { return self.add_ops(); })
[](BlockDesc &self) { return self.mutable_ops()->Add(); }); .def("new_var", [](BlockDesc &self) { return self.add_vars(); });
py::class_<VarDesc>(m, "VarDesc", "") py::class_<VarDesc>(m, "VarDesc", "")
.def(py::init<>()) .def(py::init<>())
...@@ -372,7 +373,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -372,7 +373,7 @@ All parameter, weight, gradient are variables in Paddle.
}; };
auto op_desc_set_attr = [](OpDesc &desc, const std::string &name) { auto op_desc_set_attr = [](OpDesc &desc, const std::string &name) {
auto attr = desc.mutable_attrs()->Add(); auto attr = desc.add_attrs();
attr->set_name(name); attr->set_name(name);
return attr; return attr;
}; };
...@@ -383,7 +384,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -383,7 +384,7 @@ All parameter, weight, gradient are variables in Paddle.
[op_desc_set_var](OpDesc &self, [op_desc_set_var](OpDesc &self,
const std::string &parameter, const std::string &parameter,
const std::vector<std::string> &arguments) { const std::vector<std::string> &arguments) {
auto ipt = self.mutable_inputs()->Add(); auto ipt = self.add_inputs();
op_desc_set_var(ipt, parameter, arguments); op_desc_set_var(ipt, parameter, arguments);
}) })
.def("input_names", .def("input_names",
...@@ -402,7 +403,7 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -402,7 +403,7 @@ All parameter, weight, gradient are variables in Paddle.
[op_desc_set_var](OpDesc &self, [op_desc_set_var](OpDesc &self,
const std::string &parameter, const std::string &parameter,
const std::vector<std::string> &arguments) { const std::vector<std::string> &arguments) {
auto opt = self.mutable_outputs()->Add(); auto opt = self.add_outputs();
op_desc_set_var(opt, parameter, arguments); op_desc_set_var(opt, parameter, arguments);
}) })
.def("set_attr", .def("set_attr",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册