From a08b7ccda8939d96656c3c9bede58b4a7b1e0cc4 Mon Sep 17 00:00:00 2001 From: co63oc Date: Fri, 20 Jun 2025 15:33:32 +0800 Subject: [PATCH] Fix --- python/paddle/tensor/math.py | 3 +++ test/legacy_test/test_clip_op.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 2e4724c160d3c..114fdefd30602 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -4012,6 +4012,9 @@ def clip( elif x_dtype == 'paddle.float16': min_ = float(np.finfo(np.float16).min) max_ = float(np.finfo(np.float16).max) + elif x_dtype == 'paddle.float64': + min_ = float(np.finfo(np.float64).min) + max_ = float(np.finfo(np.float64).max) else: min_ = float(np.finfo(np.float32).min) max_ = float(np.finfo(np.float32).max) diff --git a/test/legacy_test/test_clip_op.py b/test/legacy_test/test_clip_op.py index 532f6d800fb74..a34c3de3a80fd 100644 --- a/test/legacy_test/test_clip_op.py +++ b/test/legacy_test/test_clip_op.py @@ -525,5 +525,33 @@ def _executed_api(self, x, min=None, max=None): return x.clip_(min, max) +class TestClipOp_FP64(OpTest): + def setUp(self): + self.python_api = paddle.clip + self.public_python_api = paddle.clip + + self.inputs = {} + self.dtype = np.float64 + self.shape = (8, 16, 8) + self.max = float(np.finfo(np.float64).max) + self.min = float(np.finfo(np.float64).min) + + self.op_type = "clip" + self.attrs = {} + self.attrs['min'] = self.min + self.attrs['max'] = self.max + + self.inputs['X'] = np.random.random(self.shape).astype(self.dtype) + self.outputs = {'Out': np.clip(self.inputs['X'], self.min, self.max)} + + def test_check_output(self): + self.check_output( + check_pir=True, + ) + + def test_check_grad_normal(self): + self.check_grad(['X'], 'Out', check_pir=True) + + if __name__ == '__main__': unittest.main()