Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 <[email protected]>
@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