diff --git a/test/legacy_test/test_quantile_and_nanquantile.py b/test/legacy_test/test_quantile_and_nanquantile.py index b87ca40d4d6194..2478a2e1b6a7c3 100644 --- a/test/legacy_test/test_quantile_and_nanquantile.py +++ b/test/legacy_test/test_quantile_and_nanquantile.py @@ -221,6 +221,20 @@ def test_nanquantile_ZeroSize(self): loss.backward() np.testing.assert_allclose(x.grad.shape, x.shape) + def test_quantile_ZeroSize(self): + input_data = np.full(shape=[2, 0, 3], fill_value=np.nan) + x = paddle.to_tensor(input_data) + x.stop_gradient = False + paddle_res = paddle.quantile(x, q=0.35, axis=0) + np_res = np.quantile(input_data, q=0.35, axis=0) + np.testing.assert_allclose( + paddle_res.numpy(), np_res, rtol=1e-05, equal_nan=True + ) + + loss = paddle.sum(paddle_res) + loss.backward() + np.testing.assert_allclose(x.grad.shape, x.shape) + class TestMuitlpleQ(unittest.TestCase): """