Conversation
paddle/operators/reshape_op.cc
Outdated
| void InferShape(const framework::InferShapeContext &ctx) const override { | ||
| auto *in = ctx.Input<framework::Tensor>("X"); | ||
| auto shape = ctx.Attr<std::vector<int>>("shape"); | ||
| PADDLE_ENFORCE_EQ((unsigned)shape.size(), in->dims().size(), |
There was a problem hiding this comment.
unsigned long please. the size returned by ddim is ssize_t, which is 8byte width.
There was a problem hiding this comment.
Removed this unreasonable line.
paddle/operators/reshape_op.h
Outdated
| namespace paddle { | ||
| namespace operators { | ||
|
|
||
| using Tensor = framework::Tensor; |
There was a problem hiding this comment.
do not use using in the header file, according to the google style.
|
|
||
|
|
||
| class ReshapeGradOpTest(GradientChecker): | ||
| def test_normal(self): |
There was a problem hiding this comment.
now can use the function setUp to generate forward operator.
please take a look at this case
paddle/operators/reshape_op.h
Outdated
| out->mutable_data<T>(ctx.GetPlace()); | ||
|
|
||
| auto shape = ctx.Attr<std::vector<int>>("shape"); | ||
| std::vector<int64_t> tmp; |
There was a problem hiding this comment.
Please do not mix use of int64_t and size_t, which is ugly for users who read our code.
kuke
left a comment
There was a problem hiding this comment.
Refine this PR by following the review comments. Please continue to review.
paddle/operators/reshape_op.cc
Outdated
| void InferShape(const framework::InferShapeContext &ctx) const override { | ||
| auto *in = ctx.Input<framework::Tensor>("X"); | ||
| auto shape = ctx.Attr<std::vector<int>>("shape"); | ||
| PADDLE_ENFORCE_EQ((unsigned)shape.size(), in->dims().size(), |
There was a problem hiding this comment.
Removed this unreasonable line.
paddle/operators/reshape_op.h
Outdated
| namespace paddle { | ||
| namespace operators { | ||
|
|
||
| using Tensor = framework::Tensor; |
paddle/operators/reshape_op.h
Outdated
| out->mutable_data<T>(ctx.GetPlace()); | ||
|
|
||
| auto shape = ctx.Attr<std::vector<int>>("shape"); | ||
| std::vector<int64_t> tmp; |
|
|
||
|
|
||
| class ReshapeGradOpTest(GradientChecker): | ||
| def test_normal(self): |
dzhwinter
left a comment
There was a problem hiding this comment.
Seems LGTM.
Maybe @qingqing01 have more comment.
paddle/operators/reshape_op.cc
Outdated
|
|
||
| protected: | ||
| void InferShape(const framework::InferShapeContext &ctx) const override { | ||
| auto *in = ctx.Input<framework::Tensor>("X"); |
There was a problem hiding this comment.
Need to check non empty for Input('X'), like : https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/operators/squared_l2_distance_op.cc#L26
| } else { | ||
| capacity *= dim; | ||
| } | ||
| } |
There was a problem hiding this comment.
int64_t capacity = 1;
for (auto dim : shape) {
PADDLE_ENFORCE(dim > 0, "Each dimension of shape must be positive.");
capacity *= dim;
}or use std::accumulate :
int64_t capacity = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<int>());
paddle/operators/reshape_op.cc
Outdated
| int64_t in_size = framework::product(in->dims()); | ||
| PADDLE_ENFORCE_EQ(capacity, in_size, | ||
| "The size of Input(X) mismatches with Attr(shape)."); | ||
| ctx.Output<framework::Tensor>("Out")->Resize(in->dims()); |
There was a problem hiding this comment.
Why not Resize(shape)? The dims of output is not shape ?
| AddComment(R"DOC(Reshape operator | ||
|
|
||
| Reshape Input(X) into the shape specified by Attr(shape). | ||
| )DOC"); |
There was a problem hiding this comment.
| : OperatorWithKernel(type, inputs, outputs, attrs) {} | ||
|
|
||
| protected: | ||
| void InferShape(const framework::InferShapeContext &ctx) const override { |
There was a problem hiding this comment.
Need to check nonempty for the inputs.
kuke
left a comment
There was a problem hiding this comment.
updated, please continue to review @qingqing01
| : OperatorWithKernel(type, inputs, outputs, attrs) {} | ||
|
|
||
| protected: | ||
| void InferShape(const framework::InferShapeContext &ctx) const override { |
paddle/operators/reshape_op.cc
Outdated
| int64_t in_size = framework::product(in->dims()); | ||
| PADDLE_ENFORCE_EQ(capacity, in_size, | ||
| "The size of Input(X) mismatches with Attr(shape)."); | ||
| ctx.Output<framework::Tensor>("Out")->Resize(in->dims()); |
| } else { | ||
| capacity *= dim; | ||
| } | ||
| } |
paddle/operators/reshape_op.cc
Outdated
|
|
||
| protected: | ||
| void InferShape(const framework::InferShapeContext &ctx) const override { | ||
| auto *in = ctx.Input<framework::Tensor>("X"); |
| AddComment(R"DOC(Reshape operator | ||
|
|
||
| Reshape Input(X) into the shape specified by Attr(shape). | ||
| )DOC"); |
Resolve #4009