diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index 35465a046cc..53e4e619091 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -133,8 +133,8 @@ def _append_to_diff_array(a, axis, combined, values): Scalar value (including case with 0d array) is expanded to an array with length=1 in the direction of axis and the shape of the input array `a` - in along all other axes. - Note, if `values` is a scalar. then it is converted to 0d array allocating + along all other axes. + Note, if `values` is a scalar, then it is converted to 0d array allocating on the same SYCL queue as the input array `a` and with the same USM type. """ @@ -1132,7 +1132,9 @@ def fmax(x1, x2, /, out=None, *, where=True, dtype=None, subok=True, **kwargs): See Also -------- :obj:`dpnp.maximum` : Element-wise maximum of array elements, propagates NaNs. - :obj:`dpnp.fmin` : Element-wise minimum of array elements, ignore NaNs. + :obj:`dpnp.fmin` : Element-wise minimum of array elements, ignores NaNs. + :obj:`dpnp.max` : The maximum value of an array along a given axis, propagates NaNs.. + :obj:`dpnp.nanmax` : The maximum value of an array along a given axis, ignores NaNs. :obj:`dpnp.minimum` : Element-wise minimum of array elements, propagates NaNs. :obj:`dpnp.fmod` : Calculate the element-wise remainder of division. @@ -1237,7 +1239,9 @@ def fmin(x1, x2, /, out=None, *, where=True, dtype=None, subok=True, **kwargs): See Also -------- :obj:`dpnp.minimum` : Element-wise minimum of array elements, propagates NaNs. - :obj:`dpnp.fmax` : Element-wise maximum of array elements, ignore NaNs. + :obj:`dpnp.fmax` : Element-wise maximum of array elements, ignores NaNs. + :obj:`dpnp.min` : The minimum value of an array along a given axis, propagates NaNs. + :obj:`dpnp.nanmin` : The minimum value of an array along a given axis, ignores NaNs. :obj:`dpnp.maximum` : Element-wise maximum of array elements, propagates NaNs. :obj:`dpnp.fmod` : Calculate the element-wise remainder of division. diff --git a/dpnp/dpnp_iface_nanfunctions.py b/dpnp/dpnp_iface_nanfunctions.py index 966a2c9a578..a16583fa0c9 100644 --- a/dpnp/dpnp_iface_nanfunctions.py +++ b/dpnp/dpnp_iface_nanfunctions.py @@ -37,6 +37,8 @@ """ +import warnings + import numpy import dpnp @@ -45,8 +47,12 @@ from .dpnp_utils import * __all__ = [ + "nanargmax", + "nanargmin", "nancumprod", "nancumsum", + "nanmax", + "nanmin", "nanprod", "nansum", "nanvar", @@ -94,6 +100,142 @@ def _replace_nan(a, val): return a, mask +def nanargmax(a, axis=None, out=None, *, keepdims=False): + """ + Returns the indices of the maximum values along an axis ignoring NaNs. + + For full documentation refer to :obj:`numpy.nanargmax`. + + Parameters + ---------- + a : {dpnp_array, usm_ndarray} + Input array. + axis : int, optional + Axis along which to search. If ``None``, the function must return + the index of the maximum value of the flattened array. + Default: ``None``. + out : {dpnp_array, usm_ndarray}, optional + If provided, the result will be inserted into this array. It should + be of the appropriate shape and dtype. + keepdims : bool + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. + + Returns + ------- + out : dpnp.ndarray + If `axis` is ``None``, a zero-dimensional array containing the index of + the first occurrence of the maximum value ignoring NaNs; otherwise, a non-zero-dimensional + array containing the indices of the minimum values ignoring NaNs. The returned array + must have the default array index data type. + For all-NaN slices ``ValueError`` is raised. + Warning: the results cannot be trusted if a slice contains only NaNs and -Infs. + + Limitations + ----------- + Input array is only supported as either :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. + Input array data types are limited by supported DPNP :ref:`Data types`. + + See Also + -------- + :obj:`dpnp.nanargmin` : Returns the indices of the minimum values along an axis, igonring NaNs. + :obj:`dpnp.argmax` : Returns the indices of the maximum values along an axis. + + Examples + -------- + >>> import dpnp as np + >>> a = np.array([[np.nan, 4], [2, 3]]) + >>> np.argmax(a) + array(0) + >>> np.nanargmax(a) + array(1) + >>> np.nanargmax(a, axis=0) + array([1, 0]) + >>> np.nanargmax(a, axis=1) + array([1, 1]) + + """ + + a, mask = _replace_nan(a, -dpnp.inf) + if mask is not None: + mask = dpnp.all(mask, axis=axis) + if dpnp.any(mask): + raise ValueError("All-NaN slice encountered") + return dpnp.argmax(a, axis=axis, out=out, keepdims=keepdims) + + +def nanargmin(a, axis=None, out=None, *, keepdims=False): + """ + Returns the indices of the minimum values along an axis ignoring NaNs. + + For full documentation refer to :obj:`numpy.nanargmin`. + + Parameters + ---------- + a : {dpnp_array, usm_ndarray} + Input array. + axis : int, optional + Axis along which to search. If ``None``, the function must return + the index of the minimum value of the flattened array. + Default: ``None``. + out : {dpnp_array, usm_ndarray}, optional + If provided, the result will be inserted into this array. It should + be of the appropriate shape and dtype. + keepdims : bool + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. + + Returns + ------- + out : dpnp.ndarray + If `axis` is ``None``, a zero-dimensional array containing the index of + the first occurrence of the minimum value ignoring NaNs; otherwise, a non-zero-dimensional + array containing the indices of the minimum values ignoring NaNs. The returned array + must have the default array index data type. + For all-NaN slices ``ValueError`` is raised. + Warning: the results cannot be trusted if a slice contains only NaNs and Infs. + + Limitations + ----------- + Input and output arrays are only supported as either :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. + Input array data types are limited by supported DPNP :ref:`Data types`. + + See Also + -------- + :obj:`dpnp.nanargmax` : Returns the indices of the maximum values along an axis, igonring NaNs. + :obj:`dpnp.argmin` : Returns the indices of the minimum values along an axis. + + Examples + -------- + >>> import dpnp as np + >>> a = np.array([[np.nan, 4], [2, 3]]) + >>> np.argmin(a) + array(0) + >>> np.nanargmin(a) + array(2) + >>> np.nanargmin(a, axis=0) + array([1, 1]) + >>> np.nanargmin(a, axis=1) + array([1, 0]) + + """ + + a, mask = _replace_nan(a, dpnp.inf) + if mask is not None: + mask = dpnp.all(mask, axis=axis) + if dpnp.any(mask): + raise ValueError("All-NaN slice encountered") + return dpnp.argmin(a, axis=axis, out=out, keepdims=keepdims) + + def nancumprod(x1, **kwargs): """ Return the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one. @@ -168,36 +310,194 @@ def nancumsum(x1, **kwargs): return call_origin(numpy.nancumsum, x1, **kwargs) -def nansum(x1, **kwargs): +def nanmax(a, axis=None, out=None, keepdims=False, initial=None, where=True): """ - Calculate sum() function treating 'Not a Numbers' (NaN) as zero. + Return the maximum of an array or maximum along an axis, ignoring any NaNs. - For full documentation refer to :obj:`numpy.nansum`. + For full documentation refer to :obj:`numpy.nanmax`. + + Parameters + ---------- + a : {dpnp_array, usm_ndarray} + Input array. + axis : int or tuple of ints, optional + Axis or axes along which maximum values must be computed. By default, + the maximum value must be computed over the entire array. If a tuple of integers, + maximum values must be computed over multiple axes. + Default: ``None``. + out : {dpnp_array, usm_ndarray}, optional + If provided, the result will be inserted into this array. It should + be of the appropriate shape and dtype. + keepdims : bool + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. + + Returns + ------- + out : dpnp.ndarray + If the maximum value was computed over the entire array, a zero-dimensional array + containing the maximum value ignoring NaNs; otherwise, a non-zero-dimensional array + containing the maximum values ignoring NaNs. The returned array must have + the same data type as `a`. + When all-NaN slices are encountered a ``RuntimeWarning`` is raised and NaN is + returned for that slice. Limitations ----------- - Parameter `x1` is supported as :class:`dpnp.ndarray`. - Keyword argument `kwargs` is currently unsupported. - Otherwise the function will be executed sequentially on CPU. + Input array is only supported as either :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. + Parameters `where`, and `initial` are only supported with their default values. + Otherwise ``NotImplementedError`` exception will be raised. Input array data types are limited by supported DPNP :ref:`Data types`. + See Also + -------- + :obj:`dpnp.nanmin` : The minimum value of an array along a given axis, ignoring any NaNs. + :obj:`dpnp.max` : The maximum value of an array along a given axis, propagating any NaNs. + :obj:`dpnp.fmax` : Element-wise maximum of two arrays, ignoring any NaNs. + :obj:`dpnp.maximum` : Element-wise maximum of two arrays, propagating any NaNs. + :obj:`dpnp.isnan` : Shows which elements are Not a Number (NaN). + :obj:`dpnp.isfinite` : Shows which elements are neither NaN nor infinity. + Examples -------- >>> import dpnp as np - >>> np.nansum(np.array([1, 2])) - 3 - >>> np.nansum(np.array([[1, 2], [3, 4]])) - 10 + >>> a = np.array([[1, 2], [3, np.nan]]) + >>> np.nanmax(a) + array(3.) + >>> np.nanmax(a, axis=0) + array([3., 2.]) + >>> np.nanmax(a, axis=1) + array([2., 3.]) + + When positive infinity and negative infinity are present: + + >>> np.nanmax(np.array([1, 2, np.nan, np.NINF])) + array(2.) + >>> np.nanmax(np.array([1, 2, np.nan, np.inf])) + array(inf) """ - x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) - if x1_desc and not kwargs: - result_obj = dpnp_nansum(x1_desc).get_pyobj() - result = dpnp.convert_single_elem_array_to_scalar(result_obj) - return result + if initial is not None: + raise NotImplementedError( + "initial keyword argument is only supported with its default value." + ) + elif where is not True: + raise NotImplementedError( + "where keyword argument is only supported with its default value." + ) + else: + a, mask = _replace_nan(a, -dpnp.inf) + res = dpnp.max(a, axis=axis, out=out, keepdims=keepdims) + if mask is None: + return res + else: + mask = dpnp.all(mask, axis=axis) + if dpnp.any(mask): + dpnp.copyto(res, dpnp.nan, where=mask) + warnings.warn( + "All-NaN slice encountered", RuntimeWarning, stacklevel=2 + ) + return res - return call_origin(numpy.nansum, x1, **kwargs) + +def nanmin(a, axis=None, out=None, keepdims=False, initial=None, where=True): + """ + Return the minimum of an array or minimum along an axis, ignoring any NaNs. + + For full documentation refer to :obj:`numpy.nanmin`. + + Parameters + ---------- + a : {dpnp_array, usm_ndarray} + Input array. + axis : int or tuple of ints, optional + Axis or axes along which minimum values must be computed. By default, + the minimum value must be computed over the entire array. If a tuple of integers, + minimum values must be computed over multiple axes. + Default: ``None``. + out : {dpnp_array, usm_ndarray}, optional + If provided, the result will be inserted into this array. It should + be of the appropriate shape and dtype. + keepdims : bool, optional + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. + + Returns + ------- + out : dpnp.ndarray + If the minimum value was computed over the entire array, a zero-dimensional array + containing the minimum value ignoring NaNs; otherwise, a non-zero-dimensional array + containing the minimum values ignoring NaNs. The returned array must have + the same data type as `a`. + When all-NaN slices are encountered a ``RuntimeWarning`` is raised and NaN is + returned for that slice. + + Limitations + ----------- + Input array is only supported as either :class:`dpnp.ndarray` + or :class:`dpctl.tensor.usm_ndarray`. + Parameters `where`, and `initial` are only supported with their default values. + Otherwise ``NotImplementedError`` exception will be raised. + Input array data types are limited by supported DPNP :ref:`Data types`. + + See Also + -------- + :obj:`dpnp.nanmax` : The maximum value of an array along a given axis, ignoring any NaNs. + :obj:`dpnp.min` : The minimum value of an array along a given axis, propagating any NaNs. + :obj:`dpnp.fmin` : Element-wise minimum of two arrays, ignoring any NaNs. + :obj:`dpnp.minimum` : Element-wise minimum of two arrays, propagating any NaNs. + :obj:`dpnp.isnan` : Shows which elements are Not a Number (NaN). + :obj:`dpnp.isfinite` : Shows which elements are neither NaN nor infinity. + + Examples + -------- + >>> import dpnp as np + >>> a = np.array([[1, 2], [3, np.nan]]) + >>> np.nanmin(a) + array(1.) + >>> np.nanmin(a, axis=0) + array([1., 2.]) + >>> np.nanmin(a, axis=1) + array([1., 3.]) + + When positive infinity and negative infinity are present: + + >>> np.nanmin(np.array([1, 2, np.nan, np.inf])) + array(1.) + >>> np.nanmin(np.array([1, 2, np.nan, np.NINF])) + array(-inf) + + """ + + if initial is not None: + raise NotImplementedError( + "initial keyword argument is only supported with its default value." + ) + elif where is not True: + raise NotImplementedError( + "where keyword argument is only supported with its default value." + ) + else: + a, mask = _replace_nan(a, +dpnp.inf) + res = dpnp.min(a, axis=axis, out=out, keepdims=keepdims) + if mask is None: + return res + else: + mask = dpnp.all(mask, axis=axis) + if dpnp.any(mask): + dpnp.copyto(res, dpnp.nan, where=mask) + warnings.warn( + "All-NaN slice encountered", RuntimeWarning, stacklevel=2 + ) + return res def nanprod( @@ -261,6 +561,38 @@ def nanprod( ) +def nansum(x1, **kwargs): + """ + Calculate sum() function treating 'Not a Numbers' (NaN) as zero. + + For full documentation refer to :obj:`numpy.nansum`. + + Limitations + ----------- + Parameter `x1` is supported as :class:`dpnp.ndarray`. + Keyword argument `kwargs` is currently unsupported. + Otherwise the function will be executed sequentially on CPU. + Input array data types are limited by supported DPNP :ref:`Data types`. + + Examples + -------- + >>> import dpnp as np + >>> np.nansum(np.array([1, 2])) + 3 + >>> np.nansum(np.array([[1, 2], [3, 4]])) + 10 + + """ + + x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_nondefault_queue=False) + if x1_desc and not kwargs: + result_obj = dpnp_nansum(x1_desc).get_pyobj() + result = dpnp.convert_single_elem_array_to_scalar(result_obj) + return result + + return call_origin(numpy.nansum, x1, **kwargs) + + def nanvar( a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True ): diff --git a/dpnp/dpnp_iface_searching.py b/dpnp/dpnp_iface_searching.py index 0210535e169..5187a280d5c 100644 --- a/dpnp/dpnp_iface_searching.py +++ b/dpnp/dpnp_iface_searching.py @@ -60,27 +60,31 @@ def argmax(a, axis=None, out=None, *, keepdims=False): a : {dpnp_array, usm_ndarray} Input array. axis : int, optional - By default, the index is into the flattened array, otherwise - along the specified axis. + Axis along which to search. If ``None``, the function must return + the index of the maximum value of the flattened array. + Default: ``None``. out : {dpnp_array, usm_ndarray}, optional If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. - keepdims : bool, optional - If this is set to True, the axes which are reduced are left - in the result as dimensions with size one. With this option, - the result will broadcast correctly against the array. + keepdims : bool + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. Returns ------- out : dpnp.ndarray - Indices of maximum value of `a`. It has the same shape as `a.shape` - with the dimension along `axis` removed. If `keepdims` is set to True, - then the size of `axis` will be 1 with the resulting array having same - shape as `a.shape`. + If `axis` is ``None``, a zero-dimensional array containing the index of + the first occurrence of the maximum value; otherwise, a non-zero-dimensional + array containing the indices of the minimum values. The returned array + must have the default array index data type. See Also -------- :obj:`dpnp.ndarray.argmax` : Equivalent function. + :obj:`dpnp.nanargmax` : Returns the indices of the maximum values along an axis, igonring NaNs. :obj:`dpnp.argmin` : Returns the indices of the minimum values along an axis. :obj:`dpnp.max` : The maximum value along a given axis. :obj:`dpnp.unravel_index` : Convert a flat index into an index tuple. @@ -140,27 +144,31 @@ def argmin(a, axis=None, out=None, *, keepdims=False): a : {dpnp_array, usm_ndarray} Input array. axis : int, optional - By default, the index is into the flattened array, otherwise - along the specified axis. + Axis along which to search. If ``None``, the function must return + the index of the minimum value of the flattened array. + Default: ``None``. out : {dpnp_array, usm_ndarray}, optional If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. keepdims : bool, optional - If this is set to True, the axes which are reduced are left - in the result as dimensions with size one. With this option, - the result will broadcast correctly against the array. + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. Returns ------- out : dpnp.ndarray - Indices of minimum value of `a`. It has the same shape as `a.shape` - with the dimension along `axis` removed. If `keepdims` is set to True, - then the size of `axis` will be 1 with the resulting array having same - shape as `a.shape`. + If `axis` is ``None``, a zero-dimensional array containing the index of + the first occurrence of the minimum value; otherwise, a non-zero-dimensional + array containing the indices of the minimum values. The returned array + must have the default array index data type. See Also -------- :obj:`dpnp.ndarray.argmin` : Equivalent function. + :obj:`dpnp.nanargmin` : Returns the indices of the minimum values along an axis, igonring NaNs. :obj:`dpnp.argmax` : Returns the indices of the maximum values along an axis. :obj:`dpnp.min` : The minimum value along a given axis. :obj:`dpnp.unravel_index` : Convert a flat index into an index tuple. diff --git a/dpnp/dpnp_iface_statistics.py b/dpnp/dpnp_iface_statistics.py index 5d00154659c..4e4201c97cd 100644 --- a/dpnp/dpnp_iface_statistics.py +++ b/dpnp/dpnp_iface_statistics.py @@ -374,14 +374,36 @@ def max(a, axis=None, out=None, keepdims=False, initial=None, where=True): For full documentation refer to :obj:`numpy.max`. + Parameters + ---------- + a : {dpnp_array, usm_ndarray} + Input array. + axis : int or tuple of ints, optional + Axis or axes along which maximum values must be computed. By default, + the maximum value must be computed over the entire array. If a tuple of integers, + maximum values must be computed over multiple axes. + Default: ``None``. + out : {dpnp_array, usm_ndarray}, optional + If provided, the result will be inserted into this array. It should + be of the appropriate shape and dtype. + keepdims : bool + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. + Returns ------- out : dpnp.ndarray - Maximum of `a`. + If the maximum value was computed over the entire array, a zero-dimensional array + containing the maximum value; otherwise, a non-zero-dimensional array + containing the maximum values. The returned array must have + the same data type as `a`. Limitations ----------- - Input and output arrays are only supported as either :class:`dpnp.ndarray` + Input array is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Parameters `where`, and `initial` are only supported with their default values. Otherwise ``NotImplementedError`` exception will be raised. @@ -549,14 +571,36 @@ def min(a, axis=None, out=None, keepdims=False, initial=None, where=True): For full documentation refer to :obj:`numpy.min`. + Parameters + ---------- + a : {dpnp_array, usm_ndarray} + Input array. + axis : int or tuple of ints, optional + Axis or axes along which minimum values must be computed. By default, + the minimum value must be computed over the entire array. If a tuple of integers, + minimum values must be computed over multiple axes. + Default: ``None``. + out : {dpnp_array, usm_ndarray}, optional + If provided, the result will be inserted into this array. It should + be of the appropriate shape and dtype. + keepdims : bool, optional + If ``True``, the reduced axes (dimensions) must be included in the + result as singleton dimensions, and, accordingly, the result must be + compatible with the input array. Otherwise, if ``False``, the reduced + axes (dimensions) must not be included in the result. + Default: ``False``. + Returns ------- out : dpnp.ndarray - Minimum of `a`. + If the minimum value was computed over the entire array, a zero-dimensional array + containing the minimum value; otherwise, a non-zero-dimensional array + containing the minimum values. The returned array must have + the same data type as `a`. Limitations ----------- - Input and output arrays are only supported as either :class:`dpnp.ndarray` + Input array is only supported as either :class:`dpnp.ndarray` or :class:`dpctl.tensor.usm_ndarray`. Parameters `where`, and `initial` are only supported with their default values. Otherwise ``NotImplementedError`` exception will be raised. diff --git a/tests/conftest.py b/tests/conftest.py index 231af2e34fa..6b9d01691a3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -137,6 +137,13 @@ def suppress_mean_empty_slice_numpy_warnings(): yield +@pytest.fixture +def suppress_overflow_encountered_in_cast_numpy_warnings(): + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", r"overflow encountered in cast") + yield + + @pytest.fixture def suppress_divide_invalid_numpy_warnings( suppress_divide_numpy_warnings, suppress_invalid_numpy_warnings diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index c3d1fd8b077..15572947eee 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -768,34 +768,6 @@ tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_1_{ar tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_2_{array=array([], dtype=float64)}::test_flatnonzero tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_3_{array=array([], shape=(0, 2), dtype=float64)}::test_flatnonzero tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_4_{array=array([], shape=(0, 2, 0), dtype=float64)}::test_flatnonzero -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_all -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis1 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis_large -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan3 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan4 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan5 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_tie -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_zero_size -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_zero_size_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_zero_size_axis1 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_all -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis1 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis_large -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan3 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan4 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan5 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_tie -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_zero_size -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_zero_size_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_zero_size_axis1 tests/third_party/cupy/sorting_tests/test_search.py::TestNonzeroZeroDimension_param_0_{array=array(0)}::test_nonzero tests/third_party/cupy/sorting_tests/test_search.py::TestNonzeroZeroDimension_param_1_{array=array(1)}::test_nonzero tests/third_party/cupy/sorting_tests/test_sort.py::TestArgpartition_param_0_{external=False}::test_argpartition_axis @@ -1038,29 +1010,43 @@ tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_6_{ tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_7_{axis=None, ddof=1, keepdims=False, shape=(4, 3, 5)}::test_nanstd tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_8_{axis=0, ddof=0, keepdims=True, shape=(3, 4)}::test_nanstd tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_9_{axis=0, ddof=0, keepdims=True, shape=(4, 3, 5)}::test_nanstd -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_all -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_all_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis0 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis1 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis2 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis_large -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_all -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_all_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis0 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis1 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis2 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis_large -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_uxpected_interpolation + +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_unxpected_method tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_all_nan tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_nan diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 86805a4560b..dae91d41ac3 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -830,34 +830,6 @@ tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_1_{ar tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_2_{array=array([], dtype=float64)}::test_flatnonzero tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_3_{array=array([], shape=(0, 2), dtype=float64)}::test_flatnonzero tests/third_party/cupy/sorting_tests/test_search.py::TestFlatNonzero_param_4_{array=array([], shape=(0, 2, 0), dtype=float64)}::test_flatnonzero -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_all -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis1 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_axis_large -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan3 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan4 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_nan5 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_tie -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_zero_size -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_zero_size_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMax::test_nanargmax_zero_size_axis1 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_all -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis1 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_axis_large -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan2 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan3 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan4 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_nan5 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_tie -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_zero_size -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_zero_size_axis0 -tests/third_party/cupy/sorting_tests/test_search.py::TestNanArgMin::test_nanargmin_zero_size_axis1 tests/third_party/cupy/sorting_tests/test_search.py::TestNonzeroZeroDimension_param_0_{array=array(0)}::test_nonzero tests/third_party/cupy/sorting_tests/test_search.py::TestNonzeroZeroDimension_param_1_{array=array(1)}::test_nonzero tests/third_party/cupy/sorting_tests/test_sort.py::TestArgpartition_param_0_{external=False}::test_argpartition_axis @@ -1100,29 +1072,43 @@ tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_6_{ tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_7_{axis=None, ddof=1, keepdims=False, shape=(4, 3, 5)}::test_nanstd tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_8_{axis=0, ddof=0, keepdims=True, shape=(3, 4)}::test_nanstd tests/third_party/cupy/statistics_tests/test_meanvar.py::TestNanVarStd_param_9_{axis=0, ddof=0, keepdims=True, shape=(4, 3, 5)}::test_nanstd -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_all -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_all_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis0 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis1 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis2 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_axis_large -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmax_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_all -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_all_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis0 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis1 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis2 -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_axis_large -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_nanmin_nan -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis -tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_uxpected_interpolation + +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_bad_q[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_defaults[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_keepdims[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_neg_axis[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_no_axis[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_out[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_q_list[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_scalar_q[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[linear] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[lower] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[higher] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_tuple_axis[midpoint] +tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_percentile_unxpected_method tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_all_nan tests/third_party/cupy/statistics_tests/test_order.py::TestOrder::test_ptp_nan diff --git a/tests/test_mathematical.py b/tests/test_mathematical.py index 3cfbd88b4dc..af3e5fd79fe 100644 --- a/tests/test_mathematical.py +++ b/tests/test_mathematical.py @@ -700,8 +700,8 @@ def test_positive_boolean(): @pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True)) def test_prod_nanprod(func, axis, keepdims, dtype): a = numpy.arange(1, 13, dtype=dtype).reshape((2, 2, 3)) - if func == "nanprod" and issubclass(a.dtype.type, dpnp.inexact): - a[1:2:] = numpy.nan + if func == "nanprod" and dpnp.issubdtype(a.dtype, dpnp.inexact): + a[:, :, 2] = numpy.nan ia = dpnp.array(a) np_res = getattr(numpy, func)(a, axis=axis, keepdims=keepdims) @@ -718,24 +718,20 @@ def test_prod_zero_size(axis): np_res = numpy.prod(a, axis=axis) dpnp_res = dpnp.prod(ia, axis=axis) - - assert dpnp_res.shape == np_res.shape - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) @pytest.mark.parametrize("func", ["prod", "nanprod"]) @pytest.mark.parametrize("axis", [None, 0, 1, -1]) @pytest.mark.parametrize("keepdims", [False, True]) def test_prod_nanprod_bool(func, axis, keepdims): - a = numpy.arange(2, dtype=dpnp.bool) + a = numpy.arange(2, dtype=numpy.bool_) a = numpy.tile(a, (2, 2)) ia = dpnp.array(a) np_res = getattr(numpy, func)(a, axis=axis, keepdims=keepdims) dpnp_res = getattr(dpnp, func)(ia, axis=axis, keepdims=keepdims) - - assert dpnp_res.shape == np_res.shape - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) @pytest.mark.usefixtures("allow_fall_back_on_numpy") @@ -743,41 +739,48 @@ def test_prod_nanprod_bool(func, axis, keepdims): @pytest.mark.usefixtures("suppress_invalid_numpy_warnings") @pytest.mark.parametrize("func", ["prod", "nanprod"]) @pytest.mark.parametrize("in_dtype", get_all_dtypes(no_bool=True)) -@pytest.mark.parametrize("out_dtype", get_all_dtypes(no_bool=True)) +@pytest.mark.parametrize( + "out_dtype", get_all_dtypes(no_bool=True, no_none=True) +) def test_prod_nanprod_dtype(func, in_dtype, out_dtype): a = numpy.arange(1, 13, dtype=in_dtype).reshape((2, 2, 3)) - if func == "nanprod" and issubclass(a.dtype.type, dpnp.inexact): - a[1:2:] = numpy.nan + if func == "nanprod" and dpnp.issubdtype(a.dtype, dpnp.inexact): + a[:, :, 2] = numpy.nan ia = dpnp.array(a) np_res = getattr(numpy, func)(a, dtype=out_dtype) dpnp_res = getattr(dpnp, func)(ia, dtype=out_dtype) - - if out_dtype is not None: - assert dpnp_res.dtype == out_dtype - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) +@pytest.mark.usefixtures("suppress_overflow_encountered_in_cast_numpy_warnings") @pytest.mark.parametrize("func", ["prod", "nanprod"]) def test_prod_nanprod_out(func): - a = numpy.arange(1, 7).reshape((2, 3)) - if func == "nanprod" and issubclass(a.dtype.type, dpnp.inexact): - a[1:2:] = numpy.nan - ia = dpnp.array(a) + ia = dpnp.arange(1, 7).reshape((2, 3)) + ia = ia.astype(dpnp.default_float_type(ia.device)) + if func == "nanprod": + ia[:, 1] = dpnp.nan + a = dpnp.asnumpy(ia) + # output is dpnp_array np_res = getattr(numpy, func)(a, axis=0) - dpnp_res = dpnp.array(numpy.empty_like(np_res)) - getattr(dpnp, func)(ia, axis=0, out=dpnp_res) + dpnp_out = dpnp.empty(np_res.shape, dtype=np_res.dtype) + dpnp_res = getattr(dpnp, func)(ia, axis=0, out=dpnp_out) + assert dpnp_out is dpnp_res assert_allclose(dpnp_res, np_res) - dpnp_res = dpt.asarray(numpy.empty_like(np_res)) - getattr(dpnp, func)(ia, axis=0, out=dpnp_res) + # output is usm_ndarray + dpt_out = dpt.empty(np_res.shape, dtype=np_res.dtype) + dpnp_res = getattr(dpnp, func)(ia, axis=0, out=dpt_out) + assert dpt_out is dpnp_res.get_array() assert_allclose(dpnp_res, np_res) + # out is a numpy array -> TypeError dpnp_res = numpy.empty_like(np_res) with pytest.raises(TypeError): getattr(dpnp, func)(ia, axis=0, out=dpnp_res) + # incorrect shape for out dpnp_res = dpnp.array(numpy.empty((2, 3))) with pytest.raises(ValueError): getattr(dpnp, func)(ia, axis=0, out=dpnp_res) diff --git a/tests/test_search.py b/tests/test_search.py index aa5a2c9915c..56f4f23739c 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -5,58 +5,66 @@ import dpnp -from .helper import get_all_dtypes +from .helper import assert_dtype_allclose, get_all_dtypes -@pytest.mark.parametrize("func", ["argmax", "argmin"]) +@pytest.mark.parametrize("func", ["argmax", "argmin", "nanargmin", "nanargmax"]) @pytest.mark.parametrize("axis", [None, 0, 1, -1, 2, -2]) @pytest.mark.parametrize("keepdims", [False, True]) @pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True)) def test_argmax_argmin(func, axis, keepdims, dtype): a = numpy.arange(768, dtype=dtype).reshape((4, 4, 6, 8)) + if func in ["nanargmin", "nanargmax"] and dpnp.issubdtype( + a.dtype, dpnp.inexact + ): + a[2:3, 2, 3:4, 4] = numpy.nan ia = dpnp.array(a) np_res = getattr(numpy, func)(a, axis=axis, keepdims=keepdims) dpnp_res = getattr(dpnp, func)(ia, axis=axis, keepdims=keepdims) - - assert dpnp_res.shape == np_res.shape - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) @pytest.mark.parametrize("func", ["argmax", "argmin"]) @pytest.mark.parametrize("axis", [None, 0, 1, -1]) @pytest.mark.parametrize("keepdims", [False, True]) def test_argmax_argmin_bool(func, axis, keepdims): - a = numpy.arange(2, dtype=dpnp.bool) + a = numpy.arange(2, dtype=numpy.bool_) a = numpy.tile(a, (2, 2)) ia = dpnp.array(a) np_res = getattr(numpy, func)(a, axis=axis, keepdims=keepdims) dpnp_res = getattr(dpnp, func)(ia, axis=axis, keepdims=keepdims) - - assert dpnp_res.shape == np_res.shape - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) -@pytest.mark.parametrize("func", ["argmax", "argmin"]) +@pytest.mark.parametrize("func", ["argmax", "argmin", "nanargmin", "nanargmax"]) def test_argmax_argmin_out(func): - a = numpy.arange(6).reshape((2, 3)) + a = numpy.arange(12, dtype=numpy.float32).reshape((2, 2, 3)) + if func in ["nanargmin", "nanargmax"]: + a[1, 0, 2] = numpy.nan ia = dpnp.array(a) + # out is dpnp_array np_res = getattr(numpy, func)(a, axis=0) - dpnp_res = dpnp.array(numpy.empty_like(np_res)) - getattr(dpnp, func)(ia, axis=0, out=dpnp_res) + dpnp_out = dpnp.empty(np_res.shape, dtype=np_res.dtype) + dpnp_res = getattr(dpnp, func)(ia, axis=0, out=dpnp_out) + assert dpnp_out is dpnp_res assert_allclose(dpnp_res, np_res) - dpnp_res = dpt.asarray(numpy.empty_like(np_res)) - getattr(dpnp, func)(ia, axis=0, out=dpnp_res) + # out is usm_ndarray + dpt_out = dpt.empty(np_res.shape, dtype=np_res.dtype) + dpnp_res = getattr(dpnp, func)(ia, axis=0, out=dpt_out) + assert dpt_out is dpnp_res.get_array() assert_allclose(dpnp_res, np_res) + # out is a numpy array -> TypeError dpnp_res = numpy.empty_like(np_res) with pytest.raises(TypeError): getattr(dpnp, func)(ia, axis=0, out=dpnp_res) - dpnp_res = dpnp.array(numpy.empty((2, 3))) + # out shape is incorrect -> ValueError + dpnp_res = dpnp.array(numpy.empty((2, 2))) with pytest.raises(ValueError): getattr(dpnp, func)(ia, axis=0, out=dpnp_res) @@ -64,13 +72,23 @@ def test_argmax_argmin_out(func): @pytest.mark.parametrize("axis", [None, 0, 1, -1]) @pytest.mark.parametrize("keepdims", [False, True]) def test_ndarray_argmax_argmin(axis, keepdims): - a = numpy.arange(192, dtype="f4").reshape((4, 6, 8)) + a = numpy.arange(192, dtype=numpy.float32).reshape((4, 6, 8)) ia = dpnp.array(a) np_res = a.argmax(axis=axis, keepdims=keepdims) dpnp_res = ia.argmax(axis=axis, keepdims=keepdims) - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) np_res = a.argmin(axis=axis, keepdims=keepdims) dpnp_res = ia.argmin(axis=axis, keepdims=keepdims) - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) + + +@pytest.mark.parametrize("func", ["nanargmin", "nanargmax"]) +def test_nanargmax_nanargmin_error(func): + ia = dpnp.arange(12, dtype=dpnp.float32).reshape((2, 2, 3)) + ia[:, :, 2] = dpnp.nan + + # All-NaN slice encountered -> ValueError + with pytest.raises(ValueError): + getattr(dpnp, func)(ia, axis=0) diff --git a/tests/test_statistics.py b/tests/test_statistics.py index 3caaaf9c805..f3866b3c27e 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -1,3 +1,5 @@ +import warnings + import dpctl.tensor as dpt import numpy import pytest @@ -30,50 +32,52 @@ def test_median(dtype, size): assert_allclose(dpnp_res, np_res) -@pytest.mark.parametrize("func", ["max", "min"]) +@pytest.mark.parametrize("func", ["max", "min", "nanmax", "nanmin"]) @pytest.mark.parametrize("axis", [None, 0, 1, -1, 2, -2, (1, 2), (0, -2)]) @pytest.mark.parametrize("keepdims", [False, True]) @pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True)) def test_max_min(func, axis, keepdims, dtype): a = numpy.arange(768, dtype=dtype).reshape((4, 4, 6, 8)) + if func in ["nanmax", "nanmin"] and dpnp.issubdtype(a.dtype, dpnp.inexact): + a[2:3, 2, 3:4, 4] = numpy.nan ia = dpnp.array(a) np_res = getattr(numpy, func)(a, axis=axis, keepdims=keepdims) dpnp_res = getattr(dpnp, func)(ia, axis=axis, keepdims=keepdims) - - assert dpnp_res.shape == np_res.shape - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) @pytest.mark.parametrize("func", ["max", "min"]) @pytest.mark.parametrize("axis", [None, 0, 1, -1]) @pytest.mark.parametrize("keepdims", [False, True]) def test_max_min_bool(func, axis, keepdims): - a = numpy.arange(2, dtype=dpnp.bool) + a = numpy.arange(2, dtype=numpy.bool_) a = numpy.tile(a, (2, 2)) ia = dpnp.array(a) np_res = getattr(numpy, func)(a, axis=axis, keepdims=keepdims) dpnp_res = getattr(dpnp, func)(ia, axis=axis, keepdims=keepdims) - - assert dpnp_res.shape == np_res.shape - assert_allclose(dpnp_res, np_res) + assert_dtype_allclose(dpnp_res, np_res) -@pytest.mark.parametrize("func", ["max", "min"]) +@pytest.mark.parametrize("func", ["max", "min", "nanmax", "nanmin"]) def test_max_min_out(func): - a = numpy.arange(6).reshape((2, 3)) + a = numpy.arange(12, dtype=numpy.float32).reshape((2, 2, 3)) + if func in ["nanmax", "nanmin"]: + a[1, 0, 2] = numpy.nan ia = dpnp.array(a) + # out is dpnp_array np_res = getattr(numpy, func)(a, axis=0) - # output is dpnp array - dpnp_res = dpnp.array(numpy.empty_like(np_res)) - getattr(dpnp, func)(ia, axis=0, out=dpnp_res) + dpnp_out = dpnp.empty(np_res.shape, dtype=np_res.dtype) + dpnp_res = getattr(dpnp, func)(ia, axis=0, out=dpnp_out) + assert dpnp_out is dpnp_res assert_allclose(dpnp_res, np_res) - # output is usm array - dpnp_res = dpt.asarray(numpy.empty_like(np_res)) - getattr(dpnp, func)(ia, axis=0, out=dpnp_res) + # out is usm_ndarray + dpt_out = dpt.empty(np_res.shape, dtype=np_res.dtype) + dpnp_res = getattr(dpnp, func)(ia, axis=0, out=dpt_out) + assert dpt_out is dpnp_res.get_array() assert_allclose(dpnp_res, np_res) # output is numpy array -> Error @@ -82,12 +86,12 @@ def test_max_min_out(func): getattr(dpnp, func)(ia, axis=0, out=dpnp_res) # output has incorrect shape -> Error - dpnp_res = dpnp.array(numpy.empty((2, 3))) + dpnp_res = dpnp.array(numpy.empty((4, 2))) with pytest.raises(ValueError): getattr(dpnp, func)(ia, axis=0, out=dpnp_res) -@pytest.mark.parametrize("func", ["max", "min"]) +@pytest.mark.parametrize("func", ["max", "min", "nanmax", "nanmin"]) def test_max_min_error(func): ia = dpnp.arange(5) # where is not supported @@ -99,6 +103,32 @@ def test_max_min_error(func): getattr(dpnp, func)(ia, initial=6) +@pytest.mark.parametrize("func", ["nanmax", "nanmin"]) +@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True)) +def test_nanmax_nanmin_no_NaN(func, dtype): + a = numpy.arange(768, dtype=dtype).reshape((4, 4, 6, 8)) + ia = dpnp.array(a) + + np_res = getattr(numpy, func)(a, axis=0) + dpnp_res = getattr(dpnp, func)(ia, axis=0) + assert_dtype_allclose(dpnp_res, np_res) + + +@pytest.mark.parametrize("func", ["nanmax", "nanmin"]) +def test_nanmax_nanmin_all_NaN(recwarn, func): + a = numpy.arange(12, dtype=numpy.float32).reshape((2, 2, 3)) + a[:, :, 2] = numpy.nan + ia = dpnp.array(a) + + np_res = getattr(numpy, func)(a, axis=0) + dpnp_res = getattr(dpnp, func)(ia, axis=0) + assert_dtype_allclose(dpnp_res, np_res) + + assert len(recwarn) == 2 + assert all("All-NaN slice encountered" in str(r.message) for r in recwarn) + assert all(r.category is RuntimeWarning for r in recwarn) + + class TestMean: @pytest.mark.parametrize("dtype", get_all_dtypes()) def test_mean_axis_tuple(self, dtype): diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index 26d047c103d..31196e2b3da 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -369,8 +369,12 @@ def test_meshgrid(device_x, device_y): pytest.param("max", [1.0, 2.0, 4.0, 7.0]), pytest.param("mean", [1.0, 2.0, 4.0, 7.0]), pytest.param("min", [1.0, 2.0, 4.0, 7.0]), + pytest.param("nanargmax", [1.0, 2.0, 4.0, dpnp.nan]), + pytest.param("nanargmin", [1.0, 2.0, 4.0, dpnp.nan]), pytest.param("nancumprod", [1.0, dpnp.nan]), pytest.param("nancumsum", [1.0, dpnp.nan]), + pytest.param("nanmax", [1.0, 2.0, 4.0, dpnp.nan]), + pytest.param("nanmin", [1.0, 2.0, 4.0, dpnp.nan]), pytest.param("nanprod", [1.0, dpnp.nan]), pytest.param("nansum", [1.0, dpnp.nan]), pytest.param("nanvar", [1.0, 2.0, 4.0, dpnp.nan]), diff --git a/tests/test_usm_type.py b/tests/test_usm_type.py index b889bab6010..c69671e5bb0 100644 --- a/tests/test_usm_type.py +++ b/tests/test_usm_type.py @@ -399,6 +399,10 @@ def test_meshgrid(usm_type_x, usm_type_y): pytest.param("max", [1.0, 2.0, 4.0, 7.0]), pytest.param("mean", [1.0, 2.0, 4.0, 7.0]), pytest.param("min", [1.0, 2.0, 4.0, 7.0]), + pytest.param("nanargmax", [1.0, 2.0, 4.0, dp.nan]), + pytest.param("nanargmin", [1.0, 2.0, 4.0, dp.nan]), + pytest.param("nanmax", [1.0, 2.0, 4.0, dp.nan]), + pytest.param("nanmin", [1.0, 2.0, 4.0, dp.nan]), pytest.param("negative", [1.0, 0.0, -1.0]), pytest.param("positive", [1.0, 0.0, -1.0]), pytest.param("prod", [1.0, 2.0]), diff --git a/tests/third_party/cupy/sorting_tests/test_search.py b/tests/third_party/cupy/sorting_tests/test_search.py index edfe4ea02ed..d14503d6c17 100644 --- a/tests/third_party/cupy/sorting_tests/test_search.py +++ b/tests/third_party/cupy/sorting_tests/test_search.py @@ -366,40 +366,39 @@ def test_argwhere(self, xp, dtype): # return cupy.nonzero(self.array) -@testing.gpu -class TestNanArgMin(unittest.TestCase): +class TestNanArgMin: @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_nanargmin_all(self, xp, dtype): a = testing.shaped_random((2, 3), xp, dtype) return xp.nanargmin(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmin_nan(self, xp, dtype): a = xp.array([float("nan"), -1, 1], dtype) return xp.nanargmin(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmin_nan2(self, xp, dtype): a = xp.array([float("nan"), float("nan"), -1, 1], dtype) return xp.nanargmin(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmin_nan3(self, xp, dtype): a = xp.array([float("nan"), float("nan"), -1, 1, 1.0, -2.0], dtype) return xp.nanargmin(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmin_nan4(self, xp, dtype): a = xp.array([-1, 1, 1.0, -2.0, float("nan"), float("nan")], dtype) return xp.nanargmin(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmin_nan5(self, xp, dtype): a = xp.array( [-1, 1, 1.0, -2.0, float("nan"), float("nan"), -1, 1], dtype @@ -457,40 +456,39 @@ def test_nanargmin_zero_size_axis1(self, xp, dtype): return xp.nanargmin(a, axis=1) -@testing.gpu -class TestNanArgMax(unittest.TestCase): +class TestNanArgMax: @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() def test_nanargmax_all(self, xp, dtype): a = testing.shaped_random((2, 3), xp, dtype) return xp.nanargmax(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmax_nan(self, xp, dtype): a = xp.array([float("nan"), -1, 1], dtype) return xp.nanargmax(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmax_nan2(self, xp, dtype): a = xp.array([float("nan"), float("nan"), -1, 1], dtype) return xp.nanargmax(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmax_nan3(self, xp, dtype): a = xp.array([float("nan"), float("nan"), -1, 1, 1.0, -2.0], dtype) return xp.nanargmax(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmax_nan4(self, xp, dtype): a = xp.array([-1, 1, 1.0, -2.0, float("nan"), float("nan")], dtype) return xp.nanargmax(a) - @testing.for_all_dtypes(no_complex=True) - @testing.numpy_cupy_allclose(accept_error=ValueError) + @testing.for_float_dtypes() + @testing.numpy_cupy_allclose() def test_nanargmax_nan5(self, xp, dtype): a = xp.array( [-1, 1, 1.0, -2.0, float("nan"), float("nan"), -1, 1], dtype diff --git a/tests/third_party/cupy/statistics_tests/test_order.py b/tests/third_party/cupy/statistics_tests/test_order.py index 2ca82b473b5..62ac2f72b36 100644 --- a/tests/third_party/cupy/statistics_tests/test_order.py +++ b/tests/third_party/cupy/statistics_tests/test_order.py @@ -7,106 +7,110 @@ import dpnp as cupy from tests.third_party.cupy import testing -_all_interpolations = ( +_all_methods = ( + # "inverted_cdf", # TODO(takagi) Not implemented + # "averaged_inverted_cdf", # TODO(takagi) Not implemented + # "closest_observation", # TODO(takagi) Not implemented + # "interpolated_inverted_cdf", # TODO(takagi) Not implemented + # "hazen", # TODO(takagi) Not implemented + # "weibull", # TODO(takagi) Not implemented + "linear", + # "median_unbiased", # TODO(takagi) Not implemented + # "normal_unbiased", # TODO(takagi) Not implemented "lower", "higher", "midpoint", - # 'nearest', # TODO(hvy): Not implemented - "linear", + # "nearest", # TODO(hvy): Not implemented ) -def for_all_interpolations(name="interpolation"): - return testing.for_orders(_all_interpolations, name=name) +def for_all_methods(name="method"): + return pytest.mark.parametrize(name, _all_methods) -@testing.gpu -class TestOrder(unittest.TestCase): - @for_all_interpolations() +@testing.with_requires("numpy>=1.22.0rc1") +class TestOrder: + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) @testing.numpy_cupy_allclose() - def test_percentile_defaults(self, xp, dtype, interpolation): + def test_percentile_defaults(self, xp, dtype, method): a = testing.shaped_random((2, 3, 8), xp, dtype) q = testing.shaped_random((3,), xp, dtype=dtype, scale=100) - return xp.percentile(a, q, interpolation=interpolation) + return xp.percentile(a, q, method=method) - @for_all_interpolations() + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) @testing.numpy_cupy_allclose() - def test_percentile_q_list(self, xp, dtype, interpolation): + def test_percentile_q_list(self, xp, dtype, method): a = testing.shaped_arange((1001,), xp, dtype) q = [99, 99.9] - return xp.percentile(a, q, interpolation=interpolation) + return xp.percentile(a, q, method=method) - @for_all_interpolations() + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) @testing.numpy_cupy_allclose(rtol=1e-6) - def test_percentile_no_axis(self, xp, dtype, interpolation): + def test_percentile_no_axis(self, xp, dtype, method): a = testing.shaped_random((10, 2, 4, 8), xp, dtype) q = testing.shaped_random((5,), xp, dtype=dtype, scale=100) - return xp.percentile(a, q, axis=None, interpolation=interpolation) + return xp.percentile(a, q, axis=None, method=method) - @for_all_interpolations() + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) @testing.numpy_cupy_allclose(rtol=1e-6) - def test_percentile_neg_axis(self, xp, dtype, interpolation): + def test_percentile_neg_axis(self, xp, dtype, method): a = testing.shaped_random((4, 3, 10, 2, 8), xp, dtype) q = testing.shaped_random((5,), xp, dtype=dtype, scale=100) - return xp.percentile(a, q, axis=-1, interpolation=interpolation) + return xp.percentile(a, q, axis=-1, method=method) - @for_all_interpolations() + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) @testing.numpy_cupy_allclose(rtol=1e-6) - def test_percentile_tuple_axis(self, xp, dtype, interpolation): + def test_percentile_tuple_axis(self, xp, dtype, method): a = testing.shaped_random((1, 6, 3, 2), xp, dtype) q = testing.shaped_random((5,), xp, dtype=dtype, scale=100) - return xp.percentile(a, q, axis=(0, 1, 2), interpolation=interpolation) + return xp.percentile(a, q, axis=(0, 1, 2), method=method) - @for_all_interpolations() + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) @testing.numpy_cupy_allclose() - def test_percentile_scalar_q(self, xp, dtype, interpolation): + def test_percentile_scalar_q(self, xp, dtype, method): a = testing.shaped_random((2, 3, 8), xp, dtype) q = 13.37 - return xp.percentile(a, q, interpolation=interpolation) + return xp.percentile(a, q, method=method) - @for_all_interpolations() + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) @testing.numpy_cupy_allclose(rtol=1e-5) - def test_percentile_keepdims(self, xp, dtype, interpolation): + def test_percentile_keepdims(self, xp, dtype, method): a = testing.shaped_random((7, 2, 9, 2), xp, dtype) q = testing.shaped_random((5,), xp, dtype=dtype, scale=100) - return xp.percentile( - a, q, axis=None, keepdims=True, interpolation=interpolation - ) + return xp.percentile(a, q, axis=None, keepdims=True, method=method) - @for_all_interpolations() + @for_all_methods() @testing.for_float_dtypes(no_float16=True) # NumPy raises error on int8 @testing.numpy_cupy_allclose(rtol=1e-6) - def test_percentile_out(self, xp, dtype, interpolation): + def test_percentile_out(self, xp, dtype, method): a = testing.shaped_random((10, 2, 3, 2), xp, dtype) q = testing.shaped_random((5,), xp, dtype=dtype, scale=100) out = testing.shaped_random((5, 10, 2, 3), xp, dtype) - return xp.percentile( - a, q, axis=-1, interpolation=interpolation, out=out - ) + return xp.percentile(a, q, axis=-1, method=method, out=out) - @for_all_interpolations() + @for_all_methods() @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) - def test_percentile_bad_q(self, dtype, interpolation): + def test_percentile_bad_q(self, dtype, method): for xp in (numpy, cupy): a = testing.shaped_random((4, 2, 3, 2), xp, dtype) q = testing.shaped_random((1, 2, 3), xp, dtype=dtype, scale=100) with pytest.raises(ValueError): - xp.percentile(a, q, axis=-1, interpolation=interpolation) + xp.percentile(a, q, axis=-1, method=method) @testing.for_all_dtypes(no_float16=True, no_bool=True, no_complex=True) - def test_percentile_uxpected_interpolation(self, dtype): + def test_percentile_unxpected_method(self, dtype): for xp in (numpy, cupy): a = testing.shaped_random((4, 2, 3, 2), xp, dtype) q = testing.shaped_random((5,), xp, dtype=dtype, scale=100) with pytest.raises(ValueError): - xp.percentile(a, q, axis=-1, interpolation="deadbeef") + xp.percentile(a, q, axis=-1, method="deadbeef") @testing.for_all_dtypes(no_complex=True) @testing.numpy_cupy_allclose() @@ -152,8 +156,8 @@ def test_nanmax_all_nan(self, xp, dtype): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") m = xp.nanmax(a) - self.assertEqual(len(w), 1) - self.assertIs(w[0].category, RuntimeWarning) + assert len(w) == 1 + assert w[0].category is RuntimeWarning return m @testing.for_all_dtypes(no_complex=True) @@ -200,8 +204,8 @@ def test_nanmin_all_nan(self, xp, dtype): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") m = xp.nanmin(a) - self.assertEqual(len(w), 1) - self.assertIs(w[0].category, RuntimeWarning) + assert len(w) == 1 + assert w[0].category is RuntimeWarning return m @testing.for_all_dtypes(no_bool=True)