[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:
parent
6656169874
commit
0906bafa73
@ -534,6 +534,10 @@ StatusOr<Shape> InferWindowOutputShape(const Shape& base_shape,
|
|||||||
p.edge_padding_high() +
|
p.edge_padding_high() +
|
||||||
std::max<int64>(operand_shape.dimensions(i) - 1, 0LL) *
|
std::max<int64>(operand_shape.dimensions(i) - 1, 0LL) *
|
||||||
p.interior_padding();
|
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);
|
is_dynamic[i] = operand_shape.is_dynamic_dimension(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1481,6 +1481,14 @@ TEST_F(ShapeInferenceTest, Pad) {
|
|||||||
Shape inferred_shape = inferred_status.ValueOrDie();
|
Shape inferred_shape = inferred_status.ValueOrDie();
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
ShapeUtil::Equal(ShapeUtil::MakeShape(F32, {39, 31}), inferred_shape));
|
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) {
|
TEST_F(ShapeInferenceTest, Reverse) {
|
||||||
|
Loading…
Reference in New Issue
Block a user