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

Fix issue #628 with '.A' stuff on csr_matrix #631

Merged
merged 3 commits into from
Jul 5, 2024
Merged
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
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
Loading