Skip to content

Commit

Permalink
Added count_nonzero to paddle_frontend (#23282)
Browse files Browse the repository at this point in the history
Co-authored-by: Aryan Sharma <[email protected]>
Co-authored-by: danielmunioz <[email protected]>
  • Loading branch information
3 people authored Sep 15, 2023
1 parent d056360 commit 9a36235
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ivy/functional/frontends/paddle/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ def cosh(x, name=None):
return ivy.cosh(x)


@with_supported_dtypes(
{"2.5.1 and below": ("int32", "int64", "float16", "float32", "float64", "bool")},
"paddle",
)
@to_ivy_arrays_and_back
def count_nonzero(x, axis=None, keepdim=False, name=None):
return ivy.astype(ivy.count_nonzero(x, axis=axis, keepdims=keepdim), ivy.int64)


@with_supported_dtypes(
{
"2.5.1 and below": (
Expand Down
32 changes: 32 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 @@ -586,6 +586,38 @@ def test_paddle_cosh(
)


# count_nonzero
@handle_frontend_test(
fn_tree="paddle.count_nonzero",
dtype_and_x=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes(kind="integer"),
valid_axis=True,
force_int_axis=True,
min_num_dims=1,
),
)
def test_paddle_count_nonzero(
*,
dtype_and_x,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
input_dtype, x, axis = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
backend_to_test=backend_fw,
on_device=on_device,
fn_tree=fn_tree,
test_flags=test_flags,
frontend=frontend,
x=x[0],
axis=axis,
)


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

0 comments on commit 9a36235

Please sign in to comment.