提交 f5aa8b4d 编写于 作者: F fengjiayi

Update namespace of pybind/protobuf.cc and .h

上级 d633bdf1
......@@ -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_<ProgramDesc>(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_<BlockDesc>(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_<VarDesc>(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 &parameter,
const std::vector<std::string> &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
......@@ -25,7 +25,7 @@ limitations under the License. */
namespace py = pybind11;
namespace paddle {
namespace framework {
namespace pybind {
template <typename T>
inline std::vector<T> 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
......@@ -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):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册