You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by jx...@apache.org on 2017/12/27 20:18:09 UTC
[incubator-mxnet] branch master updated: refactor graph exec (#9122)
This is an automated email from the ASF dual-hosted git repository.
jxie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new be40d31 refactor graph exec (#9122)
be40d31 is described below
commit be40d31b9663cc201e63125f48a6b51d094ad9ce
Author: Pedro Larroy <92...@users.noreply.github.com>
AuthorDate: Wed Dec 27 21:18:06 2017 +0100
refactor graph exec (#9122)
---
src/executor/graph_executor.cc | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/executor/graph_executor.cc b/src/executor/graph_executor.cc
index 6afb1a6..77853a6 100644
--- a/src/executor/graph_executor.cc
+++ b/src/executor/graph_executor.cc
@@ -157,7 +157,7 @@ nnvm::NodeEntry AggregateGradient(std::vector<nnvm::NodeEntry>&& v) {
static const Op* zeros_op = Op::Get("_zeros");
static const Op* zeros_like_op = Op::Get("zeros_like");
- if (v.size() == 0) {
+ if (v.empty()) {
nnvm::NodePtr ng = nnvm::Node::Create();
ng->attrs.op = zeros_op;
ng->attrs.name = "zeros";
@@ -166,17 +166,12 @@ nnvm::NodeEntry AggregateGradient(std::vector<nnvm::NodeEntry>&& v) {
}
// remove zero in the sum. at least keep 1.
- size_t begin = 0;
- for (size_t i = 0; i < v.size(); ++i) {
- if (v[i].node->op() != zeros_op && v[i].node->op() != zeros_like_op) {
- if (begin != i) {
- v[begin] = std::move(v[i]);
- }
- ++begin;
- }
- }
- if (begin == 0) begin = 1;
- v.resize(begin);
+ auto begin = std::remove_if(v.begin(), v.end(), [](const nnvm::NodeEntry& nodeEntry) {
+ return nodeEntry.node->op() == zeros_op || nodeEntry.node->op() == zeros_like_op;
+ });
+ if (begin == v.begin()) ++begin;
+ v.erase(begin, v.end());
+ CHECK(!v.empty());
if (v.size() == 1) {
return std::move(v[0]);
--
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].