提交 f5aa8b4d 编写于 作者: F fengjiayi

Update namespace of pybind/protobuf.cc and .h

上级 d633bdf1
...@@ -15,9 +15,10 @@ limitations under the License. */ ...@@ -15,9 +15,10 @@ limitations under the License. */
#include "paddle/pybind/protobuf.h" #include "paddle/pybind/protobuf.h"
namespace paddle { namespace paddle {
namespace framework { namespace pybind {
void BindProgramDesc(py::module &m) { void BindProgramDesc(py::module &m) {
using namespace paddle::framework; // NOLINT
py::class_<ProgramDesc>(m, "ProgramDesc", "") py::class_<ProgramDesc>(m, "ProgramDesc", "")
.def_static("instance", .def_static("instance",
[] { return &GetProgramDesc(); }, [] { return &GetProgramDesc(); },
...@@ -42,10 +43,14 @@ void BindProgramDesc(py::module &m) { ...@@ -42,10 +43,14 @@ void BindProgramDesc(py::module &m) {
.def("root_block", .def("root_block",
[](ProgramDesc &self) { return self.mutable_blocks()->Mutable(0); }, [](ProgramDesc &self) { return self.mutable_blocks()->Mutable(0); },
py::return_value_policy::reference) 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(); }); .def("__str__", [](ProgramDesc &self) { return self.DebugString(); });
} }
void BindBlockDesc(py::module &m) { void BindBlockDesc(py::module &m) {
using namespace paddle::framework; // NOLINT
py::class_<BlockDesc>(m, "BlockDesc", "") py::class_<BlockDesc>(m, "BlockDesc", "")
.def("id", [](BlockDesc &self) { return self.idx(); }) .def("id", [](BlockDesc &self) { return self.idx(); })
.def("parent", [](BlockDesc &self) { return self.parent_idx(); }) .def("parent", [](BlockDesc &self) { return self.parent_idx(); })
...@@ -58,6 +63,7 @@ void BindBlockDesc(py::module &m) { ...@@ -58,6 +63,7 @@ void BindBlockDesc(py::module &m) {
} }
void BindVarDsec(py::module &m) { void BindVarDsec(py::module &m) {
using namespace paddle::framework; // NOLINT
py::class_<VarDesc>(m, "VarDesc", "") py::class_<VarDesc>(m, "VarDesc", "")
.def(py::init<>()) .def(py::init<>())
.def("set_name", .def("set_name",
...@@ -86,6 +92,7 @@ void BindVarDsec(py::module &m) { ...@@ -86,6 +92,7 @@ void BindVarDsec(py::module &m) {
} }
void BindOpDesc(py::module &m) { void BindOpDesc(py::module &m) {
using namespace paddle::framework; // NOLINT
auto op_desc_set_var = [](OpDesc::Var *var, auto op_desc_set_var = [](OpDesc::Var *var,
const std::string &parameter, const std::string &parameter,
const std::vector<std::string> &arguments) { const std::vector<std::string> &arguments) {
...@@ -132,5 +139,5 @@ void BindOpDesc(py::module &m) { ...@@ -132,5 +139,5 @@ void BindOpDesc(py::module &m) {
op_desc_set_attr(self, name)->set_i(i); op_desc_set_attr(self, name)->set_i(i);
}); });
} }
} // namespace framework } // namespace pybind
} // namespace paddle } // namespace paddle
...@@ -25,7 +25,7 @@ limitations under the License. */ ...@@ -25,7 +25,7 @@ limitations under the License. */
namespace py = pybind11; namespace py = pybind11;
namespace paddle { namespace paddle {
namespace framework { namespace pybind {
template <typename T> template <typename T>
inline std::vector<T> RepeatedToVector( inline std::vector<T> RepeatedToVector(
...@@ -50,5 +50,5 @@ void BindProgramDesc(py::module& m); ...@@ -50,5 +50,5 @@ void BindProgramDesc(py::module& m);
void BindBlockDesc(py::module& m); void BindBlockDesc(py::module& m);
void BindVarDsec(py::module& m); void BindVarDsec(py::module& m);
void BindOpDesc(py::module& m); void BindOpDesc(py::module& m);
} // namespace framework } // namespace pybind
} // namespace paddle } // namespace paddle
...@@ -23,6 +23,7 @@ class TestProgramDesc(unittest.TestCase): ...@@ -23,6 +23,7 @@ class TestProgramDesc(unittest.TestCase):
self.assertEqual(block_root.id(), block1.parent()) self.assertEqual(block_root.id(), block1.parent())
block3 = prog_desc.append_block(block_root) block3 = prog_desc.append_block(block_root)
self.assertEqual(block3.parent(), block_root.id()) self.assertEqual(block3.parent(), block_root.id())
self.assertEqual(prog_desc.block(1).id(), 1)
class TestVarDesc(unittest.TestCase): class TestVarDesc(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册