We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove dtype argument from min/max?
It looks to me there's no point for these functions to have `dtype` argument.
They should be keyword-only at the very least, for numpy compatibility.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cupy/statistics/order.py`
Content:
```
1 import warnings
2 
3 import cupy
4 from cupy import core
5 from cupy.core import _routines_statistics as _statistics
6 from cupy.core import fusion
7 from cupy.logic import content
8 
9 
10 def amin(a, axis=None, out=None, keepdims=False, dtype=None):
11     """Returns the minimum of an array or the minimum along an axis.
12 
13     .. note::
14 
15        When at least one element is NaN, the corresponding min value will be
16        NaN.
17 
18     Args:
19         a (cupy.ndarray): Array to take the minimum.
20         axis (int): Along which axis to take the minimum. The flattened array
21             is used by default.
22         out (cupy.ndarray): Output array.
23         keepdims (bool): If ``True``, the axis is remained as an axis of
24             size one.
25         dtype: Data type specifier.
26 
27     Returns:
28         cupy.ndarray: The minimum of ``a``, along the axis if specified.
29 
30     .. seealso:: :func:`numpy.amin`
31 
32     """
33     if fusion._is_fusing():
34         if keepdims:
35             raise NotImplementedError(
36                 'cupy.amin does not support `keepdims` in fusion yet.')
37         return fusion._call_reduction(_statistics.amin,
38                                       a, axis=axis, dtype=dtype, out=out)
39 
40     # TODO(okuta): check type
41     return a.min(axis=axis, dtype=dtype, out=out, keepdims=keepdims)
42 
43 
44 def amax(a, axis=None, out=None, keepdims=False, dtype=None):
45     """Returns the maximum of an array or the maximum along an axis.
46 
47     .. note::
48 
49        When at least one element is NaN, the corresponding min value will be
50        NaN.
51 
52     Args:
53         a (cupy.ndarray): Array to take the maximum.
54         axis (int): Along which axis to take the maximum. The flattened array
55             is used by default.
56         out (cupy.ndarray): Output array.
57         keepdims (bool): If ``True``, the axis is remained as an axis of
58             size one.
59         dtype: Data type specifier.
60 
61     Returns:
62         cupy.ndarray: The maximum of ``a``, along the axis if specified.
63 
64     .. seealso:: :func:`numpy.amax`
65 
66     """
67     if fusion._is_fusing():
68         if keepdims:
69             raise NotImplementedError(
70                 'cupy.amax does not support `keepdims` in fusion yet.')
71         return fusion._call_reduction(_statistics.amax,
72                                       a, axis=axis, dtype=dtype, out=out)
73 
74     # TODO(okuta): check type
75     return a.max(axis=axis, dtype=dtype, out=out, keepdims=keepdims)
76 
77 
78 def nanmin(a, axis=None, out=None, keepdims=False):
79     """Returns the minimum of an array along an axis ignoring NaN.
80 
81     When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`
82     is raised and NaN is returned.
83 
84     Args:
85         a (cupy.ndarray): Array to take the minimum.
86         axis (int): Along which axis to take the minimum. The flattened array
87             is used by default.
88         out (cupy.ndarray): Output array.
89         keepdims (bool): If ``True``, the axis is remained as an axis of
90             size one.
91 
92     Returns:
93         cupy.ndarray: The minimum of ``a``, along the axis if specified.
94 
95     .. warning::
96 
97         This function may synchronize the device.
98 
99     .. seealso:: :func:`numpy.nanmin`
100 
101     """
102     # TODO(niboshi): Avoid synchronization.
103     res = core.nanmin(a, axis=axis, out=out, keepdims=keepdims)
104     if content.isnan(res).any():  # synchronize!
105         warnings.warn('All-NaN slice encountered', RuntimeWarning)
106     return res
107 
108 
109 def nanmax(a, axis=None, out=None, keepdims=False):
110     """Returns the maximum of an array along an axis ignoring NaN.
111 
112     When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`
113     is raised and NaN is returned.
114 
115     Args:
116         a (cupy.ndarray): Array to take the maximum.
117         axis (int): Along which axis to take the maximum. The flattened array
118             is used by default.
119         out (cupy.ndarray): Output array.
120         keepdims (bool): If ``True``, the axis is remained as an axis of
121             size one.
122 
123     Returns:
124         cupy.ndarray: The maximum of ``a``, along the axis if specified.
125 
126     .. warning::
127 
128         This function may synchronize the device.
129 
130     .. seealso:: :func:`numpy.nanmax`
131 
132     """
133     # TODO(niboshi): Avoid synchronization.
134     res = core.nanmax(a, axis=axis, out=out, keepdims=keepdims)
135     if content.isnan(res).any():  # synchronize!
136         warnings.warn('All-NaN slice encountered', RuntimeWarning)
137     return res
138 
139 
140 # TODO(okuta): Implement ptp
141 
142 
143 def percentile(a, q, axis=None, out=None, interpolation='linear',
144                keepdims=False):
145     """Computes the q-th percentile of the data along the specified axis.
146 
147     Args:
148         a (cupy.ndarray): Array for which to compute percentiles.
149         q (float, tuple of floats or cupy.ndarray): Percentiles to compute
150             in the range between 0 and 100 inclusive.
151         axis (int or tuple of ints): Along which axis or axes to compute the
152             percentiles. The flattened array is used by default.
153         out (cupy.ndarray): Output array.
154         interpolation (str): Interpolation method when a quantile lies between
155             two data points. ``linear`` interpolation is used by default.
156             Supported interpolations are``lower``, ``higher``, ``midpoint``,
157             ``nearest`` and ``linear``.
158         keepdims (bool): If ``True``, the axis is remained as an axis of
159             size one.
160 
161     Returns:
162         cupy.ndarray: The percentiles of ``a``, along the axis if specified.
163 
164     .. seealso:: :func:`numpy.percentile`
165 
166     """
167     q = cupy.asarray(q, dtype=a.dtype)
168     if q.ndim == 0:
169         q = q[None]
170         zerod = True
171     else:
172         zerod = False
173     if q.ndim > 1:
174         raise ValueError('Expected q to have a dimension of 1.\n'
175                          'Actual: {0} != 1'.format(q.ndim))
176 
177     if keepdims:
178         if axis is None:
179             keepdim = (1,) * a.ndim
180         else:
181             keepdim = list(a.shape)
182             for ax in axis:
183                 keepdim[ax % a.ndim] = 1
184             keepdim = tuple(keepdim)
185 
186     # Copy a since we need it sorted but without modifying the original array
187     if isinstance(axis, int):
188         axis = axis,
189     if axis is None:
190         ap = a.flatten()
191         nkeep = 0
192     else:
193         # Reduce axes from a and put them last
194         axis = tuple(ax % a.ndim for ax in axis)
195         keep = set(range(a.ndim)) - set(axis)
196         nkeep = len(keep)
197         for i, s in enumerate(sorted(keep)):
198             a = a.swapaxes(i, s)
199         ap = a.reshape(a.shape[:nkeep] + (-1,)).copy()
200 
201     axis = -1
202     ap.sort(axis=axis)
203     Nx = ap.shape[axis]
204     indices = q * 0.01 * (Nx - 1.)  # percents to decimals
205 
206     if interpolation == 'lower':
207         indices = cupy.floor(indices).astype(cupy.int32)
208     elif interpolation == 'higher':
209         indices = cupy.ceil(indices).astype(cupy.int32)
210     elif interpolation == 'midpoint':
211         indices = 0.5 * (cupy.floor(indices) + cupy.ceil(indices))
212     elif interpolation == 'nearest':
213         # TODO(hvy): Implement nearest using around
214         raise ValueError('\'nearest\' interpolation is not yet supported. '
215                          'Please use any other interpolation method.')
216     elif interpolation == 'linear':
217         pass
218     else:
219         raise ValueError('Unexpected interpolation method.\n'
220                          'Actual: \'{0}\' not in (\'linear\', \'lower\', '
221                          '\'higher\', \'midpoint\')'.format(interpolation))
222 
223     if indices.dtype == cupy.int32:
224         ret = cupy.rollaxis(ap, axis)
225         ret = ret.take(indices, axis=0, out=out)
226     else:
227         if out is None:
228             ret = cupy.empty(ap.shape[:-1] + q.shape, dtype=cupy.float64)
229         else:
230             ret = cupy.rollaxis(out, 0, out.ndim)
231 
232         cupy.ElementwiseKernel(
233             'S idx, raw T a, raw int32 offset', 'U ret',
234             '''
235             ptrdiff_t idx_below = floor(idx);
236             U weight_above = idx - idx_below;
237 
238             ptrdiff_t offset_i = _ind.get()[0] * offset;
239             ret = a[offset_i + idx_below] * (1.0 - weight_above)
240               + a[offset_i + idx_below + 1] * weight_above;
241             ''',
242             'percentile_weightnening'
243         )(indices, ap, ap.shape[-1] if ap.ndim > 1 else 0, ret)
244         ret = cupy.rollaxis(ret, -1)  # Roll q dimension back to first axis
245 
246     if zerod:
247         ret = ret.squeeze(0)
248     if keepdims:
249         if q.size > 1:
250             keepdim = (-1,) + keepdim
251         ret = ret.reshape(keepdim)
252 
253     return core._internal_ascontiguousarray(ret)
254
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cupy/statistics/order.py b/cupy/statistics/order.py
--- a/cupy/statistics/order.py
+++ b/cupy/statistics/order.py
@@ -7,7 +7,7 @@
 from cupy.logic import content
 
 
-def amin(a, axis=None, out=None, keepdims=False, dtype=None):
+def amin(a, axis=None, out=None, keepdims=False):
     """Returns the minimum of an array or the minimum along an axis.
 
     .. note::
@@ -22,7 +22,6 @@
         out (cupy.ndarray): Output array.
         keepdims (bool): If ``True``, the axis is remained as an axis of
             size one.
-        dtype: Data type specifier.
 
     Returns:
         cupy.ndarray: The minimum of ``a``, along the axis if specified.
@@ -35,13 +34,13 @@
             raise NotImplementedError(
                 'cupy.amin does not support `keepdims` in fusion yet.')
         return fusion._call_reduction(_statistics.amin,
-                                      a, axis=axis, dtype=dtype, out=out)
+                                      a, axis=axis, out=out)
 
     # TODO(okuta): check type
-    return a.min(axis=axis, dtype=dtype, out=out, keepdims=keepdims)
+    return a.min(axis=axis, out=out, keepdims=keepdims)
 
 
-def amax(a, axis=None, out=None, keepdims=False, dtype=None):
+def amax(a, axis=None, out=None, keepdims=False):
     """Returns the maximum of an array or the maximum along an axis.
 
     .. note::
@@ -56,7 +55,6 @@
         out (cupy.ndarray): Output array.
         keepdims (bool): If ``True``, the axis is remained as an axis of
             size one.
-        dtype: Data type specifier.
 
     Returns:
         cupy.ndarray: The maximum of ``a``, along the axis if specified.
@@ -69,10 +67,10 @@
             raise NotImplementedError(
                 'cupy.amax does not support `keepdims` in fusion yet.')
         return fusion._call_reduction(_statistics.amax,
-                                      a, axis=axis, dtype=dtype, out=out)
+                                      a, axis=axis, out=out)
 
     # TODO(okuta): check type
-    return a.max(axis=axis, dtype=dtype, out=out, keepdims=keepdims)
+    return a.max(axis=axis, out=out, keepdims=keepdims)
 
 
 def nanmin(a, axis=None, out=None, keepdims=False):

{"golden_diff": "diff --git a/cupy/statistics/order.py b/cupy/statistics/order.py\n--- a/cupy/statistics/order.py\n+++ b/cupy/statistics/order.py\n@@ -7,7 +7,7 @@\n from cupy.logic import content\n \n \n-def amin(a, axis=None, out=None, keepdims=False, dtype=None):\n+def amin(a, axis=None, out=None, keepdims=False):\n     \"\"\"Returns the minimum of an array or the minimum along an axis.\n \n     .. note::\n@@ -22,7 +22,6 @@\n         out (cupy.ndarray): Output array.\n         keepdims (bool): If ``True``, the axis is remained as an axis of\n             size one.\n-        dtype: Data type specifier.\n \n     Returns:\n         cupy.ndarray: The minimum of ``a``, along the axis if specified.\n@@ -35,13 +34,13 @@\n             raise NotImplementedError(\n                 'cupy.amin does not support `keepdims` in fusion yet.')\n         return fusion._call_reduction(_statistics.amin,\n-                                      a, axis=axis, dtype=dtype, out=out)\n+                                      a, axis=axis, out=out)\n \n     # TODO(okuta): check type\n-    return a.min(axis=axis, dtype=dtype, out=out, keepdims=keepdims)\n+    return a.min(axis=axis, out=out, keepdims=keepdims)\n \n \n-def amax(a, axis=None, out=None, keepdims=False, dtype=None):\n+def amax(a, axis=None, out=None, keepdims=False):\n     \"\"\"Returns the maximum of an array or the maximum along an axis.\n \n     .. note::\n@@ -56,7 +55,6 @@\n         out (cupy.ndarray): Output array.\n         keepdims (bool): If ``True``, the axis is remained as an axis of\n             size one.\n-        dtype: Data type specifier.\n \n     Returns:\n         cupy.ndarray: The maximum of ``a``, along the axis if specified.\n@@ -69,10 +67,10 @@\n             raise NotImplementedError(\n                 'cupy.amax does not support `keepdims` in fusion yet.')\n         return fusion._call_reduction(_statistics.amax,\n-                                      a, axis=axis, dtype=dtype, out=out)\n+                                      a, axis=axis, out=out)\n \n     # TODO(okuta): check type\n-    return a.max(axis=axis, dtype=dtype, out=out, keepdims=keepdims)\n+    return a.max(axis=axis, out=out, keepdims=keepdims)\n \n \n def nanmin(a, axis=None, out=None, keepdims=False):\n", "issue": "Remove dtype argument from min/max?\nIt looks to me there's no point for these functions to have `dtype` argument.\r\nThey should be keyword-only at the very least, for numpy compatibility.\n", "before_files": [{"content": "import warnings\n\nimport cupy\nfrom cupy import core\nfrom cupy.core import _routines_statistics as _statistics\nfrom cupy.core import fusion\nfrom cupy.logic import content\n\n\ndef amin(a, axis=None, out=None, keepdims=False, dtype=None):\n    \"\"\"Returns the minimum of an array or the minimum along an axis.\n\n    .. note::\n\n       When at least one element is NaN, the corresponding min value will be\n       NaN.\n\n    Args:\n        a (cupy.ndarray): Array to take the minimum.\n        axis (int): Along which axis to take the minimum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n        dtype: Data type specifier.\n\n    Returns:\n        cupy.ndarray: The minimum of ``a``, along the axis if specified.\n\n    .. seealso:: :func:`numpy.amin`\n\n    \"\"\"\n    if fusion._is_fusing():\n        if keepdims:\n            raise NotImplementedError(\n                'cupy.amin does not support `keepdims` in fusion yet.')\n        return fusion._call_reduction(_statistics.amin,\n                                      a, axis=axis, dtype=dtype, out=out)\n\n    # TODO(okuta): check type\n    return a.min(axis=axis, dtype=dtype, out=out, keepdims=keepdims)\n\n\ndef amax(a, axis=None, out=None, keepdims=False, dtype=None):\n    \"\"\"Returns the maximum of an array or the maximum along an axis.\n\n    .. note::\n\n       When at least one element is NaN, the corresponding min value will be\n       NaN.\n\n    Args:\n        a (cupy.ndarray): Array to take the maximum.\n        axis (int): Along which axis to take the maximum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n        dtype: Data type specifier.\n\n    Returns:\n        cupy.ndarray: The maximum of ``a``, along the axis if specified.\n\n    .. seealso:: :func:`numpy.amax`\n\n    \"\"\"\n    if fusion._is_fusing():\n        if keepdims:\n            raise NotImplementedError(\n                'cupy.amax does not support `keepdims` in fusion yet.')\n        return fusion._call_reduction(_statistics.amax,\n                                      a, axis=axis, dtype=dtype, out=out)\n\n    # TODO(okuta): check type\n    return a.max(axis=axis, dtype=dtype, out=out, keepdims=keepdims)\n\n\ndef nanmin(a, axis=None, out=None, keepdims=False):\n    \"\"\"Returns the minimum of an array along an axis ignoring NaN.\n\n    When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`\n    is raised and NaN is returned.\n\n    Args:\n        a (cupy.ndarray): Array to take the minimum.\n        axis (int): Along which axis to take the minimum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The minimum of ``a``, along the axis if specified.\n\n    .. warning::\n\n        This function may synchronize the device.\n\n    .. seealso:: :func:`numpy.nanmin`\n\n    \"\"\"\n    # TODO(niboshi): Avoid synchronization.\n    res = core.nanmin(a, axis=axis, out=out, keepdims=keepdims)\n    if content.isnan(res).any():  # synchronize!\n        warnings.warn('All-NaN slice encountered', RuntimeWarning)\n    return res\n\n\ndef nanmax(a, axis=None, out=None, keepdims=False):\n    \"\"\"Returns the maximum of an array along an axis ignoring NaN.\n\n    When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`\n    is raised and NaN is returned.\n\n    Args:\n        a (cupy.ndarray): Array to take the maximum.\n        axis (int): Along which axis to take the maximum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The maximum of ``a``, along the axis if specified.\n\n    .. warning::\n\n        This function may synchronize the device.\n\n    .. seealso:: :func:`numpy.nanmax`\n\n    \"\"\"\n    # TODO(niboshi): Avoid synchronization.\n    res = core.nanmax(a, axis=axis, out=out, keepdims=keepdims)\n    if content.isnan(res).any():  # synchronize!\n        warnings.warn('All-NaN slice encountered', RuntimeWarning)\n    return res\n\n\n# TODO(okuta): Implement ptp\n\n\ndef percentile(a, q, axis=None, out=None, interpolation='linear',\n               keepdims=False):\n    \"\"\"Computes the q-th percentile of the data along the specified axis.\n\n    Args:\n        a (cupy.ndarray): Array for which to compute percentiles.\n        q (float, tuple of floats or cupy.ndarray): Percentiles to compute\n            in the range between 0 and 100 inclusive.\n        axis (int or tuple of ints): Along which axis or axes to compute the\n            percentiles. The flattened array is used by default.\n        out (cupy.ndarray): Output array.\n        interpolation (str): Interpolation method when a quantile lies between\n            two data points. ``linear`` interpolation is used by default.\n            Supported interpolations are``lower``, ``higher``, ``midpoint``,\n            ``nearest`` and ``linear``.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The percentiles of ``a``, along the axis if specified.\n\n    .. seealso:: :func:`numpy.percentile`\n\n    \"\"\"\n    q = cupy.asarray(q, dtype=a.dtype)\n    if q.ndim == 0:\n        q = q[None]\n        zerod = True\n    else:\n        zerod = False\n    if q.ndim > 1:\n        raise ValueError('Expected q to have a dimension of 1.\\n'\n                         'Actual: {0} != 1'.format(q.ndim))\n\n    if keepdims:\n        if axis is None:\n            keepdim = (1,) * a.ndim\n        else:\n            keepdim = list(a.shape)\n            for ax in axis:\n                keepdim[ax % a.ndim] = 1\n            keepdim = tuple(keepdim)\n\n    # Copy a since we need it sorted but without modifying the original array\n    if isinstance(axis, int):\n        axis = axis,\n    if axis is None:\n        ap = a.flatten()\n        nkeep = 0\n    else:\n        # Reduce axes from a and put them last\n        axis = tuple(ax % a.ndim for ax in axis)\n        keep = set(range(a.ndim)) - set(axis)\n        nkeep = len(keep)\n        for i, s in enumerate(sorted(keep)):\n            a = a.swapaxes(i, s)\n        ap = a.reshape(a.shape[:nkeep] + (-1,)).copy()\n\n    axis = -1\n    ap.sort(axis=axis)\n    Nx = ap.shape[axis]\n    indices = q * 0.01 * (Nx - 1.)  # percents to decimals\n\n    if interpolation == 'lower':\n        indices = cupy.floor(indices).astype(cupy.int32)\n    elif interpolation == 'higher':\n        indices = cupy.ceil(indices).astype(cupy.int32)\n    elif interpolation == 'midpoint':\n        indices = 0.5 * (cupy.floor(indices) + cupy.ceil(indices))\n    elif interpolation == 'nearest':\n        # TODO(hvy): Implement nearest using around\n        raise ValueError('\\'nearest\\' interpolation is not yet supported. '\n                         'Please use any other interpolation method.')\n    elif interpolation == 'linear':\n        pass\n    else:\n        raise ValueError('Unexpected interpolation method.\\n'\n                         'Actual: \\'{0}\\' not in (\\'linear\\', \\'lower\\', '\n                         '\\'higher\\', \\'midpoint\\')'.format(interpolation))\n\n    if indices.dtype == cupy.int32:\n        ret = cupy.rollaxis(ap, axis)\n        ret = ret.take(indices, axis=0, out=out)\n    else:\n        if out is None:\n            ret = cupy.empty(ap.shape[:-1] + q.shape, dtype=cupy.float64)\n        else:\n            ret = cupy.rollaxis(out, 0, out.ndim)\n\n        cupy.ElementwiseKernel(\n            'S idx, raw T a, raw int32 offset', 'U ret',\n            '''\n            ptrdiff_t idx_below = floor(idx);\n            U weight_above = idx - idx_below;\n\n            ptrdiff_t offset_i = _ind.get()[0] * offset;\n            ret = a[offset_i + idx_below] * (1.0 - weight_above)\n              + a[offset_i + idx_below + 1] * weight_above;\n            ''',\n            'percentile_weightnening'\n        )(indices, ap, ap.shape[-1] if ap.ndim > 1 else 0, ret)\n        ret = cupy.rollaxis(ret, -1)  # Roll q dimension back to first axis\n\n    if zerod:\n        ret = ret.squeeze(0)\n    if keepdims:\n        if q.size > 1:\n            keepdim = (-1,) + keepdim\n        ret = ret.reshape(keepdim)\n\n    return core._internal_ascontiguousarray(ret)\n", "path": "cupy/statistics/order.py"}], "after_files": [{"content": "import warnings\n\nimport cupy\nfrom cupy import core\nfrom cupy.core import _routines_statistics as _statistics\nfrom cupy.core import fusion\nfrom cupy.logic import content\n\n\ndef amin(a, axis=None, out=None, keepdims=False):\n    \"\"\"Returns the minimum of an array or the minimum along an axis.\n\n    .. note::\n\n       When at least one element is NaN, the corresponding min value will be\n       NaN.\n\n    Args:\n        a (cupy.ndarray): Array to take the minimum.\n        axis (int): Along which axis to take the minimum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The minimum of ``a``, along the axis if specified.\n\n    .. seealso:: :func:`numpy.amin`\n\n    \"\"\"\n    if fusion._is_fusing():\n        if keepdims:\n            raise NotImplementedError(\n                'cupy.amin does not support `keepdims` in fusion yet.')\n        return fusion._call_reduction(_statistics.amin,\n                                      a, axis=axis, out=out)\n\n    # TODO(okuta): check type\n    return a.min(axis=axis, out=out, keepdims=keepdims)\n\n\ndef amax(a, axis=None, out=None, keepdims=False):\n    \"\"\"Returns the maximum of an array or the maximum along an axis.\n\n    .. note::\n\n       When at least one element is NaN, the corresponding min value will be\n       NaN.\n\n    Args:\n        a (cupy.ndarray): Array to take the maximum.\n        axis (int): Along which axis to take the maximum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The maximum of ``a``, along the axis if specified.\n\n    .. seealso:: :func:`numpy.amax`\n\n    \"\"\"\n    if fusion._is_fusing():\n        if keepdims:\n            raise NotImplementedError(\n                'cupy.amax does not support `keepdims` in fusion yet.')\n        return fusion._call_reduction(_statistics.amax,\n                                      a, axis=axis, out=out)\n\n    # TODO(okuta): check type\n    return a.max(axis=axis, out=out, keepdims=keepdims)\n\n\ndef nanmin(a, axis=None, out=None, keepdims=False):\n    \"\"\"Returns the minimum of an array along an axis ignoring NaN.\n\n    When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`\n    is raised and NaN is returned.\n\n    Args:\n        a (cupy.ndarray): Array to take the minimum.\n        axis (int): Along which axis to take the minimum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The minimum of ``a``, along the axis if specified.\n\n    .. warning::\n\n        This function may synchronize the device.\n\n    .. seealso:: :func:`numpy.nanmin`\n\n    \"\"\"\n    # TODO(niboshi): Avoid synchronization.\n    res = core.nanmin(a, axis=axis, out=out, keepdims=keepdims)\n    if content.isnan(res).any():  # synchronize!\n        warnings.warn('All-NaN slice encountered', RuntimeWarning)\n    return res\n\n\ndef nanmax(a, axis=None, out=None, keepdims=False):\n    \"\"\"Returns the maximum of an array along an axis ignoring NaN.\n\n    When there is a slice whose elements are all NaN, a :class:`RuntimeWarning`\n    is raised and NaN is returned.\n\n    Args:\n        a (cupy.ndarray): Array to take the maximum.\n        axis (int): Along which axis to take the maximum. The flattened array\n            is used by default.\n        out (cupy.ndarray): Output array.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The maximum of ``a``, along the axis if specified.\n\n    .. warning::\n\n        This function may synchronize the device.\n\n    .. seealso:: :func:`numpy.nanmax`\n\n    \"\"\"\n    # TODO(niboshi): Avoid synchronization.\n    res = core.nanmax(a, axis=axis, out=out, keepdims=keepdims)\n    if content.isnan(res).any():  # synchronize!\n        warnings.warn('All-NaN slice encountered', RuntimeWarning)\n    return res\n\n\n# TODO(okuta): Implement ptp\n\n\ndef percentile(a, q, axis=None, out=None, interpolation='linear',\n               keepdims=False):\n    \"\"\"Computes the q-th percentile of the data along the specified axis.\n\n    Args:\n        a (cupy.ndarray): Array for which to compute percentiles.\n        q (float, tuple of floats or cupy.ndarray): Percentiles to compute\n            in the range between 0 and 100 inclusive.\n        axis (int or tuple of ints): Along which axis or axes to compute the\n            percentiles. The flattened array is used by default.\n        out (cupy.ndarray): Output array.\n        interpolation (str): Interpolation method when a quantile lies between\n            two data points. ``linear`` interpolation is used by default.\n            Supported interpolations are``lower``, ``higher``, ``midpoint``,\n            ``nearest`` and ``linear``.\n        keepdims (bool): If ``True``, the axis is remained as an axis of\n            size one.\n\n    Returns:\n        cupy.ndarray: The percentiles of ``a``, along the axis if specified.\n\n    .. seealso:: :func:`numpy.percentile`\n\n    \"\"\"\n    q = cupy.asarray(q, dtype=a.dtype)\n    if q.ndim == 0:\n        q = q[None]\n        zerod = True\n    else:\n        zerod = False\n    if q.ndim > 1:\n        raise ValueError('Expected q to have a dimension of 1.\\n'\n                         'Actual: {0} != 1'.format(q.ndim))\n\n    if keepdims:\n        if axis is None:\n            keepdim = (1,) * a.ndim\n        else:\n            keepdim = list(a.shape)\n            for ax in axis:\n                keepdim[ax % a.ndim] = 1\n            keepdim = tuple(keepdim)\n\n    # Copy a since we need it sorted but without modifying the original array\n    if isinstance(axis, int):\n        axis = axis,\n    if axis is None:\n        ap = a.flatten()\n        nkeep = 0\n    else:\n        # Reduce axes from a and put them last\n        axis = tuple(ax % a.ndim for ax in axis)\n        keep = set(range(a.ndim)) - set(axis)\n        nkeep = len(keep)\n        for i, s in enumerate(sorted(keep)):\n            a = a.swapaxes(i, s)\n        ap = a.reshape(a.shape[:nkeep] + (-1,)).copy()\n\n    axis = -1\n    ap.sort(axis=axis)\n    Nx = ap.shape[axis]\n    indices = q * 0.01 * (Nx - 1.)  # percents to decimals\n\n    if interpolation == 'lower':\n        indices = cupy.floor(indices).astype(cupy.int32)\n    elif interpolation == 'higher':\n        indices = cupy.ceil(indices).astype(cupy.int32)\n    elif interpolation == 'midpoint':\n        indices = 0.5 * (cupy.floor(indices) + cupy.ceil(indices))\n    elif interpolation == 'nearest':\n        # TODO(hvy): Implement nearest using around\n        raise ValueError('\\'nearest\\' interpolation is not yet supported. '\n                         'Please use any other interpolation method.')\n    elif interpolation == 'linear':\n        pass\n    else:\n        raise ValueError('Unexpected interpolation method.\\n'\n                         'Actual: \\'{0}\\' not in (\\'linear\\', \\'lower\\', '\n                         '\\'higher\\', \\'midpoint\\')'.format(interpolation))\n\n    if indices.dtype == cupy.int32:\n        ret = cupy.rollaxis(ap, axis)\n        ret = ret.take(indices, axis=0, out=out)\n    else:\n        if out is None:\n            ret = cupy.empty(ap.shape[:-1] + q.shape, dtype=cupy.float64)\n        else:\n            ret = cupy.rollaxis(out, 0, out.ndim)\n\n        cupy.ElementwiseKernel(\n            'S idx, raw T a, raw int32 offset', 'U ret',\n            '''\n            ptrdiff_t idx_below = floor(idx);\n            U weight_above = idx - idx_below;\n\n            ptrdiff_t offset_i = _ind.get()[0] * offset;\n            ret = a[offset_i + idx_below] * (1.0 - weight_above)\n              + a[offset_i + idx_below + 1] * weight_above;\n            ''',\n            'percentile_weightnening'\n        )(indices, ap, ap.shape[-1] if ap.ndim > 1 else 0, ret)\n        ret = cupy.rollaxis(ret, -1)  # Roll q dimension back to first axis\n\n    if zerod:\n        ret = ret.squeeze(0)\n    if keepdims:\n        if q.size > 1:\n            keepdim = (-1,) + keepdim\n        ret = ret.reshape(keepdim)\n\n    return core._internal_ascontiguousarray(ret)\n", "path": "cupy/statistics/order.py"}]}