Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 564f8b7

Browse files
committed
Reusing make_int_array function
1 parent 1278bbc commit 564f8b7

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

sklearn/feature_extraction/text.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -784,15 +784,9 @@ def _count_vocab(self, raw_documents, fixed_vocab):
784784

785785
analyze = self.build_analyzer()
786786
j_indices = []
787-
if sp_version >= (0, 14):
788-
# We can use 64-bit indices
789-
# NOTE: long on Windows is only 32 bits
790-
# indptr stores indices into j_indices, which can be large
791-
indptr = _make_long_array()
792-
else:
793-
# Sparse arrays only support 32-bit integers
794-
# j_indices stores feature indices, likely to be < 2^31
795-
indptr = _make_int_array()
787+
# indptr stores indices into j_indices, which can be large
788+
indptr = _make_int_array(dtype='l')
789+
values = _make_int_array()
796790
indptr.append(0)
797791
for doc in raw_documents:
798792
feature_counter = {}
@@ -970,18 +964,12 @@ def get_feature_names(self):
970964
key=itemgetter(1))]
971965

972966

973-
def _make_int_array():
974-
"""Construct an array.array of a type suitable for scipy.sparse indices."""
975-
return array.array(str("i"))
976-
977-
def _make_long_array():
978-
"""Construct an array.array of a type suitable for large scipy.sparse indices.
979-
980-
scipy 0.14 and later can construct sparse matrices with 64 bit integer indices.
967+
def _make_int_array(dtype='i'):
968+
"""Construct an array.array of a type suitable for scipy.sparse indices.
981969
982970
NOTE: long on Windows is only 32 bits
983971
"""
984-
return array.array(str("l"))
972+
return array.array(str(dtype))
985973

986974

987975
class TfidfTransformer(BaseEstimator, TransformerMixin):

0 commit comments

Comments
 (0)