Skip to content

out kwarg to bincount #7998

Closed
Closed

Description

@anntzer

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.

Activity

  1. jaimefrio commented on Aug 31, 2016

    @jaimefrio
    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.

  2. anntzer commented on Aug 31, 2016

    @anntzer
    ContributorAuthor

    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.

  3. seberg commented on Aug 31, 2016

    @seberg
    Member

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

  4. mattip commented on Feb 1, 2023

    @mattip
    Member

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

  5. mattip commented on Feb 8, 2023

    @mattip
    Member

    Closing, #23136 was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions