Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(paddle Bucketize):adding test function for bucketize #26665

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/runConfigurations/_template__of_py_test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions ivy/functional/frontends/paddle/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ def argsort(x, /, *, axis=-1, descending=False, name=None):
return ivy.argsort(x, axis=axis, descending=descending)


# bucketize
@with_supported_dtypes(
{"2.5.1 and below": ("float32", "float64", "int32", "int64")},
"paddle",
)
@to_ivy_arrays_and_back
def bucketize(x, sorted_sequence, out_int32=False, right=False, name=None):
if ivy.get_num_dims(sorted_sequence) != 1:
raise ValueError(
"sorted_sequence tensor must be 1 dimension, but got dim"
f" {ivy.get_num_dims(sorted_sequence)}"
)
return searchsorted(sorted_sequence, x, out_int32=out_int32, right=right, name=name)


@with_supported_dtypes(
{"2.5.1 and below": ("int32", "int64", "float32", "float64")},
"paddle",
Expand Down
9 changes: 9 additions & 0 deletions ivy/functional/frontends/paddle/tensor/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,15 @@ def t(self, name=None):
def cast(self, dtype):
return paddle_frontend.cast(self, dtype)

@with_supported_dtypes(
{"2.5.1 and below": ("float32", "float64", "int32", "int64")},
"paddle",
)
def bucketize(self, y, right=False, name=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to keep consistent signatures so I guess using sorted_sequence instead of y would make more sense, same for addingout_int32

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments. All the changes are made and please have look.

return paddle_frontend.bucketize(
self.ivy_array, sorted_sequence=y, right=right, name=name
)

@with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle")
def bmm(self, y, transpose_x=False, transpose_y=False, name=None):
return paddle_frontend.bmm(self, y, transpose_x, transpose_y)
Expand Down
39 changes: 39 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,45 @@ def test_paddle_argsort(
)


# bucketize
@handle_frontend_test(
fn_tree="paddle.bucketize",
dtype_and_values=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("valid"),
shared_dtype=True,
min_num_dims=1,
num_arrays=2,
),
out_int32=st.booleans(),
right=st.booleans(),
)
def test_paddle_bucketize(
*,
dtype_and_values,
out_int32,
right,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
dtype, input = dtype_and_values
input[0] = np.sort(input[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this sorting needed ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this not used so for by mistake this could happen. i made changes pls have a look.

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=input[0],
sorted_sequence=input[1],
out_int32=out_int32,
right=right,
)


@handle_frontend_test(
fn_tree="paddle.index_sample",
array_indices_axis=helpers.array_indices_axis(
Expand Down
Loading