Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions test/legacy_test/test_clip_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()