8000 [MRG+1] micro-optimize HashingVectorizer and FeatureHasher by kmike · Pull Request #7470 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] micro-optimize HashingVectorizer and FeatureHasher #7470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions sklearn/feature_extraction/_hashing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ from libc.stdlib cimport abs
cimport numpy as np
import numpy as np

from ..externals.six import string_types

from sklearn.utils.murmurhash cimport murmurhash3_bytes_s32

np.import_array()
Expand Down Expand Up @@ -45,7 +43,7 @@ def transform(raw_X, Py_ssize_t n_features, dtype):

for x in raw_X:
for f, v in x:
if isinstance(v, string_types):
if isinstance(v, (str, unicode)):
f = "%s%s%s" % (f, '=', v)
value = 1
else:
Expand All @@ -55,13 +53,13 @@ def transform(raw_X, Py_ssize_t n_features, dtype):
continue

if isinstance(f, unicode):
f = f.encode("utf-8")
f = (<unicode>f).encode("utf-8")
# Need explicit type check because Murmurhash does not propagate
# all exceptions. Add "except *" there?
elif not isinstance(f, bytes):
raise TypeError("feature names must be strings")

h = murmurhash3_bytes_s32(f, 0)
h = murmurhash3_bytes_s32(<bytes>f, 0)

array.resize_smart(indices, len(indices) + 1)
indices[len(indices) - 1] = abs(h) % n_features
Expand Down
0