Skip to content

ENH: Expose bit_count ufunc equivalent to the scalar methods #16325

@hexchain

Description

@hexchain

Modern CPUs have a builtin popcount instruction that counts the number of 1 bit in an unsigned integer. It would be great if numpy has a routine that exposes this operation.

Both GCC and MSVC have builtin functions for this instruction.

Possible usage:

>>> np.popcount(4)
1
>>> np.popcount(np.arange(5, dtype=np.uint))
array([0, 1, 1, 2, 1])

Metadata

Metadata

Assignees

No one assigned

    Labels

    01 - Enhancement62 - Python APIChanges or additions to the Python API. Mailing list should usually be notified.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions