From f5aa8b4d7ef508dcd66984ef36012eeff63a9c85 Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Fri, 22 Sep 2017 13:22:21 -0700 Subject: [PATCH] Update namespace of pybind/protobuf.cc and .h --- paddle/pybind/protobuf.cc | 11 +++++++++-- paddle/pybind/protobuf.h | 4 ++-- .../paddle/v2/framework/tests/test_protobuf_descs.py | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/paddle/pybind/protobuf.cc b/paddle/pybind/protobuf.cc index 47b3c43ebf..bfbe177e8f 100644 --- a/paddle/pybind/protobuf.cc +++ b/paddle/pybind/protobuf.cc @@ -15,9 +15,10 @@ limitations under the License. */ #include "paddle/pybind/protobuf.h" namespace paddle { -namespace framework { +namespace pybind { void BindProgramDesc(py::module &m) { + using namespace paddle::framework; // NOLINT py::class_(m, "ProgramDesc", "") .def_static("instance", [] { return &GetProgramDesc(); }, @@ -42,10 +43,14 @@ void BindProgramDesc(py::module &m) { .def("root_block", [](ProgramDesc &self) { return self.mutable_blocks()->Mutable(0); }, py::return_value_policy::reference) + .def("block", + [](ProgramDesc &self, int id) { return self.blocks(id); }, + py::return_value_policy::reference) .def("__str__", [](ProgramDesc &self) { return self.DebugString(); }); } void BindBlockDesc(py::module &m) { + using namespace paddle::framework; // NOLINT py::class_(m, "BlockDesc", "") .def("id", [](BlockDesc &self) { return self.idx(); }) .def("parent", [](BlockDesc &self) { return self.parent_idx(); }) @@ -58,6 +63,7 @@ void BindBlockDesc(py::module &m) { } void BindVarDsec(py::module &m) { + using namespace paddle::framework; // NOLINT py::class_(m, "VarDesc", "") .def(py::init<>()) .def("set_name", @@ -86,6 +92,7 @@ void BindVarDsec(py::module &m) { } void BindOpDesc(py::module &m) { + using namespace paddle::framework; // NOLINT auto op_desc_set_var = [](OpDesc::Var *var, const std::string ¶meter, const std::vector &arguments) { @@ -132,5 +139,5 @@ void BindOpDesc(py::module &m) { op_desc_set_attr(self, name)->set_i(i); }); } -} // namespace framework +} // namespace pybind } // namespace paddle diff --git a/paddle/pybind/protobuf.h b/paddle/pybind/protobuf.h index a32acfb038..de9a008e25 100644 --- a/paddle/pybind/protobuf.h +++ b/paddle/pybind/protobuf.h @@ -25,7 +25,7 @@ limitations under the License. */ namespace py = pybind11; namespace paddle { -namespace framework { +namespace pybind { template inline std::vector RepeatedToVector( @@ -50,5 +50,5 @@ void BindProgramDesc(py::module& m); void BindBlockDesc(py::module& m); void BindVarDsec(py::module& m); void BindOpDesc(py::module& m); -} // namespace framework +} // namespace pybind } // namespace paddle diff --git a/python/paddle/v2/framework/tests/test_protobuf_descs.py b/python/paddle/v2/framework/tests/test_protobuf_descs.py index 71bdca8765..d0192814ef 100644 --- a/python/paddle/v2/framework/tests/test_protobuf_descs.py +++ b/python/paddle/v2/framework/tests/test_protobuf_descs.py @@ -23,6 +23,7 @@ class TestProgramDesc(unittest.TestCase): self.assertEqual(block_root.id(), block1.parent()) block3 = prog_desc.append_block(block_root) self.assertEqual(block3.parent(), block_root.id()) + self.assertEqual(prog_desc.block(1).id(), 1) class TestVarDesc(unittest.TestCase): -- GitLab