Skip to content

Commit c1583ef

Browse files
authored
[0-size Tensor No.243、326] Add 0-size Tensor support for quantile
1 parent 012a9f0 commit c1583ef

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/legacy_test/test_quantile_and_nanquantile.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,20 @@ def test_nanquantile_ZeroSize(self):
221221
loss.backward()
222222
np.testing.assert_allclose(x.grad.shape, x.shape)
223223

224+
def test_quantile_ZeroSize(self):
225+
input_data = np.full(shape=[2, 0, 3], fill_value=np.nan)
226+
x = paddle.to_tensor(input_data)
227+
x.stop_gradient = False
228+
paddle_res = paddle.quantile(x, q=0.35, axis=0)
229+
np_res = np.quantile(input_data, q=0.35, axis=0)
230+
np.testing.assert_allclose(
231+
paddle_res.numpy(), np_res, rtol=1e-05, equal_nan=True
232+
)
233+
234+
loss = paddle.sum(paddle_res)
235+
loss.backward()
236+
np.testing.assert_allclose(x.grad.shape, x.shape)
237+
224238

225239
class TestMuitlpleQ(unittest.TestCase):
226240
"""

0 commit comments

Comments
 (0)