From cf717fd6ddaa1a88449d8be7886d05eae6cae303 Mon Sep 17 00:00:00 2001 From: Yamei-Lee <33742067+liym27@users.noreply.github.com> Date: Fri, 25 Oct 2019 11:44:21 +0800 Subject: [PATCH] fix bug in reshape: (#20781) consider the situation that shape of input can contain more than one -1. test=develop --- paddle/fluid/operators/reshape_op.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/operators/reshape_op.cc b/paddle/fluid/operators/reshape_op.cc index 5dd9dfba43..cf97eac3fb 100644 --- a/paddle/fluid/operators/reshape_op.cc +++ b/paddle/fluid/operators/reshape_op.cc @@ -186,13 +186,16 @@ class ReshapeOp : public framework::OperatorWithKernel { output_shape[unk_dim_idx] = -1; } } else { - PADDLE_ENFORCE_EQ( - capacity, in_size, - "ShapeError: The 'shape' in ReshapeOp is invalid. " - "The input tensor X'size must be equal to the capacity of 'shape'. " - "But received X's shape = [%s], X's size = %d, 'shape' is [%s], the " - "capacity of 'shape' is %d.", - in_dims, in_size, framework::make_ddim(shape), capacity); + if (all_positive) { + PADDLE_ENFORCE_EQ( + capacity, in_size, + "ShapeError: The 'shape' in ReshapeOp is invalid. " + "The input tensor X'size must be equal to the capacity of 'shape'. " + "But received X's shape = [%s], X's size = %d, 'shape' is [%s], " + "the " + "capacity of 'shape' is %d.", + in_dims, in_size, framework::make_ddim(shape), capacity); + } } return framework::make_ddim(output_shape); } -- GitLab