10000 out kwarg to bincount · Issue #7998 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

out kwarg to bincount #7998

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

Closed
anntzer opened this issue Aug 31, 2016 · 5 comments
Closed

out kwarg to bincount #7998

anntzer opened this issue Aug 31, 2016 · 5 comments

Comments

@anntzer
Copy link
Contributor
anntzer commented Aug 31, 2016

bincount could gain an out kwarg (which would not get zeroed before adding the weights).

Rationale: This would sidestep the issue of poor ufunc.at performance (#5922) at least for the add ufunc.

I'd expect this kwarg to be incompatible with minlength; the minlength would simply be obtained from the length of the out array.

@jaimefrio
Copy link
Member

So you would accumulate on top of the value already stored in the array? That's an interesting idea! Can you elaborate on how it replaces .at, maybe with an example?

Deciding on doing this would probably need some discussion on the list, but implementing it should be relatively straightforward.

@anntzer
Copy link
Contributor Author
anntzer commented Aug 31, 2016

Basically, you'd replace

indices = ...
weights = ...
counts = ... # perhaps a previous value, or just np.zeros(...)
np.add.at(counts, indices, weights)

by

counts = ...
np.bincount(indices, weights, out=counts)

TBH I feel it would be preferable to fix the performance of ufunc.at; OTOH given the discussion on #5922 I guess it's not going to happen any time soon, and this may be a reasonable and simpler to implement workaround.

@seberg
Copy link
Member
seberg commented Aug 31, 2016

I think you can get a speedup of maybe even up to 5 without completely overhauling ufunc.at implementation, though.

@mattip
Copy link
Member
mattip commented Feb 1, 2023

In PR #23136 ufunc.add.at became fast enough that I think it can be used for this.

@mattip
Copy link
Member
mattip commented Feb 8, 2023

Closing, #23136 was merged

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

No branches or pull requests

4 participants
0