Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: safer bincount casting (backport to 2.2.x) #28420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jakirkham
Copy link
Contributor

Backport of PR ( #28355 ) to 2.2.x

cc @tylerjereddy @seberg @charris

* BUG: safer bincount casting

* Fixes numpy#28354

* Force usage of `npy_intp` type in `np.bincount()` and avoid
unsafe casting errors with i.e., `npy_uint64`. This is similar
to our behavior with indexing.

* MAINT, BUG: PR 28355 revisions

* `arr_bincount()` now only uses unsafe casting for integer
input types, and the number of casting operations has
been reduced for the code path used in above PR.

* a test for non-crashing behavior with non-contiguous
`bincount()` input has been added.

* MAINT, BUG: PR 28355 revisions

* Based on reviewer feedback, narrow the scope of the `flags`
variable in `arr_bincount()`.

* Based on reviewer feedback, add an array-like test for the `uint64`
casting issue, which indeed fails before and passes after adding
a similar shim to the array-like code path in `arr_bincount()`.

* Based on reviewer feedback, switch the patching from `PyArray_Size`
to `PyArray_Check` in a few places.

* Update numpy/_core/src/multiarray/compiled_base.c

---------

Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@jorenham jorenham added the 08 - Backport Used to tag backport PRs label Mar 3, 2025
@charris charris added this to the 2.2.4 release milestone Mar 3, 2025
@charris charris merged commit a9d3796 into numpy:maintenance/2.2.x Mar 3, 2025
70 checks passed
@charris
Copy link
Member

charris commented Mar 3, 2025

Thanks @jakirkham .

@jakirkham jakirkham deleted the backport_treddy_issue_28354_2.2.x branch March 3, 2025 21:49
@jakirkham
Copy link
Contributor Author

Thanks Chuck! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 08 - Backport Used to tag backport PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.