Skip to content

Commit

Permalink
Merge pull request #8224 from boku13/nearest-method
Browse files Browse the repository at this point in the history
Add the `nearest` method for percentile/quantile estimation
  • Loading branch information
kmaehashi committed Mar 13, 2024
2 parents 194aab1 + a09ec81 commit be5d7f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions cupy/_statistics/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ def _quantile_unchecked(a, q, axis=None, out=None,
elif method == 'midpoint':
indices = 0.5 * (cupy.floor(indices) + cupy.ceil(indices))
elif method == 'nearest':
# TODO(hvy): Implement nearest using around
raise ValueError('\'nearest\' method is not yet supported. '
'Please use any other method.')
indices = cupy.around(indices).astype(cupy.int32)
elif method == 'linear':
pass
else:
Expand Down Expand Up @@ -311,7 +309,7 @@ def percentile(a, q, axis=None, out=None,
function completes is undefined.
method (str): Interpolation method when a quantile lies between
two data points. ``linear`` interpolation is used by default.
Supported interpolations are``lower``, ``higher``, ``midpoint``,
Supported interpolations are ``lower``, ``higher``, ``midpoint``,
``nearest`` and ``linear``.
keepdims (bool): If ``True``, the axis is remained as an axis of
size one.
Expand Down Expand Up @@ -358,7 +356,7 @@ def quantile(a, q, axis=None, out=None,
function completes is undefined.
method (str): Interpolation method when a quantile lies between
two data points. ``linear`` interpolation is used by default.
Supported interpolations are``lower``, ``higher``, ``midpoint``,
Supported interpolations are ``lower``, ``higher``, ``midpoint``,
``nearest`` and ``linear``.
keepdims (bool): If ``True``, the axis is remained as an axis of
size one.
Expand Down
2 changes: 1 addition & 1 deletion tests/cupy_tests/statistics_tests/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'lower',
'higher',
'midpoint',
# 'nearest', # TODO(hvy): Not implemented
'nearest',
)


Expand Down

0 comments on commit be5d7f6

Please sign in to comment.