Skip to content

Commit

Permalink
feat(frontend): Added lerp method to the Paddle frontend (#22571)
Browse files Browse the repository at this point in the history
Co-authored-by: hmahmood24 <[email protected]>
  • Loading branch information
he11owthere and hmahmood24 authored Sep 11, 2023
1 parent b26bdac commit f3ef825
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ivy/functional/frontends/paddle/tensor/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f3ef825

Please sign in to comment.