diff --git a/backends/mlu/tests/unittests/test_zero_dim_tensor_mlu.py b/backends/mlu/tests/unittests/test_zero_dim_tensor_mlu.py index cc6b5ae452d..05128a36e44 100644 --- a/backends/mlu/tests/unittests/test_zero_dim_tensor_mlu.py +++ b/backends/mlu/tests/unittests/test_zero_dim_tensor_mlu.py @@ -626,6 +626,16 @@ def test_reverse(self): self.assertEqual(out.shape, []) self.assertEqual(out.grad.shape, []) + def test_scale(self): + x = paddle.rand([]) + x.stop_gradient = False + out = paddle.scale(x, scale=2.0, bias=1.0) + out.backward() + + self.assertEqual(out.shape, []) + self.assertEqual(out.grad.shape, []) + self.assertEqual(x.grad.shape, []) + # Use to test API whose zero-dim input tensors don't have grad and not need to test backward in OpTest. class TestNoBackwardAPI(unittest.TestCase): diff --git a/backends/npu/tests/unittests/test_zero_dim_tensor_npu.py b/backends/npu/tests/unittests/test_zero_dim_tensor_npu.py index 9abf5cf71e9..a6ca505013e 100644 --- a/backends/npu/tests/unittests/test_zero_dim_tensor_npu.py +++ b/backends/npu/tests/unittests/test_zero_dim_tensor_npu.py @@ -626,6 +626,41 @@ def test_reverse(self): self.assertEqual(out.shape, []) self.assertEqual(out.grad.shape, []) + def test_scale(self): + x = paddle.rand([]) + x.stop_gradient = False + out = paddle.scale(x, scale=2.0, bias=1.0) + out.backward() + + self.assertEqual(out.shape, []) + self.assertEqual(out.grad.shape, []) + self.assertEqual(x.grad.shape, []) + + def test_floor_divide(self): + # 1-d // 0-d + x = paddle.to_tensor([1, -2, 3], dtype="int64") + y = paddle.full([], 2, dtype="int64") + out1_1 = paddle.floor_divide(x, y) + out1_2 = paddle.Tensor.__floordiv__(x, y) + + np.testing.assert_array_equal(out1_1.numpy(), out1_2.numpy()) + np.testing.assert_array_equal(out1_1.numpy(), np.asarray([0, -1, 1])) + + # 0-d // 1-d + out2_1 = paddle.floor_divide(y, x) + out2_2 = paddle.Tensor.__floordiv__(y, x) + + np.testing.assert_array_equal(out2_1.numpy(), out2_2.numpy()) + np.testing.assert_array_equal(out2_2.numpy(), np.asarray([2, -1, 0])) + + # 0-d // 0-d + x = paddle.full([], 3, dtype="int64") + out3_1 = paddle.floor_divide(x, y) + out3_2 = paddle.Tensor.__floordiv__(x, y) + + np.testing.assert_array_equal(out3_1.numpy(), out3_2.numpy()) + np.testing.assert_array_equal(out3_2.numpy(), np.asarray(1)) + # Use to test API whose zero-dim input tensors don't have grad and not need to test backward in OpTest. class TestNoBackwardAPI(unittest.TestCase):