Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gmpy2 #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
pip install nose2 numpy scipy scikit-learn
pip install nose2 numpy scipy scikit-learn gmpy2
- name: Run tests
run: nose2 -v --pretty-assert
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
platforms = 'any',
install_requires = [
'numpy',
'gmpy2',
],
tests_require = [
'nose2',
Expand Down
8 changes: 2 additions & 6 deletions simhash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from itertools import groupby

import numpy as np
from gmpy2 import popcount

try:
from collections.abc import Iterable
Expand Down Expand Up @@ -160,12 +161,7 @@ def _bitarray_from_bytes(b):

def distance(self, another):
assert self.f == another.f
x = (self.value ^ another.value) & ((1 << self.f) - 1)
ans = 0
while x:
ans += 1
x &= x - 1
return ans
return popcount(self.value ^ another.value)


class SimhashIndex(object):
Expand Down