-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff69972
commit 257592a
Showing
4 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Naive popcount implementation until such time that's exposed in numpy (SOON!).""" | ||
import numpy as np | ||
|
||
|
||
m1 = np.uint64(0x5555555555555555) | ||
m2 = np.uint64(0x3333333333333333) | ||
m3 = np.uint64(0x0F0F0F0F0F0F0F0F) | ||
m4 = np.uint64(0x0101010101010101) | ||
|
||
|
||
mask = np.uint64(-1) | ||
# TODO - precompute type specific hashes | ||
s55 = np.uint64(m1 & mask) # Add more digits for 128bit support | ||
s33 = np.uint64(m2 & mask) | ||
s0F = np.uint64(m3 & mask) | ||
s01 = np.uint64(m4 & mask) | ||
num_bytes_64 = 8 | ||
|
||
|
||
def bit_count64(arr): | ||
"""Count the number of bits set in each element in the array.""" | ||
arr = arr - ((arr >> 1) & s55) | ||
arr = (arr & s33) + ((arr >> 2) & s33) | ||
|
||
arr += (arr >> 4) | ||
arr &= s0F | ||
arr *= s01 | ||
arr >>= (8 * (num_bytes_64 - 1)) | ||
|
||
return arr |