Skip to content

Commit ca5ea65

Browse files
qingqing01Yang Yang(Tony)
authored andcommitted
Fix reshape op. (#10641)
1 parent 674bd83 commit ca5ea65

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

paddle/fluid/operators/reshape_op.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,16 @@ class ReshapeOp : public framework::OperatorWithKernel {
9292
}
9393

9494
if (unk_dim_idx != -1) {
95-
output_shape[unk_dim_idx] = -in_size / capacity;
96-
// in_size < 0 and is un-determinate in compile time, skip the check,
97-
// for example, in_dims = [-1, 8, 1, 1], shape = [-1, 3, 8],
98-
// capacity = -24, in_size = -8, output_shape[0] = 0
99-
// the following check will fail.
10095
if (in_size > 0) {
96+
// in_size < 0 and is un-determinate in compile time, skip the check,
97+
// for example, in_dims = [-1, 8, 1, 1], shape = [-1, 3, 8],
98+
// capacity = -24, in_size = -8, output_shape[0] = 0
99+
// the following check will fail.
100+
output_shape[unk_dim_idx] = -in_size / capacity;
101101
PADDLE_ENFORCE_EQ(output_shape[unk_dim_idx] * capacity, -in_size,
102102
"Invalid shape is given.");
103+
} else {
104+
output_shape[unk_dim_idx] = -1;
103105
}
104106
} else {
105107
PADDLE_ENFORCE_EQ(capacity, in_size, "Invalid shape is given.");

0 commit comments

Comments
 (0)