From 5b8bb3447006acabbc663dd9eb960560d78adca0 Mon Sep 17 00:00:00 2001 From: guosheng Date: Thu, 29 Mar 2018 16:24:39 +0800 Subject: [PATCH] Refine reshape_op by following comments. --- paddle/fluid/operators/reshape_op.cc | 10 ++++++---- paddle/fluid/operators/reshape_op.h | 1 - python/paddle/fluid/layers/nn.py | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/operators/reshape_op.cc b/paddle/fluid/operators/reshape_op.cc index 4b1aaf58490..b87b8e6b26c 100644 --- a/paddle/fluid/operators/reshape_op.cc +++ b/paddle/fluid/operators/reshape_op.cc @@ -49,14 +49,14 @@ Examples: specified by Attr(shape) is [6, 8], the reshape operator will transform Input(X) into a 2-D tensor with shape [6, 8] and leaving Input(X)'s data unchanged. -1. Given a 3-D tensor Input(X) with a shape [2, 4, 6], and the target shape +2. Given a 3-D tensor Input(X) with a shape [2, 4, 6], and the target shape specified by Attr(shape) is [2, 3, -1, 2], the reshape operator will transform Input(X) into a 4-D tensor with shape [2, 3, 4, 2] and leaving Input(X)'s data unchanged. In this case, one and only dimension of Attr(shape) can be set to -1, the value of this dimension is inferred from the total element number of Input(X) and remaining dimensions. -1. Given a 3-D tensor Input(X) with a shape [2, 4, 6], and the target shape +3. Given a 3-D tensor Input(X) with a shape [2, 4, 6], and the target shape specified by Attr(shape) is [-1, 0, 3, 2], the reshape operator will transform Input(X) into a 4-D tensor with shape [2, 4, 3, 2] and leaving Input(X)'s data unchanged. In this case, besides -1, 0 means the actual dimension value is going @@ -67,11 +67,13 @@ Note: 1. One and only one dimension in Attr(shape) can be set -1. In this case, the actual dimension value will be infered from the total element number of Input(X) and remaining dimensions. -1. More than one dimensions in Attr(shape) can be set to 0, which means the real + +2. More than one dimensions in Attr(shape) can be set to 0, which means the real dimension value will be copied from Input(X) at runtime. Note that the index of 0 can not exceed Rank(X). For example, Input(X) is a 3-D tensor with shape [2, 3, 4], Attr(shape) = [2, 3, 2, 0] is an invalid input. -1. Input(Shape) has a higher priority than Attr(shape) if it is provided, while + +3. Input(Shape) has a higher priority than Attr(shape) if it is provided, while Attr(shape) still should be set correctly to gurantee shape inference in compile-time. diff --git a/paddle/fluid/operators/reshape_op.h b/paddle/fluid/operators/reshape_op.h index 3a9a769229a..871b4d38d56 100644 --- a/paddle/fluid/operators/reshape_op.h +++ b/paddle/fluid/operators/reshape_op.h @@ -66,7 +66,6 @@ class ReshapeOp : public framework::OperatorWithKernel { int64_t capacity = 1; int unk_dim_idx = -1; for (size_t i = 0; i < shape.size(); ++i) { - // std::cout<< shape[i] << "haha"; if (shape[i] == unk_dim_val) { PADDLE_ENFORCE( unk_dim_idx == -1, diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index c2d32954b55..ed82fa8940e 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -3337,7 +3337,7 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None): number of x and remaining dimensions. Thus one and only one dimension can be set -1. - 1. 0 means the actual dimension value is going to be copied from the + 2. 0 means the actual dimension value is going to be copied from the corresponding dimension of x. The indice of 0s in shape can not exceed Rank(X). @@ -3347,14 +3347,14 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None): is [6, 8], the reshape operator will transform x into a 2-D tensor with shape [6, 8] and leaving x's data unchanged. - 1. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape + 2. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape specified is [2, 3, -1, 2], the reshape operator will transform x into a 4-D tensor with shape [2, 3, 4, 2] and leaving x's data unchanged. In this case, one dimension of the target shape is set to -1, the value of this dimension is inferred from the total element number of x and remaining dimensions. - 1. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape + 3. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape is [-1, 0, 3, 2], the reshape operator will transform x into a 4-D tensor with shape [2, 4, 3, 2] and leaving x's data unchanged. In this case, besides -1, 0 means the actual dimension value is going to be copied from -- GitLab