-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: Add support for complex weights in np.bincount
#23641
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
base: main
Are you sure you want to change the base?
ENH: Add support for complex weights in np.bincount
#23641
Conversation
np.bincount
np.bincount
66ef30c
to
8cdd947
Compare
8cdd947
to
66ae571
Compare
I have ran For contenxt I am running Ubuntu on WSL. Here is a link to one of the lines where it looks like there was on overflow.https://github.com/numpy/numpy/actions/runs/4834881472/jobs/8616610313?pr=23641#step:12:30887 |
ans = (PyArrayObject *)PyArray_ZEROS(1, &ans_size, NPY_DOUBLE, 0); | ||
if (ans == NULL) { | ||
if (PyArray_ISINTEGER(wts)) { | ||
iweights = (npy_uintp *)PyArray_DATA(wts); |
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.
This is cast is wrong. You should stick with intp
everywhere.
EDIT: Ops, that is unclear. The cast is wrong, not all integers are uintp
(in fact it looks like you make it double here?). The intp
comment is that uintp
isn't the correct type unless you are preserving user input, you shouldn't change that.
One reason I haven't looked at this much yet is that I am not sure how far we actually want to go here, since np.add.at
is faster now and is often a work-around (it doesn't auto-resize create/resize the result mainly).
Expanding this to more than just complex requires either proper templating (moving to c.src
format or C++
) or figuring out how to re-use the ufunc.at
logic (which may well be easier, since that has fast loops now; but that needs some new logic like chunking the index to resize, which might affect performance, although I doubt much).
@mattip do you have a tought about this?
This PR adds support for complex array weights in the
np.bincount
method.Things that still need to be done:
Could somebody please give some feedback on the changes so far? In particular I am not sure if this is the best way to do complex addition. Also, I am not sure if changing the behaviour based on datatype using the if/else statements is the best approach.
Closes #23313