Fix ValueError in dpnp.bincount for empty input arrays - #3018
Open
antonwolfy wants to merge 2 commits into
Open
Conversation
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3018/index.html |
Contributor
|
Array API standard conformance tests for dpnp=0.21.0dev3=py314h509198e_40 ran successfully. |
antonwolfy
force-pushed
the
fix/bincount-empty-input
branch
from
August 11, 2026 17:35
73993ba to
8e90fd3
Compare
dpnp.bincount raised a ValueError on an empty input array because the Python layer reduces over the array with dpnp.max/dpnp.min to determine binning edges, and those reductions have no identity for zero-size input. Short-circuit empty input and return an intp array of zeros of length minlength, matching NumPy behavior (which returns intp even when weights are provided).
antonwolfy
force-pushed
the
fix/bincount-empty-input
branch
from
August 11, 2026 17:37
8e90fd3 to
e5966bc
Compare
for_dtypes already skips dtypes the default device cannot represent natively (float64/complex128 without fp64 support, float16 without fp16 support), but for_dtypes_combination did not, so combination tests could attempt to allocate an unsupported-dtype array and fail with a device ValueError instead of exercising the intended code path. This surfaced in the new bincount empty-with-weights test. Factor the per-dtype check into a shared helper and apply it in both decorators so combination tests skip such dtypes consistently.
Collaborator
antonwolfy
marked this pull request as ready for review
August 11, 2026 21:48
antonwolfy
requested review from
ndgrigorian and
vlad-perevezentsev
as code owners
August 11, 2026 21:48
ndgrigorian
approved these changes
Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
dpnp.bincountraised aValueErrorwhen given an empty input array, while NumPy returns an empty (or zero-filled) array. This PR short-circuits the empty-input case sodpnp.bincountmatches NumPy.The Python layer determines the binning edges by reducing over the input with
dpnp.max/dpnp.min. Those reductions have no identity for zero-size input, so an empty array failed before ever reaching the kernel:The C++ kernel already guards
sample.get_size() == 0, but that code path is unreachable because themax/minreduction runs first.The fix assumes to return early for empty input with an
intparray of zeros of lengthminlength, before any reduction is performed.