Skip to content

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

alex-gregory-ds
Copy link

@alex-gregory-ds alex-gregory-ds commented Apr 22, 2023

This PR adds support for complex array weights in the np.bincount method.

Things that still need to be done:

  • Update unit tests
  • Update documentation
  • Add support for integer weights

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

@charris charris changed the title Add support for complex weights in np.bincount ENH: Add support for complex weights in np.bincount Apr 22, 2023
@alex-gregory-ds alex-gregory-ds force-pushed the support-for-bincount-complex-weights branch from 66ef30c to 8cdd947 Compare April 28, 2023 18:23
@alex-gregory-ds alex-gregory-ds force-pushed the support-for-bincount-complex-weights branch from 8cdd947 to 66ae571 Compare April 28, 2023 18:28
@alex-gregory-ds alex-gregory-ds marked this pull request as ready for review April 28, 2023 20:42
@alex-gregory-ds
Copy link
Author

I have ran runtests.py locally and get no errors but I am having issues getting the jobs to pass. In particular, for the Test Meson build (Windows) / Meson windows build/test (pull_request) it looks like I am getting some overflow issues but I am not sure why. It dosen't look like I am getting any overflow issues on the Test Meson build (Linux) / meson_spin (pull_request) job. Can anybody give me some help with this please?

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);
Copy link
Member

@seberg seberg Apr 29, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bincount does not accept complex valued weights
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy