Skip to content

Commit

Permalink
feat: add diagonal tto paddle math
Browse files Browse the repository at this point in the history
  • Loading branch information
iababio committed Sep 27, 2023
1 parent 4c8b7a6 commit f93d582
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 14 deletions.
30 changes: 25 additions & 5 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 Expand Up @@ -338,6 +357,12 @@ def log(x, name=None):
return ivy.log(x)


@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
@to_ivy_arrays_and_back
def log10(x, name=None):
return ivy.log10(x)


@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
@to_ivy_arrays_and_back
def log1p(x, name=None):
Expand All @@ -349,11 +374,6 @@ def log1p(x, name=None):
def log2(x, name=None):
return ivy.log2(x)

@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
@to_ivy_arrays_and_back
def log10(x, name=None):
return ivy.log10(x)


@with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle")
@to_ivy_arrays_and_back
Expand Down
71 changes: 62 additions & 9 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,31 @@ def test_paddle_deg2rad(
)


@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 Expand Up @@ -1413,15 +1465,13 @@ def test_paddle_log(
)


# log1p
@handle_frontend_test(
fn_tree="paddle.log1p",
fn_tree="paddle.log10",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
max_value=1e5,
),
)
def test_paddle_log1p(
def test_paddle_log10(
*,
dtype_and_x,
on_device,
Expand All @@ -1442,14 +1492,15 @@ def test_paddle_log1p(
)


# log2
# log1p
@handle_frontend_test(
fn_tree="paddle.log2",
fn_tree="paddle.log1p",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
max_value=1e5,
),
)
def test_paddle_log2(
def test_paddle_log1p(
*,
dtype_and_x,
on_device,
Expand All @@ -1469,13 +1520,15 @@ def test_paddle_log2(
x=x[0],
)


# log2
@handle_frontend_test(
fn_tree="paddle.log10",
fn_tree="paddle.log2",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
),
)
def test_paddle_log10(
def test_paddle_log2(
*,
dtype_and_x,
on_device,
Expand Down

0 comments on commit f93d582

Please sign in to comment.