diff --git a/paddle/pybind/protobuf.cc b/paddle/pybind/protobuf.cc index b4ed9c4335ab2a293b62fb523d9627046db42f19..0fb78bf7a242e33a39016c66e76535c90dcf0202 100644 --- a/paddle/pybind/protobuf.cc +++ b/paddle/pybind/protobuf.cc @@ -59,14 +59,7 @@ public: BlockDescBind(ProgramDescBind *prog, BlockDesc *desc) : prog_(prog), desc_(desc), need_update_(false) {} - ~BlockDescBind() { - std::cerr << "dtor " << this << "," << desc_ << std::endl; - } - - int32_t id() const { - std::cerr << "desc ptr " << desc_ << std::endl; - return desc_->idx(); - } + int32_t id() const { return desc_->idx(); } int32_t Parent() const { return desc_->parent_idx(); } @@ -114,11 +107,9 @@ public: return *ptr; } - BlockDescBind *AppendBlock(BlockDescBind *parent) { + BlockDescBind *AppendBlock(const BlockDescBind &parent) { auto *b = prog_->add_blocks(); - std::cerr << "block ptr " << b << std::endl; - std::cerr << "pass ptr " << parent << std::endl; - b->set_parent_idx(parent->id()); + b->set_parent_idx(parent.id()); b->set_idx(prog_->blocks_size() - 1); blocks_.emplace_back(this, b); return &blocks_.back(); @@ -141,6 +132,7 @@ public: private: explicit ProgramDescBind(ProgramDesc *prog) : prog_(prog) { + blocks_.reserve(100); for (auto &block : *prog->mutable_blocks()) { blocks_.emplace_back(this, &block); } @@ -181,7 +173,6 @@ void BindProgramDesc(py::module &m) { } void BindBlockDesc(py::module &m) { - using namespace paddle::framework; // NOLINT py::class_(m, "BlockDesc", "") .def_property_readonly("id", &BlockDescBind::id) .def_property_readonly("parent", &BlockDescBind::Parent) diff --git a/python/paddle/v2/framework/tests/test_protobuf_descs.py b/python/paddle/v2/framework/tests/test_protobuf_descs.py index b5ff2d4c36be7f7cfd0e3a794d7f50f27618ea21..fbe1f7152bb12dd7ddc69894a9ce2a892784d8f0 100644 --- a/python/paddle/v2/framework/tests/test_protobuf_descs.py +++ b/python/paddle/v2/framework/tests/test_protobuf_descs.py @@ -17,16 +17,12 @@ class TestProgramDesc(unittest.TestCase): self.assertIsNotNone(prog_desc) block_root = prog_desc.block(0) self.assertIsNotNone(block_root) - print 'here' self.assertEqual(block_root.id, 0) block1 = prog_desc.append_block(block_root) block2 = prog_desc.append_block(block1) self.assertIsNotNone(block1) - print 'here' self.assertEqual(block1.id, block2.parent) - print 'here' self.assertEqual(block_root.id, block1.parent) - print 'here' block3 = prog_desc.append_block(block_root) self.assertEqual(block3.parent, block_root.id) self.assertEqual(prog_desc.block(1).id, 1)