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

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 6

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: RaRe-Technologies/gensim
Commit Name: 1524323f6cf1de9ce95c029cbdf264ac516b21d8
Time: 2010-04-11
Author: piskvorky@92d0401f-a546-4972-9173-107b360ed7e5
File Name: src/gensim/matutils.py
Class Name:
Method Name: unitVec


Project Name: RaRe-Technologies/gensim
Commit Name: 4595a8b03d2735f78575a5206717fe1b92ec5d2a
Time: 2010-04-11
Author: radimrehurek@seznam.cz
File Name: src/gensim/matutils.py
Class Name:
Method Name: unitVec