From 08e99006216395ee61f3dad3047dd44316829a66 Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Fri, 22 Sep 2017 18:29:25 -0700 Subject: [PATCH] Fix bugs --- paddle/pybind/protobuf.cc | 18 +++++++++--------- .../v2/framework/tests/test_protobuf_descs.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/paddle/pybind/protobuf.cc b/paddle/pybind/protobuf.cc index 126c2ce1c7d..de6db60730b 100644 --- a/paddle/pybind/protobuf.cc +++ b/paddle/pybind/protobuf.cc @@ -50,12 +50,12 @@ public: VarDesc *Proto() { return &desc_; } - void SetShape(const vector &dims) { + void SetShape(const std::vector &dims) { VectorToRepeated(dims, desc_.mutable_lod_tensor()->mutable_dims()); } void SetDataType(int type_id) { - desc_.mutable_lod_tensor()->set_data_type(const_cast(type_id)); + desc_.mutable_lod_tensor()->set_data_type(static_cast(type_id)); } std::vector Shape() { @@ -86,7 +86,8 @@ public: int32_t Parent() const { return desc_->parent_idx(); } - VarDescBind *NewVar(const std::string &name) { + VarDescBind *NewVar(py::bytes name_bytes) { + std::string name = name_bytes; need_update_ = true; auto it = vars_.find(name); PADDLE_ENFORCE(it == vars_.end(), "Duplicated variable %s", name); @@ -224,16 +225,15 @@ void BindBlockDesc(py::module &m) { &BlockDescBind::AppendOp, py::return_value_policy::reference) .def("new_var", - [](BlockDesc &self) { return self.add_vars(); }, + &BlockDescBind::NewVar, py::return_value_policy::reference); } void BindVarDsec(py::module &m) { - py::class_(m, "VarDesc", "") - .def(py::init<>()) - .def("set_shape", VarDescBind::SetShape) - .def("set_data_type", VarDescBind::SetDataType) - .def("shape", VarDescBind::Shape); + py::class_(m, "VarDesc", "") + .def("set_shape", &VarDescBind::SetShape) + .def("set_data_type", &VarDescBind::SetDataType) + .def("shape", &VarDescBind::Shape); } void BindOpDesc(py::module &m) { diff --git a/python/paddle/v2/framework/tests/test_protobuf_descs.py b/python/paddle/v2/framework/tests/test_protobuf_descs.py index fbe1f7152bb..f1074f6bb50 100644 --- a/python/paddle/v2/framework/tests/test_protobuf_descs.py +++ b/python/paddle/v2/framework/tests/test_protobuf_descs.py @@ -33,7 +33,7 @@ class TestVarDesc(unittest.TestCase): def test_shape(self): program_desc = core.ProgramDesc.instance() block = program_desc.root_block() - var = block.new_var() + var = block.new_var('my_var') src_shape = [3, 2, 10, 8] var.set_shape(src_shape) res_shape = var.shape() -- GitLab