Skip to content

Commit

Permalink
Fix rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartenGr committed Jun 8, 2021
1 parent d2ef5b2 commit aec80ef
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/releases.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
v0.3.1
v0.3.2
- Fix exploding memory usage when using `top_n`

v0.3.0
Expand Down
2 changes: 1 addition & 1 deletion polyfuzz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .polyfuzz import PolyFuzz
__version__ = "0.3.1"
__version__ = "0.3.2"
6 changes: 3 additions & 3 deletions polyfuzz/models/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def cosine_similarity(from_vector: np.ndarray,
similarity_matrix = similarity_matrix.tocsr()

indices = _top_n_idx_sparse(similarity_matrix, top_n)
similarities = _top_n_similarities_sparse(similarity_matrix, top_n, indices)
similarities = _top_n_similarities_sparse(similarity_matrix, indices)
indices = np.array(np.nan_to_num(np.array(indices, dtype=np.float), nan=0), dtype=np.int)

# Faster than knn and slower than sparse but uses more memory
Expand Down Expand Up @@ -132,11 +132,11 @@ def _top_n_idx_sparse(matrix, n):
return np.array(top_n_idx)


def _top_n_similarities_sparse(matrix, n, indices):
def _top_n_similarities_sparse(matrix, indices):
""" Return similarity scores of top n values in each row of a sparse matrix """
similarity_scores = []
for row, values in enumerate(indices):
scores = [round(matrix[row, value], n) if value is not None else 0 for value in values]
scores = [round(matrix[row, value], 3) if value is not None else 0 for value in values]
similarity_scores.append(scores)
similarity_scores = np.array(similarity_scores).T
return similarity_scores
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
setup(
name="polyfuzz",
packages=find_packages(exclude=["notebooks", "docs"]),
version="0.3.1",
version="0.3.2",
author="Maarten Grootendorst",
author_email="maartengrootendorst@gmail.com",
description="PolyFuzz performs fuzzy string matching, grouping, and evaluation.",
Expand Down

0 comments on commit aec80ef

Please sign in to comment.