From f3ef8253e4c2682740d9ea0ba1ff1cf910d2a913 Mon Sep 17 00:00:00 2001 From: Bhushan Srivastava <59949692+he11owthere@users.noreply.github.com> Date: Mon, 11 Sep 2023 23:39:03 +0530 Subject: [PATCH] feat(frontend): Added lerp method to the Paddle frontend (#22571) Co-authored-by: hmahmood24 --- .../frontends/paddle/tensor/tensor.py | 4 ++ .../test_paddle/test_tensor/test_tensor.py | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/ivy/functional/frontends/paddle/tensor/tensor.py b/ivy/functional/frontends/paddle/tensor/tensor.py index 7a4f5dc308c88..ad68778a1c0fe 100644 --- a/ivy/functional/frontends/paddle/tensor/tensor.py +++ b/ivy/functional/frontends/paddle/tensor/tensor.py @@ -141,6 +141,10 @@ def sin(self, name=None): def sinh(self, name=None): return paddle_frontend.Tensor(ivy.sinh(self._ivy_array)) + @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") + def lerp(self, y, weight, name=None): + return paddle_frontend.lerp(self, y, weight) + @with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle") def lerp_(self, y, weight, name=None): self.ivy_array = paddle_frontend.lerp(self, y, weight).ivy_array diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py index 4c9762080387f..7ceeba34f4bff 100644 --- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py +++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_tensor/test_tensor.py @@ -127,6 +127,30 @@ def _get_dtype_and_square_matrix(draw): return dtype, mat +@st.composite +def _get_dtype_and_values_for_lerp(draw): + is_tensor = draw(st.booleans()) + if is_tensor: + input_dtype, x = draw( + helpers.dtype_and_values( + num_arrays=3, + available_dtypes=helpers.get_dtypes("valid"), + shared_dtype=True, + ) + ) + return input_dtype, x[0], x[1], x[2] + else: + input_dtype, x = draw( + helpers.dtype_and_values( + num_arrays=2, + available_dtypes=helpers.get_dtypes("valid"), + shared_dtype=True, + ) + ) + weight = draw(st.floats()) + return input_dtype, x[0], x[1], weight + + @st.composite def _reshape_helper(draw): # generate a shape s.t len(shape) > 0 @@ -2154,6 +2178,40 @@ def test_paddle_tensor_isnan( ) +# lerp +@handle_frontend_method( + class_tree=CLASS_TREE, + init_tree="paddle.to_tensor", + method_name="lerp", + dtypes_and_x=_get_dtype_and_values_for_lerp(), +) +def test_paddle_tensor_lerp( + dtypes_and_x, + frontend_method_data, + init_flags, + method_flags, + frontend, + on_device, + backend_fw, +): + input_dtype, x, y, weight = dtypes_and_x + helpers.test_frontend_method( + init_input_dtypes=input_dtype, + backend_to_test=backend_fw, + init_all_as_kwargs_np={"data": x}, + method_input_dtypes=input_dtype, + method_all_as_kwargs_np={ + "y": y, + "weight": weight, + }, + frontend_method_data=frontend_method_data, + init_flags=init_flags, + method_flags=method_flags, + frontend=frontend, + on_device=on_device, + ) + + # lerp_ @handle_frontend_method( class_tree=CLASS_TREE,