|
|
|
@ -36,36 +36,41 @@ class FlipOp : public framework::OperatorWithKernel {
|
|
|
|
|
platform::errors::NotFound(
|
|
|
|
|
"Output(Out) of FlipOp should not be null."));
|
|
|
|
|
auto x_dims = ctx->GetInputDim("X");
|
|
|
|
|
auto flip_dims = ctx->Attrs().Get<std::vector<int>>("dims");
|
|
|
|
|
auto flip_dims = ctx->Attrs().Get<std::vector<int>>("axis");
|
|
|
|
|
size_t flip_dims_size = flip_dims.size();
|
|
|
|
|
|
|
|
|
|
if (flip_dims_size > 0) {
|
|
|
|
|
// check if dims axis within range
|
|
|
|
|
auto min_max_d = std::minmax_element(flip_dims.begin(), flip_dims.end());
|
|
|
|
|
PADDLE_ENFORCE_LT(*min_max_d.first, x_dims.size(),
|
|
|
|
|
PADDLE_ENFORCE_LT(
|
|
|
|
|
*min_max_d.first, x_dims.size(),
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"min(dims) should be less than the input tensor X's "
|
|
|
|
|
"dimensions of FlipOp. But received min(dims) = %d, "
|
|
|
|
|
"X's dimensions = %d, X's shape = [%s]",
|
|
|
|
|
"min(axes) should be less than the input tensor X's "
|
|
|
|
|
"axes of FlipOp. But received min(axes) = %d, "
|
|
|
|
|
"X's axes = %d, X's shape = [%s]",
|
|
|
|
|
*min_max_d.first, x_dims.size(), x_dims));
|
|
|
|
|
PADDLE_ENFORCE_GE(
|
|
|
|
|
*min_max_d.first, x_dims.size() * -1,
|
|
|
|
|
PADDLE_ENFORCE_GE(*min_max_d.first, x_dims.size() * -1,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"min(dims) should be greater than or equal to the input tensor X's "
|
|
|
|
|
"dimensions of FlipOp times -1. But received min(dims) = %d, X's "
|
|
|
|
|
"dimensions = %d, X's shape = [%s]",
|
|
|
|
|
"min(axes) should be greater than or equal to the "
|
|
|
|
|
"input tensor X's "
|
|
|
|
|
"axes of FlipOp times -1. But received "
|
|
|
|
|
"min(axes) = %d, X's "
|
|
|
|
|
"axes = %d, X's shape = [%s]",
|
|
|
|
|
*min_max_d.first, x_dims.size() * -1, x_dims));
|
|
|
|
|
PADDLE_ENFORCE_LT(*min_max_d.second, x_dims.size(),
|
|
|
|
|
PADDLE_ENFORCE_LT(
|
|
|
|
|
*min_max_d.second, x_dims.size(),
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"max(dims) should be less than the input tensor X's "
|
|
|
|
|
"dimensions of FlipOp. But received max(dims) = %d, "
|
|
|
|
|
"X's dimensions = %d, X's shape = [%s]",
|
|
|
|
|
"max(axes) should be less than the input tensor X's "
|
|
|
|
|
"axes of FlipOp. But received max(axes) = %d, "
|
|
|
|
|
"X's axes = %d, X's shape = [%s]",
|
|
|
|
|
*min_max_d.second, x_dims.size(), x_dims));
|
|
|
|
|
PADDLE_ENFORCE_GE(
|
|
|
|
|
*min_max_d.second, x_dims.size() * -1,
|
|
|
|
|
PADDLE_ENFORCE_GE(*min_max_d.second, x_dims.size() * -1,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"max(dims) should be greater than or equal to the input tensor X's "
|
|
|
|
|
"dimensions of FlipOp times -1. But received max(dims) = %d, X's "
|
|
|
|
|
"dimensions = %d, X's shape = [%s]",
|
|
|
|
|
"max(axes) should be greater than or equal to the "
|
|
|
|
|
"input tensor X's "
|
|
|
|
|
"axes of FlipOp times -1. But received "
|
|
|
|
|
"max(axes) = %d, X's "
|
|
|
|
|
"axes = %d, X's shape = [%s]",
|
|
|
|
|
*min_max_d.second, x_dims.size() * -1, x_dims));
|
|
|
|
|
|
|
|
|
|
// check duplicates in dims
|
|
|
|
@ -73,9 +78,10 @@ class FlipOp : public framework::OperatorWithKernel {
|
|
|
|
|
flip_dims.end());
|
|
|
|
|
PADDLE_ENFORCE_EQ(flip_dims.size(), flip_dims_size,
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
"dims has duplicates, original flip dims size=%d, "
|
|
|
|
|
"but unique flip dims size=%d.)",
|
|
|
|
|
"axes has duplicates, original flip axes size=%d, "
|
|
|
|
|
"but unique flip axes size=%d.)",
|
|
|
|
|
flip_dims_size, flip_dims.size()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VLOG(3) << "flip operator x.shape=" << x_dims;
|
|
|
|
|
|
|
|
|
@ -104,10 +110,10 @@ class FlipOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
void Make() override {
|
|
|
|
|
AddInput("X", "(Tensor), The input tensor of flip op.");
|
|
|
|
|
AddOutput("Out", "(Tensor), The output tensor of flip op.");
|
|
|
|
|
AddAttr<std::vector<int>>("dims", "The axes to flip on.");
|
|
|
|
|
AddAttr<std::vector<int>>("axis", "The axes to flip on.");
|
|
|
|
|
AddComment(R"DOC(
|
|
|
|
|
Flip Operator.
|
|
|
|
|
Reverse the order of a n-D tensor along given axis in dims.
|
|
|
|
|
Reverse the order of a n-D tensor along given axis in axes.
|
|
|
|
|
)DOC");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|