Skip to content

Instantly share code, notes, and snippets.

View craffel's full-sized avatar

Colin Raffel craffel

View GitHub Profile
@craffel
craffel / popcount_array.pyx
Last active October 11, 2022 20:48 — forked from aldro61/popcount_array.pyx
Popcount of a numpy array of integers of any dtype
"""
Functions for computing the population count (aka Hamming weight) of an array
in-place using the built-in popcount routine.
Works with any integer datatype 64 bit-width or smaller.
Compile with gcc flag -mpopcnt
Adapted from
https://gist.github.com/aldro61/f604a3fa79b3dec5436a by Alexandre Drouin
"""
import numpy as np
cimport numpy as np