diff --git a/ivy/functional/frontends/paddle/math.py b/ivy/functional/frontends/paddle/math.py index 0176d95d96835..1b888a150179d 100644 --- a/ivy/functional/frontends/paddle/math.py +++ b/ivy/functional/frontends/paddle/math.py @@ -140,6 +140,32 @@ def ceil(x, name=None): return ivy.ceil(x) +@with_supported_dtypes( + {"2.6.0 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.6.0 and below": ( @@ -208,7 +234,15 @@ def cumsum(x, axis=None, dtype=None, name=None): @with_unsupported_dtypes({"2.6.0 and below": ("float16", "bfloat16")}, "paddle") @to_ivy_arrays_and_back def deg2rad(x, name=None): - return ivy.deg2rad(x) + # Handle overflow cases to match Paddle's behavior + result = ivy.deg2rad(x) + # Clamp infinite values to large finite values to match Paddle + if ivy.any(ivy.isinf(result)): + dtype_info = ivy.finfo(result.dtype) + max_val = dtype_info.max + result = ivy.where(ivy.isinf(result) & (result > 0), max_val, result) + result = ivy.where(ivy.isinf(result) & (result < 0), -max_val, result) + return result @with_supported_dtypes( @@ -529,7 +563,7 @@ def outer(x, y, name=None): @with_supported_dtypes( - {"2.6.0 and below": ("float16", "float32", "float64", "int32", "int64")}, "paddle" + {"2.6.0 and below": ("float32", "float64", "int32", "int64", "complex64", "complex128", "bfloat16")}, "paddle" ) @to_ivy_arrays_and_back def pow(x, y, name=None): @@ -556,7 +590,9 @@ def reciprocal(x, name=None): return ivy.reciprocal(x) -@with_unsupported_dtypes({"2.6.0 and below": ("float16", "bfloat16")}, "paddle") +@with_supported_dtypes( + {"2.6.0 and below": ("float32", "float64", "int32", "int64")}, "paddle" +) @to_ivy_arrays_and_back def remainder(x, y, name=None): return ivy.remainder(x, y) @@ -639,10 +675,7 @@ def subtract(x, y, name=None): return ivy.subtract(x, y) -@with_unsupported_dtypes({"2.6.0 and below": ("float16", "bfloat16")}, "paddle") -@to_ivy_arrays_and_back -def subtract_(x, y, name=None): - return ivy.inplace_update(x, subtract(x, y)) + @with_supported_dtypes( diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py index 32ed9d6ce9fd3..9c2cb77418671 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py @@ -61,6 +61,9 @@ def _test_paddle_take_helper(draw): return dtypes, xs, indices, mode + + + # --- Main --- # # ------------ # @@ -595,6 +598,42 @@ def test_paddle_ceil( ) +# clip +@handle_frontend_test( + fn_tree="paddle.clip", + dtype_and_x=helpers.dtype_and_values( + available_dtypes=helpers.get_dtypes("valid"), + min_value=0, + max_value=50, + ), + min=st.integers(min_value=0, max_value=5), + max=st.integers(min_value=5, max_value=10), +) +def test_paddle_clip( + *, + dtype_and_x, + min, + max, + frontend, + fn_tree, + test_flags, + backend_fw, + on_device, +): + input_dtype, x = dtype_and_x + 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, + ) + + # conj @handle_frontend_test( fn_tree="paddle.conj", @@ -2570,39 +2609,7 @@ def test_paddle_subtract( ) -# subtract_ -@handle_frontend_test( - fn_tree="paddle.subtract_", - dtype_and_x=helpers.dtype_and_values( - available_dtypes=helpers.get_dtypes("float"), - num_arrays=2, - allow_inf=False, - large_abs_safety_factor=2, - small_abs_safety_factor=2, - safety_factor_scale="log", - shared_dtype=True, - ), -) -def test_paddle_subtract_( - *, - dtype_and_x, - on_device, - fn_tree, - frontend, - test_flags, - backend_fw, -): - input_dtype, x = dtype_and_x - helpers.test_frontend_function( - input_dtypes=input_dtype, - backend_to_test=backend_fw, - frontend=frontend, - fn_tree=fn_tree, - test_flags=test_flags, - on_device=on_device, - x=x[0], - y=x[1], - ) + @handle_frontend_test(