Skip to content

Commit

Permalink
Push update to paddle frontend diagonal
Browse files Browse the repository at this point in the history
  • Loading branch information
iababio committed Sep 10, 2023
1 parent c8b343b commit dc092ae
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 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 @@ -539,3 +539,22 @@ def tanh(x, name=None):
@to_ivy_arrays_and_back
def trunc(x, name=None):
return ivy.trunc(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)
48 changes: 29 additions & 19 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# global
from hypothesis import strategies as st
from hypothesis import strategies as st, reproduce_failure

# local
import ivy_tests.test_ivy.helpers as helpers
Expand Down Expand Up @@ -2292,39 +2292,49 @@ def test_paddle_trunc(
)


@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=2,
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]


# diagonal
@handle_frontend_test(
fn_tree="paddle.tensor.math.diagonal",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("numeric"),
min_num_dims=2,
max_num_dims=2,
min_dim_size=1,
max_dim_size=50,
),
offset=helpers.ints(min_value=-10, max_value=50),
axes=st.lists(
helpers.ints(min_value=-2, max_value=1), min_size=2, max_size=2, unique=True
).filter(lambda axes: axes[0] % 2 != axes[1] % 2),
fn_tree="paddle.diagonal",
data=_draw_paddle_diagonal()
)
def test_paddle_diagonal(
*,
dtype_and_x,
offset,
axes,
data,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
input_dtype, x = dtype_and_x
_dtype, _x, offset, axes = data
helpers.test_frontend_function(
input_dtypes=input_dtype,
input_dtypes=_dtype,
frontend=frontend,
backend_to_test=backend_fw,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
x=x[0],
x=_x,
offset=offset,
axis1=axes[0],
axis2=axes[1],
Expand Down

0 comments on commit dc092ae

Please sign in to comment.