diff --git a/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc b/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc index b1b8c927844..dfd09a79356 100644 --- a/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc +++ b/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc @@ -623,8 +623,9 @@ void OnnxExporter::ExportNodes(const FuncGraphPtr &func_graph, std::mapcast(); + const int INDEX = 2; if (nextCNode->IsApply(prim::kPrimUpdateState) && - IsPrimitiveCNode(nextCNode->input(2), std::make_shared("MakeTuple"))) { + IsPrimitiveCNode(nextCNode->input(INDEX), std::make_shared("MakeTuple"))) { continue; } } @@ -735,7 +736,8 @@ void OnnxExporter::ExportPrimTranspose(const FuncGraphPtr &func_graph, const CNo std::map *node_map_ptr, onnx::GraphProto *const graph_proto) { auto input_data = GetNodeInputName(node->input(1), node_map_ptr, graph_proto); - auto input_perm = node->input(2); + const int PERM_INDEX = 2; + auto input_perm = node->input(PERM_INDEX); auto node_idx = AllocateNodeIndex(); (*node_map_ptr)[node] = node_idx; @@ -770,7 +772,8 @@ void OnnxExporter::ExportPrimStridedSlice(const FuncGraphPtr &func_graph, const std::map *node_map_ptr, onnx::GraphProto *const graph_proto) { auto input_data = GetNodeInputName(node->input(1), node_map_ptr, graph_proto); - auto begin = node->input(2); + const int BEGIN_INDEX = 2; + auto begin = node->input(BEGIN_INDEX); auto name = prim::kPrimStridedSlice->name(); std::string name_begin; if (begin->isa()) { @@ -791,7 +794,8 @@ void OnnxExporter::ExportPrimStridedSlice(const FuncGraphPtr &func_graph, const << "Need to insert op convert variable from tuple to tensor for " << name; } - auto end = node->input(3); + const int END_INDEX = 3; + auto end = node->input(END_INDEX); std::string name_end; if (end->isa()) { auto const_node_idx = AllocateNodeIndex(); @@ -832,7 +836,8 @@ void OnnxExporter::ExportPrimStridedSlice(const FuncGraphPtr &func_graph, const attr_proto_axes->set_type(onnx::AttributeProto_AttributeType_TENSOR); ConvertTupleToTensor(dyn_cast(axes)->value(), attr_proto_axes->mutable_t()); - auto strides = node->input(4); + const int STRIDES_INDEX = 4; + auto strides = node->input(STRIDES_INDEX); std::string name_strides; if (strides->isa()) { auto const_node_idx = AllocateNodeIndex(); @@ -876,7 +881,8 @@ void OnnxExporter::ExportPrimResizeNearestNeighbor(const FuncGraphPtr &func_grap auto tuple_ptr = dyn_cast(prim->GetAttr("size")); - for (size_t i = 0; i < x_shape->shape().size() - 2; i++) { + const int NUM = 2; + for (size_t i = 0; i < x_shape->shape().size() - NUM; i++) { resize_size.push_back(x_shape->shape()[i]); } for (size_t i = 0; i < tuple_ptr->size(); i++) { diff --git a/mindspore/core/ops/tile.cc b/mindspore/core/ops/tile.cc index 95d9040cdcd..0b1081ded9d 100644 --- a/mindspore/core/ops/tile.cc +++ b/mindspore/core/ops/tile.cc @@ -52,7 +52,8 @@ std::vector GetInferShape(const std::vector &input_shape, cons abstract::ShapePtr TileInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { MS_EXCEPTION_IF_NULL(primitive); auto prim_name = primitive->name(); - CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, 2, prim_name); + const int INDEX = 2; + CheckAndConvertUtils::CheckInteger("input numbers", SizeToLong(input_args.size()), kEqual, INDEX, prim_name); for (const auto &item : input_args) { MS_EXCEPTION_IF_NULL(item); }