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: added quantile function (new) #23580

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions ivy/functional/frontends/paddle/stat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# global
import ivy
import numpy as np
from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
from ivy.functional.frontends.paddle.func_wrapper import (
to_ivy_arrays_and_back,
Expand Down Expand Up @@ -52,6 +53,18 @@ def numel(x, name=None):
return ivy.array(prod if prod > 0 else ivy.array(length, dtype=ivy.int64))


@with_unsupported_dtypes(
{"2.5.1 and below": ("bfloat16", "uint16")},
"paddle",
)
@to_ivy_arrays_and_back
def quantile(x, q, axis=None, keepdim=False, name=None):
result = ivy.quantile(x, q, axis=axis, keepdims=keepdim)
if keepdim and result.shape == ():
result = np.expand_dims(result, axis=0)
return result.astype(np.float64)


@with_supported_dtypes(
{"2.5.1 and below": ("float32", "float64", "uint16")},
"paddle",
Expand Down
43 changes: 43 additions & 0 deletions ivy_tests/test_ivy/test_frontends/test_paddle/test_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,49 @@ def test_paddle_numel(
)


# quantile
@handle_frontend_test(
fn_tree="paddle.quantile",
dtype_x_and_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("valid"),
min_num_dims=1,
min_value=-1e10,
max_value=1e10,
valid_axis=True,
force_int_axis=True, # Assuming this forces the axis to be an integer.
),
q=st.floats(0.0, 1.0),
keepdim=st.booleans(),
)
def test_paddle_quantile(
*,
dtype_x_and_axis,
q,
keepdim,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
input_dtypes, (x,), axis = dtype_x_and_axis
# Convert axis if it's a tuple
if isinstance(axis, tuple):
axis = axis[0] if len(axis) == 1 else list(axis)
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the purpose of this logic, I don't think this is required.

Copy link
Contributor Author

@jaskiratsingh2000 jaskiratsingh2000 Sep 15, 2023

Choose a reason for hiding this comment

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

Since axis varibale has to be int not tuples when accepting parameters so that is wy I added it.

helpers.test_frontend_function(
input_dtypes=input_dtypes,
frontend=frontend,
backend_to_test=backend_fw,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
x=x[0],
q=q,
axis=axis,
keepdim=keepdim,
)


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