Skip to content

Commit

Permalink
feat: add diagonal to paddle frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
iababio committed Sep 30, 2023
1 parent 3b53c67 commit e3c2ac4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ivy/functional/frontends/paddle/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ def deg2rad(x, name=None):
return ivy.deg2rad(x)


@with_supported_dtypes(
{
"2.5.1 and below": (
"int32",
"int64",
"float64",
"complex128",
"float32",
"complex64",
"bool",
)
},
"paddle",
)
@to_ivy_arrays_and_back
def diagonal(x, offset=0, axis1=0, axis2=1, name=None):
return ivy.diagonal(x, offset=offset, axis1=axis1, axis2=axis2)


@with_supported_dtypes(
{"2.5.1 and below": ("float32", "float64", "int32", "int64")}, "paddle"
)
Expand Down
53 changes: 53 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@
# --------------- #


@st.composite
def _draw_paddle_diagonal(draw):
_dtype, _x = draw(
helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("numeric"),
min_num_dims=2,
max_num_dims=10,
min_dim_size=1,
max_dim_size=50,
)
)

offset = (draw(helpers.ints(min_value=-10, max_value=50)),)
axes = (
draw(
st.lists(
helpers.ints(min_value=-(len(_x)), max_value=len(_x)),
min_size=len(_x) + 1,
max_size=len(_x) + 1,
unique=True,
).filter(lambda axes: axes[0] % 2 != axes[1] % 2)
),
)

return _dtype, _x[0], offset[0], axes[0]


@st.composite
def _test_paddle_take_helper(draw):
mode = draw(st.sampled_from(["raise", "clip", "wrap"]))
Expand Down Expand Up @@ -680,6 +707,32 @@ def test_paddle_deg2rad(
)


# diagonal
@handle_frontend_test(fn_tree="paddle.diagonal", data=_draw_paddle_diagonal())
def test_paddle_diagonal(
*,
data,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
_dtype, _x, offset, axes = data
helpers.test_frontend_function(
input_dtypes=_dtype,
frontend=frontend,
backend_to_test=backend_fw,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
x=_x,
offset=offset,
axis1=axes[0],
axis2=axes[1],
)


# diff
@handle_frontend_test(
fn_tree="paddle.diff",
Expand Down

0 comments on commit e3c2ac4

Please sign in to comment.