Skip to content

Commit

Permalink
Fix scipy '.A' alias being deprecated (#631)
Browse files Browse the repository at this point in the history
* Fix issue #628 with '.A' stuff on csr_matrix

* Modifying requirements.txt for numpy and another .A

---------

Co-authored-by: tqtg <[email protected]>
  • Loading branch information
quentinhaenn and tqtg authored Jul 5, 2024
1 parent 27f4604 commit 3abfdaa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions cornac/data/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ def batch_bow(self, batch_ids, binary=False, keep_sparse=False):
if binary:
bow_mat.data.fill(1)

return bow_mat if keep_sparse else bow_mat.A
return bow_mat if keep_sparse else bow_mat.toarray()

def batch_tfidf(self, batch_ids, keep_sparse=False):
"""Return matrix of TF-IDF features corresponding to provided batch_ids
Expand All @@ -972,7 +972,8 @@ def batch_tfidf(self, batch_ids, keep_sparse=False):
"""
tfidf_mat = self.tfidf_matrix[batch_ids]
return tfidf_mat if keep_sparse else tfidf_mat.A
return tfidf_mat if keep_sparse else tfidf_mat.toarray()


class ReviewModality(TextModality):
"""Review modality
Expand Down Expand Up @@ -1034,6 +1035,7 @@ class ReviewModality(TextModality):
Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).
"""

def __init__(self,
data: List[tuple] = None,
group_by: str = None,
Expand Down
8 changes: 4 additions & 4 deletions cornac/models/knn/recom_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def score(self, user_idx, item_idx=None):
if item_idx is not None:
weighted_avg = compute_score_single(
True,
self.sim_mat[user_idx].A.ravel(),
self.sim_mat[user_idx].toarray().ravel(),
self.iu_mat.indptr[item_idx],
self.iu_mat.indptr[item_idx + 1],
self.iu_mat.indices,
Expand All @@ -251,7 +251,7 @@ def score(self, user_idx, item_idx=None):
weighted_avg = np.zeros(self.num_items)
compute_score(
True,
self.sim_mat[user_idx].A.ravel(),
self.sim_mat[user_idx].toarray().ravel(),
self.iu_mat.indptr,
self.iu_mat.indices,
self.iu_mat.data,
Expand Down Expand Up @@ -412,7 +412,7 @@ def score(self, user_idx, item_idx=None):
if item_idx is not None:
weighted_avg = compute_score_single(
False,
self.ui_mat[user_idx].A.ravel(),
self.ui_mat[user_idx].toarray().ravel(),
self.sim_mat.indptr[item_idx],
self.sim_mat.indptr[item_idx + 1],
self.sim_mat.indices,
Expand All @@ -424,7 +424,7 @@ def score(self, user_idx, item_idx=None):
weighted_avg = np.zeros(self.num_items)
compute_score(
False,
self.ui_mat[user_idx].A.ravel(),
self.ui_mat[user_idx].toarray().ravel(),
self.sim_mat.indptr,
self.sim_mat.indices,
self.sim_mat.data,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy
numpy<2.0
scipy
Cython
tqdm
Expand Down

0 comments on commit 3abfdaa

Please sign in to comment.