-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: safer bincount casting #28355
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
BUG: safer bincount casting #28355
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,7 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *const *args, | |
npy_intp *numbers, *ians, len, mx, mn, ans_size; | ||
npy_intp minlength = 0; | ||
npy_intp i; | ||
int flags; | ||
double *weights , *dans; | ||
|
||
NPY_PREPARE_ARGPARSER; | ||
|
@@ -177,7 +178,13 @@ arr_bincount(PyObject *NPY_UNUSED(self), PyObject *const *args, | |
} | ||
|
||
if (lst == NULL) { | ||
lst = (PyArrayObject *)PyArray_ContiguousFromAny(list, NPY_INTP, 1, 1); | ||
flags = NPY_ARRAY_WRITEABLE | NPY_ARRAY_ALIGNED | NPY_ARRAY_C_CONTIGUOUS; | ||
if (PyArray_Size((PyObject *)list) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The deprecation makes this pretty messy, almost wondering if we should just finalize it... In either case, I think the I am not quite sure that not setting force-cast in the non-array case won't finalize the deprecation (in small parts).
|
||
PyArray_ISINTEGER((PyArrayObject *)list)) { | ||
flags = flags | NPY_ARRAY_FORCECAST; | ||
} | ||
seberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyArray_Descr* local_dtype = PyArray_DescrFromType(NPY_INTP); | ||
lst = (PyArrayObject *)PyArray_FromAny(list, local_dtype, 1, 1, flags, NULL); | ||
if (lst == NULL) { | ||
goto fail; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would move this down into the if, but OK.
I think we can put this in, if we change things to a
PyArray_Check
below, unless I am missing something. It seems fine, even if it might not be 100% for array-likes.I would lean towards not backporting. It has been around forever, and the reason it came up was just cupy testing against NumPy as far as I am aware.