[XLA] InferPadShape should report an error when the result dimension size is a

negative number.

Modify an existing test case to test the situation.

PiperOrigin-RevId: 232502738
This commit is contained in:
Bixia Zheng 2019-02-05 09:40:12 -08:00 committed by TensorFlower Gardener
parent 6656169874
commit 0906bafa73
2 changed files with 12 additions and 0 deletions

View File

@ -534,6 +534,10 @@ StatusOr<Shape> InferWindowOutputShape(const Shape& base_shape,
p.edge_padding_high() +
std::max<int64>(operand_shape.dimensions(i) - 1, 0LL) *
p.interior_padding();
if (dimensions[i] < 0) {
return InvalidArgument("Padding result in negative size for dimension %d",
i);
}
is_dynamic[i] = operand_shape.is_dynamic_dimension(i);
}

View File

@ -1481,6 +1481,14 @@ TEST_F(ShapeInferenceTest, Pad) {
Shape inferred_shape = inferred_status.ValueOrDie();
ASSERT_TRUE(
ShapeUtil::Equal(ShapeUtil::MakeShape(F32, {39, 31}), inferred_shape));
dimension1->set_edge_padding_low(-20);
dimension1->set_edge_padding_high(-10);
auto negative_dimension_size = ShapeInference::InferPadShape(
input_shape, padding_value_shape, padding_config);
ASSERT_FALSE(negative_dimension_size.ok());
ASSERT_THAT(negative_dimension_size.status().error_message(),
HasSubstr("negative size for dimension 1"));
}
TEST_F(ShapeInferenceTest, Reverse) {