From 78fa325e653d0298bcff1be372c85cdf377d420a Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 20:40:44 +0200 Subject: [PATCH 01/12] Implement dpnp.digitize --- dpnp/dpnp_iface_histograms.py | 91 ++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/dpnp/dpnp_iface_histograms.py b/dpnp/dpnp_iface_histograms.py index 919c3f64b99d..6745336f4694 100644 --- a/dpnp/dpnp_iface_histograms.py +++ b/dpnp/dpnp_iface_histograms.py @@ -46,6 +46,7 @@ import dpnp __all__ = [ + "digitize", "histogram", "histogram_bin_edges", ] @@ -174,7 +175,6 @@ def _get_bin_edges(a, bins, range, usm_type): # numpy's gh-10322 means that type resolution rules are dependent on # array shapes. To avoid this causing problems, we pick a type now and # stick with it throughout. - # pylint: disable=possibly-used-before-assignment bin_type = dpnp.result_type(first_edge, last_edge, a) if dpnp.issubdtype(bin_type, dpnp.integer): bin_type = dpnp.result_type( @@ -208,6 +208,94 @@ def _search_sorted_inclusive(a, v): ) +def digitize(x, bins, right=False): + """ + Return the indices of the bins to which each value in input array belongs. + + For full documentation refer to :obj:`numpy.digitize`. + + Parameters + ---------- + a : {dpnp.ndarray, usm_ndarray} + Input array to be binned. + bins : {dpnp.ndarray, usm_ndarray} + Array of bins. It has to be 1-dimensional and monotonic + increasing or decreasing. + right : {bool}, optional + Indicates whether the intervals include the right or the left bin edge. + Default: ``False``. + + Returns + ------- + indices : dpnp.ndarray + Array of indices with the same shape as `x`. + + Note + ---- + dpnp.digitize does not raise an exception when the input array is + not monotonic. + + See Also + -------- + :obj:`dpnp.bincount` : Count number of occurrences of each value in array + of non-negative integers. + :obj:`dpnp.histogram` : Compute the histogram of a data set. + :obj:`dpnp.unique` : Find the unique elements of an array. + :obj:`dpnp.searchsorted` : Find indices where elements should be inserted + to maintain order. + + Examples + -------- + >>> import dpnp as np + >>> x = np.array([0.2, 6.4, 3.0, 1.6]) + >>> bins = np.array([0.0, 1.0, 2.5, 4.0, 10.0]) + >>> inds = np.digitize(x, bins) + >>> inds + array([1, 4, 3, 2]) + >>> for n in range(x.size): + ... print(bins[inds[n]-1], "<=", x[n], "<", bins[inds[n]]) + ... + 0. <= 0.2 < 1. + 4. <= 6.4 < 10. + 2.5 <= 3. < 4. + 1. <= 1.6 < 2.5 + + >>> x = np.array([1.2, 10.0, 12.4, 15.5, 20.]) + >>> bins = np.array([0, 5, 10, 15, 20]) + >>> np.digitize(x,bins,right=True) + array([1, 2, 3, 4, 4]) + >>> np.digitize(x,bins,right=False) + array([1, 3, 3, 4, 5]) + + """ + + dpnp.check_supported_arrays_type(x, bins) + + if dpnp.issubdtype(x.dtype, dpnp.complexfloating): + raise TypeError("x may not be complex") + + if bins.ndim > 1: + raise ValueError("object too deep for desired array") + if bins.ndim < 1: + raise ValueError("object of too small depth for desired array") + + # This is backwards because the arguments below are swapped + side = "left" if right else "right" + + # Check if bins are monotonically increasing. + # If all bins are NaN, the array is considered to be decreasing. + bins_increasing = bins[0] <= bins[-1] or ( + not dpnp.isnan(bins[0]) and dpnp.isnan(bins[-1]) + ) + + if bins_increasing: + # Use dpnp.searchsorted directly if bins are increasing + return dpnp.searchsorted(bins, x, side=side) + + # Reverse bins and adjust indices if bins are decreasing + return bins.size - dpnp.searchsorted(bins[::-1], x, side=side) + + def histogram(a, bins=10, range=None, density=None, weights=None): """ Compute the histogram of a data set. @@ -336,7 +424,6 @@ def histogram(a, bins=10, range=None, density=None, weights=None): if density: db = dpnp.diff(bin_edges).astype(dpnp.default_float_type()) - # pylint: disable=possibly-used-before-assignment return n / db / n.sum(), bin_edges return n, bin_edges From 39d00eb8a3fe16cbd8e7569d537e6403da962db3 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 20:43:12 +0200 Subject: [PATCH 02/12] Update cupy tests for digitize func --- .../cupy/statistics_tests/test_histogram.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/third_party/cupy/statistics_tests/test_histogram.py b/tests/third_party/cupy/statistics_tests/test_histogram.py index bb1dd8e07ce5..6e2d20dc4105 100644 --- a/tests/third_party/cupy/statistics_tests/test_histogram.py +++ b/tests/third_party/cupy/statistics_tests/test_histogram.py @@ -345,7 +345,6 @@ def test_bincount_too_small_minlength(self, dtype): # in this comment to restore the support. -@pytest.mark.skip("digitize() is not implemented yet") @testing.parameterize( *testing.product( { @@ -367,6 +366,8 @@ class TestDigitize: @testing.for_all_dtypes(no_bool=True, no_complex=True) @testing.numpy_cupy_array_equal() def test_digitize(self, xp, dtype): + if self.shape == () and not self.increasing: + pytest.skip("dpctl issue #1689") x = testing.shaped_arange(self.shape, xp, dtype) bins = self.bins if not self.increasing: @@ -376,7 +377,6 @@ def test_digitize(self, xp, dtype): return (y,) -@pytest.mark.skip("digitize() is not implemented yet") @testing.parameterize({"right": True}, {"right": False}) class TestDigitizeNanInf(unittest.TestCase): @testing.numpy_cupy_array_equal() @@ -447,18 +447,17 @@ def test_searchsorted_minf(self, xp): return (y,) -@pytest.mark.skip("digitize() is not implemented yet") class TestDigitizeInvalid(unittest.TestCase): def test_digitize_complex(self): for xp in (numpy, cupy): - x = testing.shaped_arange((14,), xp, complex) - bins = xp.array([1.0, 3.0, 5.0, 8.0, 12.0], complex) + x = testing.shaped_arange((14,), xp, xp.complex64) + bins = xp.array([1.0, 3.0, 5.0, 8.0, 12.0], xp.complex64) with pytest.raises(TypeError): xp.digitize(x, bins) def test_digitize_nd_bins(self): for xp in (numpy, cupy): - x = testing.shaped_arange((14,), xp, xp.float64) + x = testing.shaped_arange((14,), xp, cupy.default_float_type()) bins = xp.array([[1], [2]]) with pytest.raises(ValueError): xp.digitize(x, bins) From b20f8f27a47674b9f3e2f54a80b7f677f9f358be Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 20:43:33 +0200 Subject: [PATCH 03/12] Update skipped_tests files --- tests/skipped_tests.tbl | 55 ------------------------------------- tests/skipped_tests_gpu.tbl | 55 ------------------------------------- 2 files changed, 110 deletions(-) diff --git a/tests/skipped_tests.tbl b/tests/skipped_tests.tbl index f05a82c20492..74ede86e40d8 100644 --- a/tests/skipped_tests.tbl +++ b/tests/skipped_tests.tbl @@ -646,61 +646,6 @@ tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_ tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_rowvar tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_y -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeInvalid::test_digitize_complex -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeInvalid::test_digitize_nd_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_all_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins_decreasing -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins_decreasing_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_searchsorted_inf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_searchsorted_minf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_all_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins_decreasing -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins_decreasing_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_searchsorted_inf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_searchsorted_minf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_0_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_10_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_11_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_12_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_13_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_14_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_15_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_16_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_17_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_18_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_19_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_1_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_20_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_21_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_22_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_23_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_24_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_25_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_26_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_27_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_28_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_29_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_2_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_30_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_31_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_32_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_33_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_34_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_35_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_3_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_4_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_5_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_6_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_7_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_8_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_9_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=False, shape=()}::test_digitize - 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] diff --git a/tests/skipped_tests_gpu.tbl b/tests/skipped_tests_gpu.tbl index 18c367822010..1c61f8e076fc 100644 --- a/tests/skipped_tests_gpu.tbl +++ b/tests/skipped_tests_gpu.tbl @@ -669,61 +669,6 @@ tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_ tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_rowvar tests/third_party/cupy/statistics_tests/test_correlation.py::TestCorrcoef::test_corrcoef_y -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeInvalid::test_digitize_complex -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeInvalid::test_digitize_nd_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_all_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins_decreasing -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins_decreasing_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_digitize_nan_bins_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_searchsorted_inf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_0_{right=True}::test_searchsorted_minf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_all_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins_decreasing -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins_decreasing_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_digitize_nan_bins_repeated -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_searchsorted_inf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitizeNanInf_param_1_{right=False}::test_searchsorted_minf -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_0_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_10_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_11_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_12_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_13_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_14_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_15_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_16_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_17_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=True, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_18_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_19_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_1_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_20_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_21_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_22_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_23_{bins=[-1.0, 1.0, 2.5, 4.0, 20.0], increasing=False, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_24_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_25_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_26_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_27_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_28_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_29_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=True, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_2_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_30_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_31_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_32_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_33_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_34_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_35_{bins=[0.0, 1.0, 1.0, 4.0, 4.0, 10.0], increasing=False, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_3_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=False, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_4_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=False, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_5_{bins=[1.5, 2.5, 4.0, 6.0], increasing=True, right=False, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_6_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=True, shape=()}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_7_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=True, shape=(10,)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_8_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=True, shape=(6, 3, 3)}::test_digitize -tests/third_party/cupy/statistics_tests/test_histogram.py::TestDigitize_param_9_{bins=[1.5, 2.5, 4.0, 6.0], increasing=False, right=False, shape=()}::test_digitize - 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] From 5c78198099b63fd4a62016ab63ec335f8a004492 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 20:58:35 +0200 Subject: [PATCH 04/12] Add tests in test_sycl_queue and test_usm_type --- tests/test_sycl_queue.py | 1 + tests/test_usm_type.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/test_sycl_queue.py b/tests/test_sycl_queue.py index 9286131a65b5..fae4dd52221c 100644 --- a/tests/test_sycl_queue.py +++ b/tests/test_sycl_queue.py @@ -606,6 +606,7 @@ def test_reduce_hypot(device): pytest.param("arctan2", [[-1, +1, +1, -1]], [[-1, -1, +1, +1]]), pytest.param("copysign", [0.0, 1.0, 2.0], [-1.0, 0.0, 1.0]), pytest.param("cross", [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]), + pytest.param("digitize", [0.2, 6.4, 3.0], [0.0, 1.0, 2.5, 4.0]), pytest.param( "divide", [0.0, 1.0, 2.0, 3.0, 4.0], [4.0, 4.0, 4.0, 4.0, 4.0] ), diff --git a/tests/test_usm_type.py b/tests/test_usm_type.py index a2b38b82e8d0..eab59cf001b6 100644 --- a/tests/test_usm_type.py +++ b/tests/test_usm_type.py @@ -614,6 +614,7 @@ def test_1in_1out(func, data, usm_type): pytest.param("arctan2", [[-1, +1, +1, -1]], [[-1, -1, +1, +1]]), pytest.param("copysign", [0.0, 1.0, 2.0], [-1.0, 0.0, 1.0]), pytest.param("cross", [1.0, 2.0, 3.0], [4.0, 5.0, 6.0]), + pytest.param("digitize", [0.2, 6.4, 3.0], [0.0, 1.0, 2.5, 4.0]), # dpnp.dot has 3 different implementations based on input arrays dtype # checking all of them pytest.param("dot", [3.0, 4.0, 5.0], [1.0, 2.0, 3.0]), From 3d75d26179b44bf85618d21874733fc9ae62b13c Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 21:04:00 +0200 Subject: [PATCH 05/12] Return pylint disable --- dpnp/dpnp_iface_histograms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dpnp/dpnp_iface_histograms.py b/dpnp/dpnp_iface_histograms.py index 6745336f4694..89b4106cc5ea 100644 --- a/dpnp/dpnp_iface_histograms.py +++ b/dpnp/dpnp_iface_histograms.py @@ -175,6 +175,7 @@ def _get_bin_edges(a, bins, range, usm_type): # numpy's gh-10322 means that type resolution rules are dependent on # array shapes. To avoid this causing problems, we pick a type now and # stick with it throughout. + # pylint: disable=possibly-used-before-assignment bin_type = dpnp.result_type(first_edge, last_edge, a) if dpnp.issubdtype(bin_type, dpnp.integer): bin_type = dpnp.result_type( @@ -423,6 +424,7 @@ def histogram(a, bins=10, range=None, density=None, weights=None): n = dpnp.diff(cum_n) if density: + # pylint: disable=possibly-used-before-assignment db = dpnp.diff(bin_edges).astype(dpnp.default_float_type()) return n / db / n.sum(), bin_edges From 333d28d91417ecb9d62d6e56bbc59c2e72dfbb58 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 22:45:15 +0200 Subject: [PATCH 06/12] Handle empty bins --- dpnp/dpnp_iface_histograms.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dpnp/dpnp_iface_histograms.py b/dpnp/dpnp_iface_histograms.py index 89b4106cc5ea..424ea9bb2bc0 100644 --- a/dpnp/dpnp_iface_histograms.py +++ b/dpnp/dpnp_iface_histograms.py @@ -284,10 +284,14 @@ def digitize(x, bins, right=False): side = "left" if right else "right" # Check if bins are monotonically increasing. + # If bins is empty, the array is considered to be increasing. # If all bins are NaN, the array is considered to be decreasing. - bins_increasing = bins[0] <= bins[-1] or ( - not dpnp.isnan(bins[0]) and dpnp.isnan(bins[-1]) - ) + if bins.size == 0: + bins_increasing = True + else: + bins_increasing = bins[0] <= bins[-1] or ( + not dpnp.isnan(bins[0]) and dpnp.isnan(bins[-1]) + ) if bins_increasing: # Use dpnp.searchsorted directly if bins are increasing From 5747be0a4821f7702898060d0fa9d2f8f97ab245 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 22:45:56 +0200 Subject: [PATCH 07/12] Small update cupy tests --- tests/third_party/cupy/statistics_tests/test_histogram.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/third_party/cupy/statistics_tests/test_histogram.py b/tests/third_party/cupy/statistics_tests/test_histogram.py index 6e2d20dc4105..18fd4a0aa555 100644 --- a/tests/third_party/cupy/statistics_tests/test_histogram.py +++ b/tests/third_party/cupy/statistics_tests/test_histogram.py @@ -432,7 +432,7 @@ def test_digitize_all_nan_bins(self, xp): @testing.numpy_cupy_array_equal() def test_searchsorted_inf(self, xp): - x = testing.shaped_arange((14,), xp, xp.float64) + x = testing.shaped_arange((14,), xp, cupy.default_float_type()) x[5] = float("inf") bins = xp.array([0, 1, 2, 4, 10]) y = xp.digitize(x, bins, right=self.right) @@ -440,7 +440,7 @@ def test_searchsorted_inf(self, xp): @testing.numpy_cupy_array_equal() def test_searchsorted_minf(self, xp): - x = testing.shaped_arange((14,), xp, xp.float64) + x = testing.shaped_arange((14,), xp, cupy.default_float_type()) x[5] = float("-inf") bins = xp.array([0, 1, 2, 4, 10]) y = xp.digitize(x, bins, right=self.right) From ae38d74452960895b739a64b9aa3ca219c412417 Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 22:48:16 +0200 Subject: [PATCH 08/12] Add dpnp tests for dpnp.digitize --- tests/test_statistics.py | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/test_statistics.py b/tests/test_statistics.py index ad617752d049..fa964ea6cc60 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -252,6 +252,77 @@ def test_avg_error(self): dpnp.average(a, axis=0, weights=w) +class TestDigitize: + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True) + ) + @pytest.mark.parametrize("right", [True, False]) + @pytest.mark.parametrize( + "x, bins", + [ + # Negative values + ( + numpy.array([-5, -3, -1, 0, 1, 3, 5]), + numpy.array([-4, -2, 0, 2, 4]), + ), + # Non-uniform bins + ( + numpy.array([1, 2, 3, 4, 5, 6, 7, 8, 9]), + numpy.array([1, 4, 6, 7]), + ), + # Infinity values + ( + numpy.array([-numpy.inf, -1, 0, 1, numpy.inf]), + numpy.array([-2, -1, 0, 1, 2]), + ), + # Repeated elements + (numpy.array([1, 2, 2, 3, 3, 3, 4, 5]), numpy.array([1, 2, 3, 4])), + ], + ) + def test_digitize(self, x, bins, dtype, right): + x = x.astype(dtype) + bins = bins.astype(dtype) + x_dp = dpnp.array(x) + bins_dp = dpnp.array(bins) + + result = dpnp.digitize(x_dp, bins_dp, right=right) + expected = numpy.digitize(x, bins, right=right) + assert_dtype_allclose(result, expected) + + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True) + ) + @pytest.mark.parametrize( + "x, bins", + [ + # Empty array + (numpy.array([]), numpy.array([1, 2, 3])), + # Empty bins + (numpy.array([1, 2, 3]), numpy.array([])), + ], + ) + def test_digitize_empty(self, x, bins, dtype): + x = x.astype(dtype) + bins = bins.astype(dtype) + x_dp = dpnp.array(x) + bins_dp = dpnp.array(bins) + + result = dpnp.digitize(x_dp, bins_dp) + expected = numpy.digitize(x, bins) + assert_dtype_allclose(result, expected) + + def test_digitize_error(self): + x_dp = dpnp.array([1, 2, 3], dtype="float32") + bins_dp = dpnp.array([1, 2, 3], dtype="float32") + + # unsupported type + x_np = dpnp.asnumpy(x_dp) + bins_np = dpnp.asnumpy(bins_dp) + with pytest.raises(TypeError): + dpnp.digitize(x_np, bins_dp) + dpnp.digitize(x_dp, bins_np) + + class TestMean: @pytest.mark.parametrize("dtype", get_all_dtypes()) @pytest.mark.parametrize("axis", [None, 0, 1, (0, 1)]) From 5547308a9db5d36d5524c88ad33fd3770f18b51c Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 22:57:09 +0200 Subject: [PATCH 09/12] Increase code coverage --- tests/test_statistics.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_statistics.py b/tests/test_statistics.py index fa964ea6cc60..3c869578c7e9 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -322,6 +322,11 @@ def test_digitize_error(self): dpnp.digitize(x_np, bins_dp) dpnp.digitize(x_dp, bins_np) + # bins ndim < 1 + bins_scalar = dpnp.array(1) + with pytest.raises(ValueError): + dpnp.digitize(x_dp, bins_scalar) + class TestMean: @pytest.mark.parametrize("dtype", get_all_dtypes()) From b6312b6a040174f6a6a17a72d4e779d259de44cb Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 22:58:55 +0200 Subject: [PATCH 10/12] Apply remarks --- dpnp/dpnp_iface_histograms.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dpnp/dpnp_iface_histograms.py b/dpnp/dpnp_iface_histograms.py index 424ea9bb2bc0..1a1b4daf740d 100644 --- a/dpnp/dpnp_iface_histograms.py +++ b/dpnp/dpnp_iface_histograms.py @@ -222,7 +222,7 @@ def digitize(x, bins, right=False): bins : {dpnp.ndarray, usm_ndarray} Array of bins. It has to be 1-dimensional and monotonic increasing or decreasing. - right : {bool}, optional + right : bool, optional Indicates whether the intervals include the right or the left bin edge. Default: ``False``. @@ -231,9 +231,9 @@ def digitize(x, bins, right=False): indices : dpnp.ndarray Array of indices with the same shape as `x`. - Note - ---- - dpnp.digitize does not raise an exception when the input array is + Notes + ----- + This will not raise an exception when the input array is not monotonic. See Also @@ -263,9 +263,9 @@ def digitize(x, bins, right=False): >>> x = np.array([1.2, 10.0, 12.4, 15.5, 20.]) >>> bins = np.array([0, 5, 10, 15, 20]) - >>> np.digitize(x,bins,right=True) + >>> np.digitize(x, bins, right=True) array([1, 2, 3, 4, 4]) - >>> np.digitize(x,bins,right=False) + >>> np.digitize(x, bins, right=False) array([1, 3, 3, 4, 5]) """ From 1d1e23a09d83231a6de57806016f3a9411ff275c Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Wed, 22 May 2024 22:59:57 +0200 Subject: [PATCH 11/12] Move tests from test_statistic to test_histogram --- tests/test_histogram.py | 76 ++++++++++++++++++++++++++++++++++++++++ tests/test_statistics.py | 76 ---------------------------------------- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/tests/test_histogram.py b/tests/test_histogram.py index a70f2db80443..4d0f4e1dafc4 100644 --- a/tests/test_histogram.py +++ b/tests/test_histogram.py @@ -20,6 +20,82 @@ ) +class TestDigitize: + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True) + ) + @pytest.mark.parametrize("right", [True, False]) + @pytest.mark.parametrize( + "x, bins", + [ + # Negative values + ( + numpy.array([-5, -3, -1, 0, 1, 3, 5]), + numpy.array([-4, -2, 0, 2, 4]), + ), + # Non-uniform bins + ( + numpy.array([1, 2, 3, 4, 5, 6, 7, 8, 9]), + numpy.array([1, 4, 6, 7]), + ), + # Infinity values + ( + numpy.array([-numpy.inf, -1, 0, 1, numpy.inf]), + numpy.array([-2, -1, 0, 1, 2]), + ), + # Repeated elements + (numpy.array([1, 2, 2, 3, 3, 3, 4, 5]), numpy.array([1, 2, 3, 4])), + ], + ) + def test_digitize(self, x, bins, dtype, right): + x = x.astype(dtype) + bins = bins.astype(dtype) + x_dp = dpnp.array(x) + bins_dp = dpnp.array(bins) + + result = dpnp.digitize(x_dp, bins_dp, right=right) + expected = numpy.digitize(x, bins, right=right) + assert_dtype_allclose(result, expected) + + @pytest.mark.parametrize( + "dtype", get_all_dtypes(no_bool=True, no_complex=True) + ) + @pytest.mark.parametrize( + "x, bins", + [ + # Empty array + (numpy.array([]), numpy.array([1, 2, 3])), + # Empty bins + (numpy.array([1, 2, 3]), numpy.array([])), + ], + ) + def test_digitize_empty(self, x, bins, dtype): + x = x.astype(dtype) + bins = bins.astype(dtype) + x_dp = dpnp.array(x) + bins_dp = dpnp.array(bins) + + result = dpnp.digitize(x_dp, bins_dp) + expected = numpy.digitize(x, bins) + assert_dtype_allclose(result, expected) + + def test_digitize_error(self): + x_dp = dpnp.array([1, 2, 3], dtype="float32") + bins_dp = dpnp.array([1, 2, 3], dtype="float32") + + # unsupported type + x_np = dpnp.asnumpy(x_dp) + bins_np = dpnp.asnumpy(bins_dp) + with pytest.raises(TypeError): + dpnp.digitize(x_np, bins_dp) + dpnp.digitize(x_dp, bins_np) + + # bins ndim < 1 + bins_scalar = dpnp.array(1) + with pytest.raises(ValueError): + dpnp.digitize(x_dp, bins_scalar) + + class TestHistogram: @pytest.mark.usefixtures("suppress_complex_warning") @pytest.mark.parametrize( diff --git a/tests/test_statistics.py b/tests/test_statistics.py index 3c869578c7e9..ad617752d049 100644 --- a/tests/test_statistics.py +++ b/tests/test_statistics.py @@ -252,82 +252,6 @@ def test_avg_error(self): dpnp.average(a, axis=0, weights=w) -class TestDigitize: - @pytest.mark.parametrize( - "dtype", get_all_dtypes(no_bool=True, no_complex=True) - ) - @pytest.mark.parametrize("right", [True, False]) - @pytest.mark.parametrize( - "x, bins", - [ - # Negative values - ( - numpy.array([-5, -3, -1, 0, 1, 3, 5]), - numpy.array([-4, -2, 0, 2, 4]), - ), - # Non-uniform bins - ( - numpy.array([1, 2, 3, 4, 5, 6, 7, 8, 9]), - numpy.array([1, 4, 6, 7]), - ), - # Infinity values - ( - numpy.array([-numpy.inf, -1, 0, 1, numpy.inf]), - numpy.array([-2, -1, 0, 1, 2]), - ), - # Repeated elements - (numpy.array([1, 2, 2, 3, 3, 3, 4, 5]), numpy.array([1, 2, 3, 4])), - ], - ) - def test_digitize(self, x, bins, dtype, right): - x = x.astype(dtype) - bins = bins.astype(dtype) - x_dp = dpnp.array(x) - bins_dp = dpnp.array(bins) - - result = dpnp.digitize(x_dp, bins_dp, right=right) - expected = numpy.digitize(x, bins, right=right) - assert_dtype_allclose(result, expected) - - @pytest.mark.parametrize( - "dtype", get_all_dtypes(no_bool=True, no_complex=True) - ) - @pytest.mark.parametrize( - "x, bins", - [ - # Empty array - (numpy.array([]), numpy.array([1, 2, 3])), - # Empty bins - (numpy.array([1, 2, 3]), numpy.array([])), - ], - ) - def test_digitize_empty(self, x, bins, dtype): - x = x.astype(dtype) - bins = bins.astype(dtype) - x_dp = dpnp.array(x) - bins_dp = dpnp.array(bins) - - result = dpnp.digitize(x_dp, bins_dp) - expected = numpy.digitize(x, bins) - assert_dtype_allclose(result, expected) - - def test_digitize_error(self): - x_dp = dpnp.array([1, 2, 3], dtype="float32") - bins_dp = dpnp.array([1, 2, 3], dtype="float32") - - # unsupported type - x_np = dpnp.asnumpy(x_dp) - bins_np = dpnp.asnumpy(bins_dp) - with pytest.raises(TypeError): - dpnp.digitize(x_np, bins_dp) - dpnp.digitize(x_dp, bins_np) - - # bins ndim < 1 - bins_scalar = dpnp.array(1) - with pytest.raises(ValueError): - dpnp.digitize(x_dp, bins_scalar) - - class TestMean: @pytest.mark.parametrize("dtype", get_all_dtypes()) @pytest.mark.parametrize("axis", [None, 0, 1, (0, 1)]) From adf52a51b9636a8df56738e16b7f4f75e0a337ce Mon Sep 17 00:00:00 2001 From: Vladislav Perevezentsev Date: Thu, 23 May 2024 12:27:31 +0200 Subject: [PATCH 12/12] Add test with different dtypes --- tests/test_histogram.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_histogram.py b/tests/test_histogram.py index 4d0f4e1dafc4..7601d67c54a9 100644 --- a/tests/test_histogram.py +++ b/tests/test_histogram.py @@ -57,6 +57,23 @@ def test_digitize(self, x, bins, dtype, right): expected = numpy.digitize(x, bins, right=right) assert_dtype_allclose(result, expected) + @pytest.mark.parametrize( + "dtype_x", get_all_dtypes(no_bool=True, no_complex=True) + ) + @pytest.mark.parametrize( + "dtype_bins", get_all_dtypes(no_bool=True, no_complex=True) + ) + @pytest.mark.parametrize("right", [True, False]) + def test_digitize_diff_types(self, dtype_x, dtype_bins, right): + x = numpy.array([1, 2, 3, 4, 5], dtype=dtype_x) + bins = numpy.array([1, 3, 5], dtype=dtype_bins) + x_dp = dpnp.array(x) + bins_dp = dpnp.array(bins) + + result = dpnp.digitize(x_dp, bins_dp, right=right) + expected = numpy.digitize(x, bins, right=right) + assert_dtype_allclose(result, expected) + @pytest.mark.parametrize( "dtype", get_all_dtypes(no_bool=True, no_complex=True) )