From 225579b9d9ab28de046805f40301d68d9dd3b5cb Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Thu, 17 Aug 2017 11:10:32 +0800 Subject: [PATCH] Remove own for add_op * add_op could take a unique_ptr or a const reference. If unique_ptr is taken, the NetOp will take care of that operator's life cycle. If a const reference is taken, that op will be Cloned. --- paddle/operators/net_op.h | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/paddle/operators/net_op.h b/paddle/operators/net_op.h index ce7da1f3836..e8720c96099 100644 --- a/paddle/operators/net_op.h +++ b/paddle/operators/net_op.h @@ -89,33 +89,18 @@ class NetOp : public framework::OperatorBase { /** * @brief Add an operator by ptr */ - void AddOp(framework::OperatorBase* op, bool own) { + void AddOp(std::unique_ptr&& op) { PADDLE_ENFORCE(!add_op_done_, "Cannot AddOp when this network is sealed"); PADDLE_ENFORCE_NOT_NULL(op, "Cannot Insert Null op"); - if (!own) { - op = op->Clone().release(); - } - ops_.emplace_back(op); - } - - void AddOp(std::unique_ptr&& op) { - AddOp(op.release(), true); + ops_.push_back(std::move(op)); } - void InsertOp(size_t pos, framework::OperatorBase* op, bool own) { + void InsertOp(size_t pos, std::unique_ptr&& op) { PADDLE_ENFORCE(!add_op_done_, "Cannot InsertOp when this network is sealed"); PADDLE_ENFORCE_NOT_NULL(op, "Cannot Insert Null op"); PADDLE_ENFORCE_LE(pos, ops_.size(), "Out of range"); - if (!own) { - op = op->Clone().release(); - } - ops_.insert(ops_.begin() + pos, - std::unique_ptr(op)); - } - - void InsertOp(size_t pos, std::unique_ptr&& op) { - InsertOp(pos, op.release(), true); + ops_.insert(ops_.begin() + pos, std::move(op)); } void InsertOp(size_t pos, const framework::OperatorBase& op) { -- GitLab