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.
This commit is contained in:
Mathieu Blondel 2013-05-08 04:44:37 +09:00
parent dc38e6baeb
commit dcebf9eaa3
1 changed files with 3 additions and 3 deletions

View File

@ -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)