Merge pull request #20934 from yongtang:07182018-QuantizedAdd

PiperOrigin-RevId: 205463996
This commit is contained in:
TensorFlower Gardener 2018-07-20 15:37:26 -07:00
commit 9151e61398
2 changed files with 22 additions and 0 deletions

View File

@ -1504,6 +1504,13 @@ REGISTER_OP("QuantizedAdd")
.SetIsCommutative()
.SetShapeFn([](InferenceContext* c) {
TF_RETURN_IF_ERROR(shape_inference::BroadcastBinaryOpShapeFn(c));
// min_x, max_x, min_y, max_y should be scalar.
ShapeHandle unused;
TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 0, &unused));
TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 0, &unused));
TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 0, &unused));
TF_RETURN_IF_ERROR(c->WithRank(c->input(5), 0, &unused));
c->set_output(1, c->Scalar());
c->set_output(2, c->Scalar());
return Status::OK();

View File

@ -543,4 +543,19 @@ TEST(MathOpsTest, HistogramFixedWidth_ShapeFn) {
INFER_OK(op, "[?];[2];[]", "[?]");
INFER_OK(op, "[?];[2];?", "[?]");
}
TEST(MathOpsTest, QuantizedAdd_ShapeFn) {
ShapeInferenceTestOp op("QuantizedAdd");
INFER_OK(op, "?;?;?;?;?;?", "?;[];[]");
INFER_OK(op, "?;?;[];[];[];[]", "?;[];[]");
INFER_OK(op, "[1,2];?;[];[];[];[]", "?;[];[]");
INFER_OK(op, "[];[2];[];[];[];[]", "[d1_0];[];[]");
// Rank checks on input scalars.
INFER_ERROR("must be rank 0", op, "?;?;[1];?;?;?");
INFER_ERROR("must be rank 0", op, "?;?;?;[2];?;?");
INFER_ERROR("must be rank 0", op, "?;?;?;?;[3];?");
INFER_ERROR("must be rank 0", op, "?;?;?;?;?;[4]");
}
} // end namespace tensorflow