Skip to content

Commit

Permalink
removed scipy sparsetools functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hechth committed Nov 7, 2024
1 parent b9119e0 commit fe730c2
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions gensim/models/lsimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import numpy as np
import scipy.linalg
import scipy.sparse
from scipy.sparse import sparsetools

from gensim import interfaces, matutils, utils
from gensim.models import basemodel
Expand Down Expand Up @@ -960,10 +959,8 @@ def stochastic_svd(
m, n = corpus.shape
assert num_terms == m, f"mismatch in number of features: {m} in sparse matrix vs. {num_terms} parameter"
o = random_state.normal(0.0, 1.0, (n, samples)).astype(y.dtype) # draw a random gaussian matrix
sparsetools.csc_matvecs(
m, n, samples, corpus.indptr, corpus.indices,
corpus.data, o.ravel(), y.ravel(),
) # y = corpus * o
y = corpus.dot(o) # y = corpus * o

del o

# unlike np, scipy.sparse `astype()` copies everything, even if there is no change to dtype!
Expand Down Expand Up @@ -994,10 +991,7 @@ def stochastic_svd(
num_docs += n
logger.debug("multiplying chunk * gauss")
o = random_state.normal(0.0, 1.0, (n, samples), ).astype(dtype) # draw a random gaussian matrix
sparsetools.csc_matvecs(
m, n, samples, chunk.indptr, chunk.indices, # y = y + chunk * o
chunk.data, o.ravel(), y.ravel(),
)
y = y + chunk * o
del chunk, o
y = [y]
q, _ = matutils.qr_destroy(y) # orthonormalize the range
Expand Down

0 comments on commit fe730c2

Please sign in to comment.