Skip to content

Commit

Permalink
Fix reshape op. (#10641)
Browse files Browse the repository at this point in the history
  • Loading branch information
qingqing01 authored and Yang Yang(Tony) committed May 15, 2018
1 parent 674bd83 commit ca5ea65
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions paddle/fluid/operators/reshape_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ class ReshapeOp : public framework::OperatorWithKernel {
}

if (unk_dim_idx != -1) {
output_shape[unk_dim_idx] = -in_size / capacity;
// in_size < 0 and is un-determinate in compile time, skip the check,
// for example, in_dims = [-1, 8, 1, 1], shape = [-1, 3, 8],
// capacity = -24, in_size = -8, output_shape[0] = 0
// the following check will fail.
if (in_size > 0) {
// in_size < 0 and is un-determinate in compile time, skip the check,
// for example, in_dims = [-1, 8, 1, 1], shape = [-1, 3, 8],
// capacity = -24, in_size = -8, output_shape[0] = 0
// the following check will fail.
output_shape[unk_dim_idx] = -in_size / capacity;
PADDLE_ENFORCE_EQ(output_shape[unk_dim_idx] * capacity, -in_size,
"Invalid shape is given.");
} else {
output_shape[unk_dim_idx] = -1;
}
} else {
PADDLE_ENFORCE_EQ(capacity, in_size, "Invalid shape is given.");
Expand Down

0 comments on commit ca5ea65

Please sign in to comment.