Repository: ivy-llc/ivy

Issue:
clip



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/paddle/tensor/tensor.py b/ivy/functional/frontends/paddle/tensor/tensor.py
--- a/ivy/functional/frontends/paddle/tensor/tensor.py
+++ b/ivy/functional/frontends/paddle/tensor/tensor.py
@@ -161,6 +161,24 @@ def argsort(self, axis=-1, descending=False, name=None):
     def floor(self, name=None):
         return ivy.floor(self._ivy_array)
 
+    @with_supported_dtypes(
+        {"2.5.0 and below": ("float32", "float64", "int32", "int64")}, "paddle"
+    )
+    def clip(self, min=None, max=None, name=None):
+        ivy.utils.assertions.check_all_or_any_fn(
+            min,
+            max,
+            fn=ivy.exists,
+            type="any",
+            limit=[1, 2],
+            message="at most one of min or max can be None",
+        )
+        if min is None:
+            return ivy.minimum(self._ivy_array, max)
+        if max is None:
+            return ivy.maximum(self._ivy_array, min)
+        return ivy.clip(self._ivy_array, min, max)
+
     @with_unsupported_dtypes({"2.5.0 and below": ("float16", "bfloat16")}, "paddle")
     def floor_(self):
         return ivy.floor(self._ivy_array)


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_paddle_tensor.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_paddle_tensor.py
--- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_paddle_tensor.py
+++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_paddle_tensor.py
@@ -73,6 +73,34 @@ def _get_dtype_and_square_matrix(draw):
     return dtype, mat
 
 
+@st.composite
+def _get_clip_inputs(draw):
+    shape = draw(
+        helpers.get_shape(
+            min_num_dims=1, max_num_dims=5, min_dim_size=1, max_dim_size=10
+        )
+    )
+    x_dtype, x = draw(
+        helpers.dtype_and_values(
+            available_dtypes=helpers.get_dtypes("valid"),
+            shape=shape,
+            min_value=0,
+            max_value=50,
+        )
+    )
+    min = draw(
+        helpers.array_values(dtype=x_dtype[0], shape=(1,), min_value=0, max_value=25)
+    )
+    max = draw(
+        helpers.array_values(dtype=x_dtype[0], shape=(1,), min_value=26, max_value=50)
+    )
+    if draw(st.booleans()):
+        min = None
+    elif draw(st.booleans()):
+        max = None
+    return x_dtype, x, min, max
+
+
 # Tests #
 # ----- #
 
@@ -1877,6 +1905,37 @@ def test_paddle_minimum(
     )
 
 
+# clip
+@handle_frontend_method(
+    class_tree=CLASS_TREE,
+    init_tree="paddle.to_tensor",
+    method_name="clip",
+    input_and_ranges=_get_clip_inputs(),
+)
+def test_paddle_clip(
+    input_and_ranges,
+    frontend,
+    frontend_method_data,
+    init_flags,
+    method_flags,
+    on_device,
+):
+    input_dtype, x, min, max = input_and_ranges
+    helpers.test_frontend_method(
+        init_input_dtypes=input_dtype,
+        init_all_as_kwargs_np={
+            "data": x[0],
+        },
+        method_input_dtypes=input_dtype,
+        method_all_as_kwargs_np={"min": min, "max": max},
+        frontend_method_data=frontend_method_data,
+        init_flags=init_flags,
+        method_flags=method_flags,
+        frontend=frontend,
+        on_device=on_device,
+    )
+
+
 #  less_than
 @handle_frontend_method(
     class_tree=CLASS_TREE,