Skip to content

Commit 3abfdaa

Browse files
Fix scipy '.A' alias being deprecated (#631)
* Fix issue #628 with '.A' stuff on csr_matrix * Modifying requirements.txt for numpy and another .A --------- Co-authored-by: tqtg <[email protected]>
1 parent 27f4604 commit 3abfdaa

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

cornac/data/text.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ def batch_bow(self, batch_ids, binary=False, keep_sparse=False):
951951
if binary:
952952
bow_mat.data.fill(1)
953953

954-
return bow_mat if keep_sparse else bow_mat.A
954+
return bow_mat if keep_sparse else bow_mat.toarray()
955955

956956
def batch_tfidf(self, batch_ids, keep_sparse=False):
957957
"""Return matrix of TF-IDF features corresponding to provided batch_ids
@@ -972,7 +972,8 @@ def batch_tfidf(self, batch_ids, keep_sparse=False):
972972
973973
"""
974974
tfidf_mat = self.tfidf_matrix[batch_ids]
975-
return tfidf_mat if keep_sparse else tfidf_mat.A
975+
return tfidf_mat if keep_sparse else tfidf_mat.toarray()
976+
976977

977978
class ReviewModality(TextModality):
978979
"""Review modality
@@ -1034,6 +1035,7 @@ class ReviewModality(TextModality):
10341035
Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).
10351036
10361037
"""
1038+
10371039
def __init__(self,
10381040
data: List[tuple] = None,
10391041
group_by: str = None,

cornac/models/knn/recom_knn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def score(self, user_idx, item_idx=None):
239239
if item_idx is not None:
240240
weighted_avg = compute_score_single(
241241
True,
242-
self.sim_mat[user_idx].A.ravel(),
242+
self.sim_mat[user_idx].toarray().ravel(),
243243
self.iu_mat.indptr[item_idx],
244244
self.iu_mat.indptr[item_idx + 1],
245245
self.iu_mat.indices,
@@ -251,7 +251,7 @@ def score(self, user_idx, item_idx=None):
251251
weighted_avg = np.zeros(self.num_items)
252252
compute_score(
253253
True,
254-
self.sim_mat[user_idx].A.ravel(),
254+
self.sim_mat[user_idx].toarray().ravel(),
255255
self.iu_mat.indptr,
256256
self.iu_mat.indices,
257257
self.iu_mat.data,
@@ -412,7 +412,7 @@ def score(self, user_idx, item_idx=None):
412412
if item_idx is not None:
413413
weighted_avg = compute_score_single(
414414
False,
415-
self.ui_mat[user_idx].A.ravel(),
415+
self.ui_mat[user_idx].toarray().ravel(),
416416
self.sim_mat.indptr[item_idx],
417417
self.sim_mat.indptr[item_idx + 1],
418418
self.sim_mat.indices,
@@ -424,7 +424,7 @@ def score(self, user_idx, item_idx=None):
424424
weighted_avg = np.zeros(self.num_items)
425425
compute_score(
426426
False,
427-
self.ui_mat[user_idx].A.ravel(),
427+
self.ui_mat[user_idx].toarray().ravel(),
428428
self.sim_mat.indptr,
429429
self.sim_mat.indices,
430430
self.sim_mat.data,

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy
1+
numpy<2.0
22
scipy
33
Cython
44
tqdm

0 commit comments

Comments
 (0)