You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by ma...@apache.org on 2018/09/18 16:32:58 UTC

[incubator-mxnet] branch master updated: [MXNET-860] Reduce redundant copies, check for regressions with clang-tidy (#12355)

This is an automated email from the ASF dual-hosted git repository.

marcoabreu 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 7168254  [MXNET-860] Reduce redundant copies, check for regressions with clang-tidy (#12355)
7168254 is described below

commit 7168254da55e710590125ca165dfa2c436815f72
Author: Kellen Sunderland <ke...@gmail.com>
AuthorDate: Tue Sep 18 18:32:46 2018 +0200

    [MXNET-860] Reduce redundant copies, check for regressions with clang-tidy (#12355)
    
    * [MXNET-860] - Fix some unneeded copies
    
    * [MXNET-860] - Add unnecessary copy check to clang-tidy
---
 .clang-tidy                       | 2 +-
 src/ndarray/ndarray.cc            | 4 ++--
 src/operator/contrib/roi_align.cc | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
index 993656e..c84ba32 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -54,7 +54,7 @@ Checks: >
 
 # In order to trigger an error, you must have a rule defined both in checks and in this section.
 WarningsAsErrors: >
-    cppcoreguidelines-no-malloc
+    cppcoreguidelines-no-malloc, performance-unnecessary-copy-initialization
 
 # Todo: define a better regex match that includes most project headers, but excludes third party
 # code.
diff --git a/src/ndarray/ndarray.cc b/src/ndarray/ndarray.cc
index 853838a..ddffa28 100644
--- a/src/ndarray/ndarray.cc
+++ b/src/ndarray/ndarray.cc
@@ -1031,7 +1031,7 @@ inline void CopyFromToRspImpl(const NDArray& from, const NDArray& to, RunContext
     op::FillZerosRspImpl(s, to);
     return;
   }
-  auto aux_shape = from.aux_shape(rowsparse::kIdx);
+  const auto& aux_shape = from.aux_shape(rowsparse::kIdx);
   to.CheckAndAlloc({aux_shape});
   TBlob val = to.data();
   TBlob idx = to.aux_data(rowsparse::kIdx);
@@ -1122,7 +1122,7 @@ void CopyFromToImpl(const NDArray& from, const NDArray& to,
     if (from_stype == to_stype) {
       casted_nd = from;  // same stype, no need to cast from
     } else {  // different stypes on different ctx needs an temporary casted_nd
-      TShape shape = from.shape();
+      const TShape& shape = from.shape();
       if (to_stype == kDefaultStorage) {
         casted_nd = NDArray(shape, from_ctx);
       } else {
diff --git a/src/operator/contrib/roi_align.cc b/src/operator/contrib/roi_align.cc
index 65ee626..3ce2213 100644
--- a/src/operator/contrib/roi_align.cc
+++ b/src/operator/contrib/roi_align.cc
@@ -422,7 +422,7 @@ void ROIAlignForwardCompute(const nnvm::NodeAttrs& attrs,
   CHECK_EQ(out_data.size(), expected_out);
   CHECK_EQ(out_data[roialign::kOut].shape_[0], in_data[roialign::kBox].shape_[0]);
 
-  const ROIAlignParam param = nnvm::get<ROIAlignParam>(attrs.parsed);
+  const ROIAlignParam& param = nnvm::get<ROIAlignParam>(attrs.parsed);
 
   const int count = out_data[roialign::kOut].Size();
   // const int num_rois = in_data[roialign::kBox].size(0);
@@ -466,7 +466,7 @@ void ROIAlignBackwardCompute(const nnvm::NodeAttrs& attrs,
   CHECK_NE(req[1], kWriteInplace) <<
     "ROIAlign: Backward doesn't support kWriteInplace.";
 
-  const ROIAlignParam param = nnvm::get<ROIAlignParam>(attrs.parsed);
+  const ROIAlignParam& param = nnvm::get<ROIAlignParam>(attrs.parsed);
 
   const int count = out_grad[0].Size();
   const int num_rois = in_data[0].size(0);
@@ -534,7 +534,7 @@ He, Kaiming, et al. "Mask R-CNN." ICCV, 2017
 .set_attr<nnvm::FInferShape>("FInferShape", [](const nnvm::NodeAttrs& attrs,
       std::vector<TShape> *in_shape, std::vector<TShape> *out_shape){
   using namespace mshadow;
-  const ROIAlignParam param = nnvm::get<ROIAlignParam>(attrs.parsed);
+  const ROIAlignParam& param = nnvm::get<ROIAlignParam>(attrs.parsed);
   CHECK_EQ(in_shape->size(), 2) << "Input:[data, rois]";
   // data: [batch_size, c, h, w]
   TShape dshape = in_shape->at(roialign::kData);