From dcebf9eaa3c8a6ebb34a4aca0a89c2c3a9c6c8b9 Mon Sep 17 00:00:00 2001 From: Mathieu Blondel Date: Wed, 8 May 2013 04:44:37 +0900 Subject: [PATCH] COSMIT: more robust condition in inverse_transform. We need to support other formats than CSC and COO. Besides, tocsr() doesn't trigger a copy if the matrix is already CSR. --- sklearn/feature_extraction/text.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py index af8666c2a95..2ac774f0b92 100644 --- a/sklearn/feature_extraction/text.py +++ b/sklearn/feature_extraction/text.py @@ -806,10 +806,10 @@ class CountVectorizer(BaseEstimator, VectorizerMixin): X_inv : list of arrays, len = n_samples List of arrays of terms. """ - if sp.isspmatrix_coo(X) or sp.isspmatrix_csc(X): - # COO matrix is not indexable, CSC is slow for row manipulations + if sp.issparse(X): + # We need CSR format for fast row manipulations. X = X.tocsr() - elif not sp.issparse(X): + else: # We need to convert X to a matrix, so that the indexing # returns 2D objects X = np.asmatrix(X)