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.
When building it is best to set the RUSTFLAGS environment variable to specify
targeting CPUs with the POPCNT instruction. i.e. RUSTFLAGS='-C target-feature=+popcnt' maturin build -r
.
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 a mid-2013 MacBook Air (1.7 GHz Intel Core i7) yields:
%timeit count_ones(arr)
45.3 ms ± 2.08 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
Compared to the simple unpack and sum case:
%timeit np.unpackbits(arr).sum()
108 ms ± 6.89 ms 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
Hashes for bit_counter-0.1.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47f7b5ff67da46871ae35098b2b050ecde213589996bfdb11a50919155323613 |
|
MD5 | 61c7f980584f49ec96bcf8309ab382de |
|
BLAKE2b-256 | cb52551e0b13c8d9a9ba76b977a875e700fc9add9b2dfe84dd25f91d3f66b762 |
Hashes for bit_counter-0.1.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9108a26ef1498fc942eb5ef8b4d591a42c9d94eda7a32f1e183c89b9ac4ea43 |
|
MD5 | ddc6e1060b66f46a50a77fae777f58b4 |
|
BLAKE2b-256 | 70de7dd67f424016ec3bc7b35951d5de6804c9dac05ad6a1aeee89e25c4b4d20 |
Hashes for bit_counter-0.1.0-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84ca7be58517ad6dec02747eb4029a952175e2ac040c90a24f6674fdb6c5d017 |
|
MD5 | 0d024009f19542a88d43b18fd5c7f5b1 |
|
BLAKE2b-256 | 3e72412ebd057207e059de02b5421d2704a333bf04c9c6d181cc14f19ab47161 |
Hashes for bit_counter-0.1.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da2eb6a5ed2e51a0e49f2d6f99ae2b16f76eaf9cb16288623d4ecb852bd7f8fa |
|
MD5 | d8ce53f96c5cc11fcf71155d0e52cc94 |
|
BLAKE2b-256 | dfe643ed5ff1cfbce6178ffe443a0b89c5775a1ac878f5459f0fc9040e64ab46 |
Hashes for bit_counter-0.1.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b01068b3345359e361ec37c3f5dc65b5aeacf8cc4b654fdfe0816e19626990a4 |
|
MD5 | 48472d4525dc6c98a8f103f7197ed024 |
|
BLAKE2b-256 | 623f9dd27fbcb2ea93811bd82dc078a767ed5ed08b015376833f21b0515c667a |
Hashes for bit_counter-0.1.0-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 984ebd44de7beca070e259a45d3876fefd19122417d13da1367fbfc36c15cb1e |
|
MD5 | 4ff60c9a77221d2d4f782ff43c874d97 |
|
BLAKE2b-256 | bb51208eae15d4ac0f4fafabd2991888de2f4f422e358e718613e326fb923569 |
Hashes for bit_counter-0.1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f02ad2373d50355fafd22e450ad1458f850e3fa3b70307676908cc3f32329f6b |
|
MD5 | 7dc7c7ef3c244fee36c2c1022af93c17 |
|
BLAKE2b-256 | f593f01c510d863149439e0cb036f39517287b44c8b86c510fc40fd14dd6bb8c |
Hashes for bit_counter-0.1.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30da4f1103b1cafeb27299009ca3f13c49400020477cd2378ee6bca0f4275d9b |
|
MD5 | f9cc0aa9fdc45d9a7dd5a3cc05405664 |
|
BLAKE2b-256 | f17aeb1fe6438cba2e6ebd1599c7c3f13c88456a64dfeed0f710284a3ffa2625 |
Hashes for bit_counter-0.1.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb945f9d9830e671c743d71f0f4ed77dd846d0e1e71e73a358ba0006a44b445a |
|
MD5 | aa7ce204b3eb098d82c143d36572ac92 |
|
BLAKE2b-256 | 924ce207291e49ce9cfd042927fd318f20e58052723f36ae82f74c8074c182fd |
Hashes for bit_counter-0.1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c899960c02ad930ae6ad3d0ff6fcbfab56d18b234f9fa06049e184827baf1570 |
|
MD5 | 7be1e0188d72e103609665883f383cd1 |
|
BLAKE2b-256 | 18ffe204f7b9e995adae769d712c62f240aac07c36520a589ee87093bc409e57 |
Hashes for bit_counter-0.1.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f6ee9b0ed4b30b895b9ada5649aff913293ee8b3c830c8d021c7067ad3003b8 |
|
MD5 | 376d02454401bdc9a5b75f6ea496d54c |
|
BLAKE2b-256 | 7ceab67717cde9b460db29cab74280faf6a6b681c15c3e78faa4d982ed0de7e2 |
Hashes for bit_counter-0.1.0-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20e58411bd0a74b20347acc441c19187bccc57b997cd473616bc94c8cb3c83a0 |
|
MD5 | cd1e689c42684ceac37e8a200aeaf743 |
|
BLAKE2b-256 | da83dbc8d7c8847b1c751b8b79be52def6d1d4934037dadabee0849761694710 |
Hashes for bit_counter-0.1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f613e9446edb61b1e1ed4c32a8223e2c6a5bed4e6986da17a088034553b4a5f4 |
|
MD5 | ac18e37818995ac97760d71843b72737 |
|
BLAKE2b-256 | 39dddfe31d188f959787ed09d47f3da3eb6e7c34892e8979f26eb36deeec9ba0 |
Hashes for bit_counter-0.1.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1717ecc7dbc3d16fb13a3fc422d71bd69d321ba213b5d3cfa380ff2099a8e9f1 |
|
MD5 | 49afbe73f504ffb73e9e99822b5a8591 |
|
BLAKE2b-256 | e1c43dd0ba7d628e7624ea7f7e8511bd40305e7dcf7f9fbe5a7374ea9da121d4 |