Skip to content

Commit 7c47d09

Browse files
Apply review comments IntelPython#2
1 parent cfe043e commit 7c47d09

File tree

4 files changed

+49
-51
lines changed

4 files changed

+49
-51
lines changed

dpnp/backend/extensions/statistics/bincount.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ struct BincountF
114114
const auto local_mem_size =
115115
get_local_mem_size_in_items<T>(exec_q);
116116
if (local_mem_size >= needed_bins_count) {
117-
uint32_t local_hist_count = get_local_hist_copies_count(
118-
local_mem_size, local_size, needed_bins_count);
117+
const uint32_t local_hist_count =
118+
get_local_hist_copies_count(local_mem_size, local_size,
119+
needed_bins_count);
119120

120121
auto hist = HistWithLocalCopies<HistType>(
121122
out, needed_bins_count, local_hist_count, cgh);
@@ -155,13 +156,13 @@ Bincount::Bincount() : dispatch_table("sample", "histogram")
155156
dispatch_table.populate_dispatch_table<SupportedTypes, BincountF>();
156157
}
157158

158-
std::tuple<sycl::event, sycl::event>
159-
Bincount::call(const dpctl::tensor::usm_ndarray &sample,
160-
int64_t min,
161-
int64_t max,
162-
std::optional<const dpctl::tensor::usm_ndarray> &weights,
163-
dpctl::tensor::usm_ndarray &histogram,
164-
const std::vector<sycl::event> &depends)
159+
std::tuple<sycl::event, sycl::event> Bincount::call(
160+
const dpctl::tensor::usm_ndarray &sample,
161+
const int64_t min,
162+
const int64_t max,
163+
const std::optional<const dpctl::tensor::usm_ndarray> &weights,
164+
dpctl::tensor::usm_ndarray &histogram,
165+
const std::vector<sycl::event> &depends)
165166
{
166167
validate(sample, std::optional<const dpctl::tensor::usm_ndarray>(), weights,
167168
histogram);

dpnp/backend/extensions/statistics/bincount.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ struct Bincount
4040
{
4141
using FnT = sycl::event (*)(sycl::queue &,
4242
const void *,
43-
int64_t,
44-
int64_t,
43+
const int64_t,
44+
const int64_t,
4545
const void *,
4646
void *,
4747
const size_t,
@@ -54,9 +54,9 @@ struct Bincount
5454

5555
std::tuple<sycl::event, sycl::event>
5656
call(const dpctl::tensor::usm_ndarray &input,
57-
int64_t min,
58-
int64_t max,
59-
std::optional<const dpctl::tensor::usm_ndarray> &weights,
57+
const int64_t min,
58+
const int64_t max,
59+
const std::optional<const dpctl::tensor::usm_ndarray> &weights,
6060
dpctl::tensor::usm_ndarray &output,
6161
const std::vector<sycl::event> &depends);
6262
};

tests/test_histogram.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,37 @@ def test_different_bins_amount(self, bins_count):
576576
expected_hist = numpy.bincount(v)
577577
result_hist = dpnp.bincount(iv)
578578
assert_array_equal(result_hist, expected_hist)
579+
580+
@pytest.mark.parametrize(
581+
"array",
582+
[[1, 2, 3], [1, 2, 2, 1, 2, 4], [2, 2, 2, 2]],
583+
ids=["[1, 2, 3]", "[1, 2, 2, 1, 2, 4]", "[2, 2, 2, 2]"],
584+
)
585+
@pytest.mark.parametrize(
586+
"minlength", [0, 1, 3, 5], ids=["0", "1", "3", "5"]
587+
)
588+
def test_bincount_minlength(self, array, minlength):
589+
np_a = numpy.array(array)
590+
dpnp_a = dpnp.array(array)
591+
592+
expected = numpy.bincount(np_a, minlength=minlength)
593+
result = dpnp.bincount(dpnp_a, minlength=minlength)
594+
assert_allclose(expected, result)
595+
596+
@pytest.mark.parametrize(
597+
"array", [[1, 2, 2, 1, 2, 4]], ids=["[1, 2, 2, 1, 2, 4]"]
598+
)
599+
@pytest.mark.parametrize(
600+
"weights",
601+
[None, [0.3, 0.5, 0.2, 0.7, 1.0, -0.6], [2, 2, 2, 2, 2, 2]],
602+
ids=["None", "[0.3, 0.5, 0.2, 0.7, 1., -0.6]", "[2, 2, 2, 2, 2, 2]"],
603+
)
604+
def test_bincount_weights(self, array, weights):
605+
np_a = numpy.array(array)
606+
np_weights = numpy.array(weights) if weights is not None else weights
607+
dpnp_a = dpnp.array(array)
608+
dpnp_weights = dpnp.array(weights) if weights is not None else weights
609+
610+
expected = numpy.bincount(np_a, weights=np_weights)
611+
result = dpnp.bincount(dpnp_a, weights=dpnp_weights)
612+
assert_allclose(expected, result)

tests/test_statistics.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -573,43 +573,6 @@ def test_std_error(self):
573573
dpnp.std(ia, ddof="1")
574574

575575

576-
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
577-
class TestBincount:
578-
@pytest.mark.parametrize(
579-
"array",
580-
[[1, 2, 3], [1, 2, 2, 1, 2, 4], [2, 2, 2, 2]],
581-
ids=["[1, 2, 3]", "[1, 2, 2, 1, 2, 4]", "[2, 2, 2, 2]"],
582-
)
583-
@pytest.mark.parametrize(
584-
"minlength", [0, 1, 3, 5], ids=["0", "1", "3", "5"]
585-
)
586-
def test_bincount_minlength(self, array, minlength):
587-
np_a = numpy.array(array)
588-
dpnp_a = dpnp.array(array)
589-
590-
expected = numpy.bincount(np_a, minlength=minlength)
591-
result = dpnp.bincount(dpnp_a, minlength=minlength)
592-
assert_allclose(expected, result)
593-
594-
@pytest.mark.parametrize(
595-
"array", [[1, 2, 2, 1, 2, 4]], ids=["[1, 2, 2, 1, 2, 4]"]
596-
)
597-
@pytest.mark.parametrize(
598-
"weights",
599-
[None, [0.3, 0.5, 0.2, 0.7, 1.0, -0.6], [2, 2, 2, 2, 2, 2]],
600-
ids=["None", "[0.3, 0.5, 0.2, 0.7, 1., -0.6]", "[2, 2, 2, 2, 2, 2]"],
601-
)
602-
def test_bincount_weights(self, array, weights):
603-
np_a = numpy.array(array)
604-
np_weights = numpy.array(weights) if weights is not None else weights
605-
dpnp_a = dpnp.array(array)
606-
dpnp_weights = dpnp.array(weights) if weights is not None else weights
607-
608-
expected = numpy.bincount(np_a, weights=np_weights)
609-
result = dpnp.bincount(dpnp_a, weights=dpnp_weights)
610-
assert_allclose(expected, result)
611-
612-
613576
@pytest.mark.parametrize(
614577
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
615578
)

0 commit comments

Comments
 (0)