From 5ff184e298c7e36fc4fde65c0d0c594e4ff4e60f Mon Sep 17 00:00:00 2001 From: tom__chen Date: Tue, 27 Apr 2021 13:50:22 -0400 Subject: [PATCH] fix pclint warnings --- mindspore/core/abstract/param_validator.cc | 4 +-- mindspore/core/abstract/prim_arrays.cc | 14 ++++----- mindspore/core/abstract/prim_nn.cc | 36 +++++++++++----------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/mindspore/core/abstract/param_validator.cc b/mindspore/core/abstract/param_validator.cc index 8739c0249e..bae9f50ac3 100644 --- a/mindspore/core/abstract/param_validator.cc +++ b/mindspore/core/abstract/param_validator.cc @@ -166,7 +166,7 @@ void CheckShapeAnyAndPositive(const std::string &op, const ShapeVector &shape) { int64_t CheckAttrPositiveInt64(const std::string &op, const ValuePtr &attr, const std::string &attr_name) { int64_t attr_val = attr->cast()->value(); if (attr_val <= 0) { - MS_LOG(EXCEPTION) << "Invalid " << attr_name << " value: " << attr_val << ", should be greater then 0"; + MS_LOG(EXCEPTION) << op << " invalid " << attr_name << " value: " << attr_val << ", should be greater then 0"; } return attr_val; } @@ -182,7 +182,7 @@ std::vector CheckAttrIntOrTuple(const std::string &op, const ValuePtr & [](const ValuePtr &e) -> int64_t { return GetValue(e); }); } else { int64_t attr_val = attr->cast()->value(); - result.insert(result.begin(), num_element, attr_val); + (void)result.insert(result.begin(), num_element, attr_val); } return result; } diff --git a/mindspore/core/abstract/prim_arrays.cc b/mindspore/core/abstract/prim_arrays.cc index 68c36ae9b6..cc5ff66887 100644 --- a/mindspore/core/abstract/prim_arrays.cc +++ b/mindspore/core/abstract/prim_arrays.cc @@ -877,21 +877,21 @@ AbstractBasePtr InferImplSplit(const AnalysisEnginePtr &, const PrimitivePtr &pr ValuePtr axis = primitive->GetAttr("axis"); int64_t axis_value = CheckAxis(op_name, axis, -(rank + 1), rank); - axis_value = GetPositiveAxis(axis_value, LongToSize(rank)); + uint64_t axis_value_pos = LongToUlong(GetPositiveAxis(axis_value, LongToSize(rank))); int64_t output_num_value = primitive->GetAttr("output_num")->cast()->value(); - if ((x_shape[axis_value] != Shape::SHP_ANY) && (x_shape[axis_value] % output_num_value != 0)) { - MS_LOG(EXCEPTION) << "x_shape[" << axis_value << "] = " << x_shape[axis_value] + if ((x_shape[axis_value_pos] != Shape::SHP_ANY) && (x_shape[axis_value_pos] % output_num_value != 0)) { + MS_LOG(EXCEPTION) << "x_shape[" << axis_value_pos << "] = " << x_shape[axis_value_pos] << " must be divisible by output_num = " << output_num_value; } ShapeVector output_shape = x_shape; - if (output_shape[axis_value] != Shape::SHP_ANY) { - output_shape[axis_value] = static_cast(x_shape[axis_value] / output_num_value); + if (output_shape[axis_value_pos] != Shape::SHP_ANY) { + output_shape[axis_value_pos] = static_cast(x_shape[axis_value_pos] / output_num_value); } ShapeVector output_shape_min = x_shape_min; - output_shape_min[axis_value] = static_cast(x_shape_min[axis_value] / output_num_value); + output_shape_min[axis_value_pos] = static_cast(x_shape_min[axis_value_pos] / output_num_value); ShapeVector output_shape_max = x_shape_max; - output_shape_max[axis_value] = static_cast(x_shape_max[axis_value] / output_num_value); + output_shape_max[axis_value_pos] = static_cast(x_shape_max[axis_value_pos] / output_num_value); AbstractBasePtrList output_list; for (int64_t i = 0; i < output_num_value; ++i) { diff --git a/mindspore/core/abstract/prim_nn.cc b/mindspore/core/abstract/prim_nn.cc index aa027fc0ca..d9ae0e73cb 100644 --- a/mindspore/core/abstract/prim_nn.cc +++ b/mindspore/core/abstract/prim_nn.cc @@ -230,28 +230,28 @@ void Conv2DPadFunction(std::vector *output_hw, std::vector *pa const std::vector &dilation, const int64_t &pad_mode, const std::vector &padding) { if (pad_mode == PadMode::VALID) { - output_hw->push_back(std::ceil(((x_h * 1.0) - dilation[0] * (kernel[0] - 1)) / stride[0])); - output_hw->push_back(std::ceil(((x_w * 1.0) - dilation[1] * (kernel[1] - 1)) / stride[1])); - pad_list->insert(pad_list->begin(), 4, 0); + output_hw->push_back(static_cast(std::ceil(((x_h * 1.0) - dilation[0] * (kernel[0] - 1)) / stride[0]))); + output_hw->push_back(static_cast(std::ceil(((x_w * 1.0) - dilation[1] * (kernel[1] - 1)) / stride[1]))); + (void)pad_list->insert(pad_list->begin(), 4, 0); } else if (pad_mode == PadMode::SAME) { - output_hw->push_back(std::ceil((x_h * 1.0) / stride[0])); - output_hw->push_back(std::ceil((x_w * 1.0) / stride[1])); + output_hw->push_back(static_cast(std::ceil((x_h * 1.0) / stride[0]))); + output_hw->push_back(static_cast(std::ceil((x_w * 1.0) / stride[1]))); int64_t pad_needed_h = (output_hw->at(0) - 1) * stride[0] + dilation[0] * (kernel[0] - 1) + 1 - x_h; pad_needed_h = std::max((int64_t)0, pad_needed_h); - pad_list->push_back(std::floor(pad_needed_h / 2)); + pad_list->push_back(static_cast(std::floor(pad_needed_h / 2))); pad_list->push_back(pad_needed_h - pad_list->at(0)); int64_t pad_needed_w = (output_hw->at(1) - 1) * stride[1] + dilation[1] * (kernel[1] - 1) + 1 - x_w; pad_needed_w = std::max((int64_t)0, pad_needed_w); - pad_list->push_back(std::floor(pad_needed_w / 2)); + pad_list->push_back(static_cast(std::floor(pad_needed_w / 2))); pad_list->push_back(pad_needed_w - pad_list->at(2)); } else if (pad_mode == PadMode::PAD) { - pad_list->insert(pad_list->begin(), padding.begin(), padding.end()); - output_hw->push_back(std::floor( - 1 + - ((x_h * 1.0) + pad_list->at(0) + pad_list->at(1) - kernel[0] - (kernel[0] - 1) * (dilation[0] - 1)) / stride[0])); - output_hw->push_back(std::floor( - 1 + - ((x_w * 1.0) + pad_list->at(2) + pad_list->at(3) - kernel[1] - (kernel[1] - 1) * (dilation[1] - 1)) / stride[1])); + (void)pad_list->insert(pad_list->begin(), padding.begin(), padding.end()); + output_hw->push_back(static_cast(std::floor( + 1 + ((x_h * 1.0) + pad_list->at(0) + pad_list->at(1) - kernel[0] - (kernel[0] - 1) * (dilation[0] - 1)) / + stride[0]))); + output_hw->push_back(static_cast(std::floor( + 1 + ((x_w * 1.0) + pad_list->at(2) + pad_list->at(3) - kernel[1] - (kernel[1] - 1) * (dilation[1] - 1)) / + stride[1]))); } } @@ -279,10 +279,10 @@ AbstractBasePtr InferImplConv2D(const AnalysisEnginePtr &, const PrimitivePtr &p CheckShapeAnyAndPositive(op_name + " w_shape", w_shape); CheckShapeAllPositive(op_name + " w_min_shape", w_min_shape); CheckShapeAllPositive(op_name + " w_max_shape", w_max_shape); - const int64_t n_axis = 0; - int64_t c_axis = 1; - int64_t h_axis = 2; - int64_t w_axis = 3; + const uint64_t n_axis = 0; + uint64_t c_axis = 1; + uint64_t h_axis = 2; + uint64_t w_axis = 3; int64_t data_format = GetAndCheckFormat(primitive->GetAttr("format")); if (data_format == Format::NHWC) { c_axis = 3;