Skip to content

Commit

Permalink
Suppress a warning in unsqueeze (#2637)
Browse files Browse the repository at this point in the history
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 <kezhan@microsoft.com>
  • Loading branch information
xuhdev and linkerzhang committed Mar 10, 2020
1 parent 0582d52 commit 94b01cd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions onnx/defs/tensor/defs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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;
}
}

Expand Down

0 comments on commit 94b01cd

Please sign in to comment.