From 94b01cddcf888fbf9bcab8b6939cda39707ac814 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Mon, 9 Mar 2020 22:16:05 -0700 Subject: [PATCH] Suppress a warning in unsqueeze (#2637) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I keep getting this warning when building PyTorch: ``` In file included from /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/utils.h:6, from /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc:4: /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc: In lambda function: /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc:1414:22: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses] for (size_t(i) = 0; i < axes.size(); ++i) { ^ /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/schema.h:959:12: note: in definition of macro ‘ONNX_OPERATOR_SET_SCHEMA_EX’ return impl.SetName(#name) \ ^~~~ /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc:1369:1: note: in expansion of macro ‘ONNX_OPERATOR_SET_SCHEMA’ ONNX_OPERATOR_SET_SCHEMA( ``` This commit should fix it and modernize the code a bit. Co-authored-by: Ke Zhang --- onnx/defs/tensor/defs.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/onnx/defs/tensor/defs.cc b/onnx/defs/tensor/defs.cc index 296a704a270..f6d86ccf835 100644 --- a/onnx/defs/tensor/defs.cc +++ b/onnx/defs/tensor/defs.cc @@ -1578,13 +1578,13 @@ ONNX_OPERATOR_SET_SCHEMA( const auto& input_shape = ctx.getInputType(0)->tensor_type().shape(); const auto input_ndim = input_shape.dim_size(); const auto output_ndim = input_ndim + static_cast(axes.size()); - for (size_t(i) = 0; i < axes.size(); ++i) { - if (axes[i] < -output_ndim || axes[i] >= output_ndim) { + for (auto& axe : axes) { + if (axe < -output_ndim || axe >= output_ndim) { fail_shape_inference( "values in 'axes' are beyond the bounds of the computed output shape"); } - if (axes[i] < 0) { - axes[i] += output_ndim; + if (axe < 0) { + axe += output_ndim; } }