bitstring

Slow bitwise operations

泄露秘密 提交于 2019-11-30 20:13:00
I am working on a Python library that performs a lot of bitwise operations on long bit strings, and I want to find a bit string type that will maximize its speed. I have tried the built-in Python int type, numpy, bitstring , and bitarray , and suprisingly, the Python ints seem to win hands down when it comes to bitwise operations. Everything I have googled says numpy should be much faster for vectorized operations like this. Am I using numpy wrong somehow? Is there another Python library I can use that actually improves on Python's built-in int type? from timeit import timeit import random

Slow bitwise operations

拜拜、爱过 提交于 2019-11-30 03:49:13
问题 I am working on a Python library that performs a lot of bitwise operations on long bit strings, and I want to find a bit string type that will maximize its speed. I have tried the built-in Python int type, numpy, bitstring, and bitarray, and suprisingly, the Python ints seem to win hands down when it comes to bitwise operations. Everything I have googled says numpy should be much faster for vectorized operations like this. Am I using numpy wrong somehow? Is there another Python library I can

Calculating Hamming weight efficiently in matlab

倖福魔咒の 提交于 2019-11-28 08:25:39
Given a MATLAB uint32 to be interpreted as a bit string, what is an efficient and concise way of counting how many nonzero bits are in the string? I have a working, naive approach which loops over the bits, but that's too slow for my needs. (A C++ implementation using std::bitset count() runs almost instantly). I've found a pretty nice page listing various bit counting techniques, but I'm hoping there is an easy MATLAB-esque way. http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive Update #1 Just implemented the Brian Kernighan algorithm as follows: w = 0; while ( bits > 0 )