[mir] Pass aggregate arguments by const reference (#7143)
authorСергей Баранников/AI Tools Lab /SRR/Engineer/삼성전자 <s.barannikov@samsung.com>
Tue, 3 Sep 2019 18:38:46 +0000 (21:38 +0300)
committerAlexander Efimov/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Tue, 3 Sep 2019 18:38:46 +0000 (21:38 +0300)
clang-tidy suggests to pass by value and use `std::move`, but it is easy to forget and does not give significant benefits.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
13 files changed:
compiler/mir/include/mir/Shape.h
compiler/mir/include/mir/ops/AvgPool2DOp.h
compiler/mir/include/mir/ops/Conv2DOp.h
compiler/mir/include/mir/ops/DepthwiseConv2DOp.h
compiler/mir/include/mir/ops/MaxPool2DOp.h
compiler/mir/include/mir/ops/PadOp.h
compiler/mir/include/mir/ops/ReduceMeanOp.h
compiler/mir/include/mir/ops/ReduceOp.h
compiler/mir/include/mir/ops/ResizeOp.h
compiler/mir/include/mir/ops/SqueezeOp.h
compiler/mir/include/mir/ops/TransposeOp.h
compiler/mir/src/ops/TransposeOp.cpp
compiler/mir/unittests/ShapeRange.cpp

index f3082e8..18fa812 100644 (file)
@@ -40,7 +40,8 @@ public:
 
   Shape(std::initializer_list<int32_t> &&dims) : _dims(std::move(dims)) {}
 
-  explicit Shape(const std::vector<int32_t> &dims) : _dims(std::begin(dims), std::end(dims)) {}
+  // TODO Make it 'explicit'.
+  Shape(const std::vector<int32_t> &dims) : _dims(std::begin(dims), std::end(dims)) {}
 
   int32_t rank() const { return static_cast<int32_t>(_dims.size()); }
 
index 394e537..c53cd79 100644 (file)
@@ -31,12 +31,13 @@ namespace ops
 class AvgPool2DOp : public Operation
 {
 public:
-  AvgPool2DOp(Output *arg, std::vector<std::int32_t> window_size, std::vector<std::int32_t> strides,
-              std::vector<std::int32_t> padding_before, std::vector<std::int32_t> padding_after,
-              bool include_pad, DataFormat data_format)
-      : Operation(Type::avgPool2D, {arg}), _window_size(std::move(window_size)),
-        _strides(std::move(strides)), _padding_before(std::move(padding_before)),
-        _padding_after(std::move(padding_after)), _include_pad(include_pad),
+  AvgPool2DOp(Output *arg, const std::vector<std::int32_t> &window_size,
+              const std::vector<std::int32_t> &strides,
+              const std::vector<std::int32_t> &padding_before,
+              const std::vector<std::int32_t> &padding_after, bool include_pad,
+              DataFormat data_format)
+      : Operation(Type::avgPool2D, {arg}), _window_size(window_size), _strides(strides),
+        _padding_before(padding_before), _padding_after(padding_after), _include_pad(include_pad),
         _data_format(data_format)
   {
     inferOutputShapes();
index cfb9723..7acd2fd 100644 (file)
@@ -29,11 +29,12 @@ namespace ops
 class Conv2DOp : public Operation
 {
 public:
-  Conv2DOp(Output *input, Output *kernel, const Shape &strides, std::vector<int32_t> padding_before,
-           std::vector<int32_t> padding_after, DataFormat data_format = DataFormat::NHWC)
+  Conv2DOp(Output *input, Output *kernel, const Shape &strides,
+           const std::vector<std::int32_t> &padding_before,
+           const std::vector<std::int32_t> &padding_after,
+           DataFormat data_format = DataFormat::NHWC)
       : Operation(Type::conv2D, {input, kernel}), _strides(strides),
-        _padding_before(std::move(padding_before)), _padding_after(std::move(padding_after)),
-        _data_format(data_format)
+        _padding_before(padding_before), _padding_after(padding_after), _data_format(data_format)
   {
     inferOutputShapes();
   }
index 6198a72..e4c9790 100644 (file)
@@ -30,11 +30,11 @@ class DepthwiseConv2DOp : public Operation
 {
 public:
   DepthwiseConv2DOp(Output *input, Output *kernel, const Shape &strides,
-                    std::vector<int32_t> padding_before, std::vector<int32_t> padding_after,
+                    const std::vector<std::int32_t> &padding_before,
+                    const std::vector<std::int32_t> &padding_after,
                     DataFormat data_format = DataFormat::NHWC)
       : Operation(Type::depthwiseConv, {input, kernel}), _strides(strides),
-        _padding_before(std::move(padding_before)), _padding_after(std::move(padding_after)),
-        _data_format(data_format)
+        _padding_before(padding_before), _padding_after(padding_after), _data_format(data_format)
   {
     inferOutputShapes();
   }
index 691fad4..2a9d55c 100644 (file)
@@ -31,12 +31,12 @@ namespace ops
 class MaxPool2DOp : public Operation
 {
 public:
-  MaxPool2DOp(Output *arg, std::vector<std::int32_t> window_size, std::vector<std::int32_t> strides,
-              std::vector<std::int32_t> padding_before, std::vector<std::int32_t> padding_after,
-              DataFormat data_format)
-      : Operation(Type::maxPool2D, {arg}), _window_size(std::move(window_size)),
-        _strides(std::move(strides)), _padding_before(std::move(padding_before)),
-        _padding_after(std::move(padding_after)), _data_format(data_format)
+  MaxPool2DOp(Output *arg, const std::vector<std::int32_t> &window_size,
+              const std::vector<std::int32_t> &strides,
+              const std::vector<std::int32_t> &padding_before,
+              const std::vector<std::int32_t> &padding_after, DataFormat data_format)
+      : Operation(Type::maxPool2D, {arg}), _window_size(window_size), _strides(strides),
+        _padding_before(padding_before), _padding_after(padding_after), _data_format(data_format)
   {
     inferOutputShapes();
   }
index e1e59f3..1b109e5 100644 (file)
@@ -31,10 +31,10 @@ public:
   /// @param padding_before The padding to be added before the tensor.
   /// @param padding_after The padding to be added after the tensor.
   /// @param padding_value The value to be used for padding.
-  PadOp(Output *arg, std::vector<std::int32_t> padding_before,
-        std::vector<std::int32_t> padding_after, float padding_value)
-      : Operation(Type::pad, {arg}), _padding_before(std::move(padding_before)),
-        _padding_after(std::move(padding_after)), _padding_value(padding_value)
+  PadOp(Output *arg, const std::vector<std::int32_t> &padding_before,
+        const std::vector<std::int32_t> &padding_after, float padding_value)
+      : Operation(Type::pad, {arg}), _padding_before(padding_before), _padding_after(padding_after),
+        _padding_value(padding_value)
   {
     assert(_padding_before.size() == _padding_after.size());
     inferOutputShapes();
index 957bd7e..add47ac 100644 (file)
@@ -28,8 +28,8 @@ namespace ops
 class ReduceMeanOp : public ReduceOp
 {
 public:
-  ReduceMeanOp(Output *arg, std::vector<int> reduction_dims, bool keep_dims)
-      : ReduceOp(Type::reduceMean, arg, std::move(reduction_dims), keep_dims)
+  ReduceMeanOp(Output *arg, const std::vector<int> &reduction_dims, bool keep_dims)
+      : ReduceOp(Type::reduceMean, arg, reduction_dims, keep_dims)
   {
   }
 
index a9171a1..f8a2de8 100644 (file)
@@ -28,8 +28,8 @@ namespace ops
 class ReduceOp : public Operation
 {
 protected:
-  ReduceOp(Type type, Output *arg, std::vector<int> reduction_dims, bool keep_dims)
-      : Operation(type, {arg}), _reduction_dims(std::move(reduction_dims)), _keep_dims(keep_dims)
+  ReduceOp(Type type, Output *arg, const std::vector<int> &reduction_dims, bool keep_dims)
+      : Operation(type, {arg}), _reduction_dims(reduction_dims), _keep_dims(keep_dims)
   {
     inferOutputShapes();
   }
index a8ca393..d4ef4a2 100644 (file)
@@ -39,8 +39,8 @@ public:
     nearestNeighbor, // TODO: BICUBIC and BILINEAR
   };
 
-  ResizeOp(Output *arg, ResizeMethod mode, std::vector<float> scales)
-      : Operation(Type::resizeIm, {arg}), _mode(mode), _scales(std::move(scales))
+  ResizeOp(Output *arg, ResizeMethod mode, const std::vector<float> &scales)
+      : Operation(Type::resizeIm, {arg}), _mode(mode), _scales(scales)
   {
     // Infer output shape based on given scales.
     auto &input_shape = getInputShape(0);
index bc90e8c..23e119e 100644 (file)
@@ -28,8 +28,8 @@ namespace ops
 class SqueezeOp : public Operation
 {
 public:
-  SqueezeOp(Output *arg, std::vector<int32_t> dims_to_squeeze)
-      : Operation(Type::squeeze, {arg}), _dims_to_squeeze(std::move(dims_to_squeeze))
+  SqueezeOp(Output *arg, const std::vector<std::int32_t> &dims_to_squeeze)
+      : Operation(Type::squeeze, {arg}), _dims_to_squeeze(dims_to_squeeze)
   {
     // Infer output shape.
     inferOutputShapes();
index 001eedf..53fa084 100644 (file)
@@ -33,7 +33,7 @@ namespace ops
 class TransposeOp : public Operation
 {
 public:
-  TransposeOp(Output *arg, std::vector<std::size_t> axis_order);
+  TransposeOp(Output *arg, const std::vector<std::size_t> &axis_order);
 
   const std::vector<std::size_t> &getAxisOrder() const { return _axis_order; }
 
index 9d7f1ea..d626506 100644 (file)
@@ -21,8 +21,8 @@ namespace mir
 namespace ops
 {
 
-TransposeOp::TransposeOp(Output *arg, std::vector<std::size_t> axis_order)
-    : Operation(Type::transpose, {arg}), _axis_order(std::move(axis_order))
+TransposeOp::TransposeOp(Output *arg, const std::vector<std::size_t> &axis_order)
+    : Operation(Type::transpose, {arg}), _axis_order(axis_order)
 {
   assert(_axis_order.size() == static_cast<std::size_t>(getInputShape(0).rank()));
   inferOutputShapes();
@@ -33,7 +33,7 @@ void TransposeOp::inferOutputShapes()
   auto &input_shape = getInputShape(0);
   Shape output_shape(input_shape.rank());
   for (std::size_t i = 0; i < _axis_order.size(); ++i)
-    output_shape.dim(static_cast<int32_t>(i)) =
+    output_shape.dim(static_cast<std::int64_t>(i)) =
         input_shape.dim(static_cast<int32_t>(_axis_order.at(i)));
   setOutputShape(0, output_shape);
 }
index 30d151b..3b32d0c 100644 (file)
@@ -75,4 +75,4 @@ TEST(ShapeRange, Contains)
         ASSERT_TRUE(range.contains(idx));
     }
 }
-}
+} // namespace