a31eab99dfbc6dcb7fe2ef149c59a30910adbbbd,src/gensim/similarities/docsim.py,SparseMatrixSimilarity,getSimilarities,#SparseMatrixSimilarity#Any#,206
Before Change
vec = scipy.sparse.dok_matrix((self.corpus.shape[1], 1), dtype=self.corpus.dtype)
for fieldId, fieldValue in doc:
vec[fieldId, 0] = fieldValue
if vec.shape != (self.corpus.shape[1], 1):
raise ValueError("vector shape mismatch; expected %s, got %s" %
((self.corpus.shape[1], 1,), vec.shape))
// compute cosine similarity against every other document in the collection
allSims = self.corpus * vec.tocsc() // N x T * T x 1 = N x 1
allSims = list(allSims.toarray().flat) // convert to plain python list
assert len(allSims) == self.corpus.shape[0] // make sure no document got lost!
return allSims
After Change
// compute cosine similarity against every other document in the collection
result = self.corpus * query.tocsc() // N x T * T x C = N x C
if result.shape[1] == 1:
// for queries of one document, return a 1d array
result = result.toarray().flatten()
else:
// otherwise, return a 2d matrix (//queries x //index)
result = result.toarray().T
return result
//endclass SparseMatrixSimilarity
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 7
Instances
Project Name: RaRe-Technologies/gensim
Commit Name: a31eab99dfbc6dcb7fe2ef149c59a30910adbbbd
Time: 2011-05-15
Author: radimrehurek@seznam.cz
File Name: src/gensim/similarities/docsim.py
Class Name: SparseMatrixSimilarity
Method Name: getSimilarities
Project Name: tensorflow/kfac
Commit Name: 94855fb1910ff6b9dd8306dafd097ac9f93eb57b
Time: 2019-08-13
Author: jamesmartens@google.com
File Name: kfac/python/ops/utils.py
Class Name:
Method Name: cross_replica_mean
Project Name: tensorflow/kfac
Commit Name: 94855fb1910ff6b9dd8306dafd097ac9f93eb57b
Time: 2019-08-13
Author: jamesmartens@google.com
File Name: kfac/python/ops/utils.py
Class Name:
Method Name: cross_replica_sum