Repository: ivy-llc/ivy

Issue:
clip_



Discussion:
This issue has been labelled as stale. If you would like to continue working on this issue, then please add another comment or create a PR . If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. For more information please refer to this page in our documentation: https://lets-unify.ai/ivy/contributing/1_the_basics.html#todo-list-issues
Working on it



Resolving patch:
diff --git a/ivy/functional/frontends/paddle/tensor/math.py b/ivy/functional/frontends/paddle/tensor/math.py
--- a/ivy/functional/frontends/paddle/tensor/math.py
+++ b/ivy/functional/frontends/paddle/tensor/math.py
@@ -15,6 +15,29 @@ def ceil_(x, name=None):
     return ivy.ceil(x, out=x)
 
 
+@with_supported_dtypes(
+    {"2.5.1 and below": ("float32", "float64", "int32", "int64")}, "paddle"
+)
+@to_ivy_arrays_and_back
+def clip_(x, 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:
+        min = ivy.min(x)
+    if max is None:
+        max = ivy.max(x)
+    res = ivy.clip(x, min, max)
+    if res.dtype != x.dtype:
+        res = ivy.astype(res, x.dtype)
+    return res
+
+
 @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
 @to_ivy_arrays_and_back
 def exp_(x, name=None):


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py
--- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py
+++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_math.py
@@ -1,6 +1,34 @@
 # local
 import ivy_tests.test_ivy.helpers as helpers
 from ivy_tests.test_ivy.helpers import handle_frontend_test
+from hypothesis import strategies as st
+
+
+# --- Helpers --- #
+# --------------- #
+
+
+@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,
+        )
+    )
+
+    return x_dtype, x
+
+
+# --- Main --- #
+# ------------ #
 
 
 # ceil_
@@ -31,6 +59,39 @@ def test_paddle_ceil_(
     )
 
 
+# clip_
+@handle_frontend_test(
+    fn_tree="paddle.tensor.math.clip_",
+    input_and_ranges=_get_clip_inputs_(),
+    min=st.integers(min_value=0, max_value=5),
+    max=st.integers(min_value=5, max_value=10),
+)
+def test_paddle_clip_(
+    *,
+    input_and_ranges,
+    min,
+    max,
+    frontend,
+    fn_tree,
+    test_flags,
+    backend_fw,
+    on_device,
+):
+    input_dtype, x = input_and_ranges
+
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        backend_to_test=backend_fw,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        x=x[0],
+        min=min,
+        max=max,
+    )
+
+
 # exp_
 @handle_frontend_test(
     fn_tree="paddle.tensor.math.exp_",