Skip to content

Commit

Permalink
Merge pull request #2083 from recommenders-team/miguel/scipy_sar_issue
Browse files Browse the repository at this point in the history
SAR sparse multiplcation modification due to a breaking change in scipy
  • Loading branch information
miguelgfierro committed Apr 29, 2024
2 parents f7e8194 + 7c51605 commit 6fb6a95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions recommenders/utils/python_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def jaccard(cooccurrence):
with np.errstate(invalid="ignore", divide="ignore"):
result = cooccurrence / (diag_rows + diag_cols - cooccurrence)

return np.array(result)
return np.array(result) if isinstance(result, np.ndarray) else result.toarray()


def lift(cooccurrence):
Expand All @@ -85,7 +85,7 @@ def lift(cooccurrence):
with np.errstate(invalid="ignore", divide="ignore"):
result = cooccurrence / (diag_rows * diag_cols)

return np.array(result)
return np.array(result) if isinstance(result, np.ndarray) else result.toarray()


def mutual_information(cooccurrence):
Expand All @@ -106,7 +106,7 @@ def mutual_information(cooccurrence):
with np.errstate(invalid="ignore", divide="ignore"):
result = np.log2(cooccurrence.shape[0] * lift(cooccurrence))

return np.array(result)
return np.array(result) if isinstance(result, np.ndarray) else result.toarray()


def lexicographers_mutual_information(cooccurrence):
Expand All @@ -128,7 +128,7 @@ def lexicographers_mutual_information(cooccurrence):
with np.errstate(invalid="ignore", divide="ignore"):
result = cooccurrence * mutual_information(cooccurrence)

return np.array(result)
return np.array(result) if isinstance(result, np.ndarray) else result.toarray()


def cosine_similarity(cooccurrence):
Expand All @@ -151,7 +151,7 @@ def cosine_similarity(cooccurrence):
with np.errstate(invalid="ignore", divide="ignore"):
result = cooccurrence / np.sqrt(diag_rows * diag_cols)

return np.array(result)
return np.array(result) if isinstance(result, np.ndarray) else result.toarray()


def inclusion_index(cooccurrence):
Expand All @@ -173,7 +173,7 @@ def inclusion_index(cooccurrence):
with np.errstate(invalid="ignore", divide="ignore"):
result = cooccurrence / np.minimum(diag_rows, diag_cols)

return np.array(result)
return np.array(result) if isinstance(result, np.ndarray) else result.toarray()


def get_top_k_scored_items(scores, top_k, sort_top_k=False):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"retrying>=1.3.4,<2",
"scikit-learn>=1.2.0,<2", # requires scipy, and introduce breaking change affects feature_extraction.text.TfidfVectorizer.min_df
"scikit-surprise>=1.1.3",
"scipy>=1.10.1,<1.11.0", # FIXME: We limit <1.11.0 until #1954 is fixed
"scipy>=1.10.1",
"seaborn>=0.13.0,<1", # requires matplotlib, packaging
"transformers>=4.27.0,<5", # requires packaging, pyyaml, requests, tqdm
]
Expand Down

0 comments on commit 6fb6a95

Please sign in to comment.