No project description provided
Project description
bit-counter
Package for counting the number of one bits in a numpy array of uint8 values. Implemented as a Python module using Rust, providing high performance counting.
Building
To build this package an installation of Rust and Python with the maturin package is required. The Maturin documentation on maturin local development is a useful reference for more details.
This project is configured by default to target CPUs with the POPCNT instruction.
The builds available on PyPI have been built with this configuration.
If you require a version for an older CPU without popcnt
support, build with
the RUSTFLAGS environment variable to exclude the popcnt
target-feature.
i.e. RUSTFLAGS='-C target-feature=-popcnt' maturin build -r
.
By default the bit counting is done with a parallel map across all available
CPUs through the use of rayon. Number of threads
can be configured with the environment variable RAYON_NUM_THREADS
.
Example usage
import numpy as np
from bit_counter import count_ones
arr = np.packbits(np.random.choice([True, False], 1000000))
count_of_true_values = count_ones(arr)
Performance
When built to target a CPU with popcnt
support the count_ones
method
provided is substantially faster than a naive np.unpackbits(arr).sum()
.
The count_ones
method also doesn't require unpacking the bit packed numpy
array, so doesn't require any addtional memory to do the calculation.
For example with the following test code for 100 million True/False values that are packed:
import numpy as np
from bit_counter import count_ones
arr = np.packbits(np.random.choice([True, False], 100000000))
Using this package on an AMD Ryzen 9 3900X 12-Core Processor yields:
%timeit count_ones(arr)
905 µs ± 4.64 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
Compared to the simple unpack and sum case:
%timeit np.unpackbits(arr).sum()
60.4 ms ± 421 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file bit_counter-0.2.0.tar.gz
.
File metadata
- Download URL: bit_counter-0.2.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | daa7ebb572b1e8ad1a4c7caa754d1223948a1d5d056361a5f2fa903ad862af64 |
|
MD5 | c0912e42f8093ebfdde364279de206b6 |
|
BLAKE2b-256 | a01e228c3dd784d8c2516b158d140352bdff86433c44ab60d95fb1c8aabe807c |
File details
Details for the file bit_counter-0.2.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: PyPy, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 357f1bec313132ec944656d939cf17d256fade06d1424175c5f9594b15e9e76e |
|
MD5 | fb4434ff0c121420da9bf8821eca96b4 |
|
BLAKE2b-256 | 516f27850e479634e268773f0f2f197515b7e57e08489b50f6fbfda54de82bb0 |
File details
Details for the file bit_counter-0.2.0-cp310-none-win_amd64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp310-none-win_amd64.whl
- Upload date:
- Size: 151.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c891b6b2652e069c15d951d3274148f38d6a2a8922ca0b57c67effa81de4b693 |
|
MD5 | 9f1b0490628edbb596c08e4dd7f4bc86 |
|
BLAKE2b-256 | 5f6ff52c1cf88ac1cb48dcd1a63017c631621cb823c622f44e5a017de38e0aaa |
File details
Details for the file bit_counter-0.2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 782a82149250797789800e06857d43294f6cdc53799b38b3dd2165f088f3bb8a |
|
MD5 | c9a84d4370ea6692ada9c0f4e03507b4 |
|
BLAKE2b-256 | 88a086bb52ddf28ecb6826306ae706395964d8726d42a0c9596ed0b71f5cc829 |
File details
Details for the file bit_counter-0.2.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 525.7 kB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66a5c01e374a6f34c0c9b38546b5e9c1a68e3af8e9f692b1c7b3dfc03dbdfaff |
|
MD5 | f1a7dc7d3012d477353c25bd7586410b |
|
BLAKE2b-256 | 7eb1dc043a4e9fc287fee54b899a37160d2e90eb48566878c0e809611874a508 |
File details
Details for the file bit_counter-0.2.0-cp39-none-win_amd64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp39-none-win_amd64.whl
- Upload date:
- Size: 151.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67c02b3c3040b04b607ed5671f1957bbb54455bb4abb8f7b7012538d8bfc43e6 |
|
MD5 | a8565f3bbbe64557510fac6f76f5cae2 |
|
BLAKE2b-256 | 90c7159a0425dcabfbbc79abb4712b709090da5b71e1867c3990dc50bddb856e |
File details
Details for the file bit_counter-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b96b9a4091aa6d42d7f2566d9f8e91718a39fc7cb459229757d758b18c98918d |
|
MD5 | 5701e81c44d16d422ea1c13bbbdf4cef |
|
BLAKE2b-256 | 0bfa5f65b834e38b2922837ed8de5ecccc3e977e15691ae309574e31c3999129 |
File details
Details for the file bit_counter-0.2.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 525.1 kB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 466d7ee572d39ec64843e8d1e483be3a4aa300c4206e9cfc4fc229e0b6e95d50 |
|
MD5 | bba14fb01e5ea85112ebad2c6aa6ad4d |
|
BLAKE2b-256 | 7bed5bdeee168de172a932e8897ff6bb46dd5161aa0d0891683f2197a888097b |
File details
Details for the file bit_counter-0.2.0-cp38-none-win_amd64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp38-none-win_amd64.whl
- Upload date:
- Size: 150.9 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbef882ff2ecb3e53e4e413c4f8adc7225351dcc95c454a5155b8031a9ddffdf |
|
MD5 | 47e5d0bf2be1324388b4ff701c9c35be |
|
BLAKE2b-256 | 73130bb985429afb31d5f7a83d3bc90386d79dd1aecb125736064a05a97c0d16 |
File details
Details for the file bit_counter-0.2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 966a393cd528c225c91ca1d56fbadba076de597b839fec60a6654d50d808d1f7 |
|
MD5 | d754d50b58426d2fdd0534b7616e6e11 |
|
BLAKE2b-256 | 3328d80339c674ac57b19ad6015dc4e96c0326d68aa8ba02290046a93fdfe41a |
File details
Details for the file bit_counter-0.2.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 526.0 kB
- Tags: CPython 3.8, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8138b067850f14ba0b7eceab0db84b12c3ff7bf2f62c1ed24c63ae3c41d293c1 |
|
MD5 | acb3492ff699f0b23d4053e23af91288 |
|
BLAKE2b-256 | e954a090d4fc681cd676a0abd5976f335ac32b8803614eaa9286422d8a8d48b8 |
File details
Details for the file bit_counter-0.2.0-cp37-none-win_amd64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp37-none-win_amd64.whl
- Upload date:
- Size: 150.9 kB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff0ed2282b0a9ef31725bdda8cd673b27b99663071f961d3c308b93476941734 |
|
MD5 | 80bba91ca3913bde5120809d1c32c586 |
|
BLAKE2b-256 | bbcdce6735ff1af5208cddf3713111e1b6600d39b0fb1601df4684e2a29b27a2 |
File details
Details for the file bit_counter-0.2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.7m, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 222b15a5fc261a06d8d9d06a5877f8352dc36cb83cb2bdba30f7462080234ccf |
|
MD5 | 45a29c52fbcf57125205f583098d722a |
|
BLAKE2b-256 | 5b48231b5db1848ab975559a37eb48f91580c4a5fee2d59e79035302db3fb800 |
File details
Details for the file bit_counter-0.2.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: bit_counter-0.2.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 526.0 kB
- Tags: CPython 3.7m, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.13.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0e93a780b1cbc8ecda66aeda27d18dcee014a0ebab00d7fb0605b4312f41b5d |
|
MD5 | ddafe8a75898c9dd059a68b30ee233de |
|
BLAKE2b-256 | bb2304e1cb5f1af54bbc420634c8c469b556224deec8f2f52cedd2caec5424d7 |