Skip to content

Commit

Permalink
fixed matrix_indptr
Browse files Browse the repository at this point in the history
  • Loading branch information
manneshiva committed May 18, 2017
1 parent 7c1e57d commit 2eef0b6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gensim/matutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,15 @@ def scipy2scipy_clipped(matrix, topn, eps=1e-9):
else:
matrix_indices = []
matrix_data = []
matrix_indptr = [0]
for v in matrix:
# Sort and clip each row vector first.
biggest = argsort(abs(v).data, topn, reverse=True)
indices, data = v.indices.take(biggest), v.data.take(biggest)
# Store the topn indices and values of each row vector.
matrix_data.append(data)
matrix_indices.append(indices)
matrix_indptr = np.array([i * topn for i in range(1 + len(matrix_indices))])
matrix_indptr.append(matrix_indptr[-1] + min(len(indices), topn))
matrix_indices = np.concatenate(matrix_indices).ravel()
matrix_data = np.concatenate(matrix_data).ravel()
# Instantiate and return a sparse csr_matrix which preserves the order of indices/data.
Expand Down

0 comments on commit 2eef0b6

Please sign in to comment.