Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/12498#discussion_r60615930
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/feature/HashingTF.scala ---
@@ -66,8 +83,9 @@ class HashingTF(val numFeatures: Int) extends
Serializable {
def transform(document: Iterable[_]): Vector = {
val termFrequencies = mutable.HashMap.empty[Int, Double]
val setTF = if (binary) (i: Int) => 1.0 else (i: Int) =>
termFrequencies.getOrElse(i, 0.0) + 1.0
+ val hashFunc: Any => Int = if (hashAlgorithm == Murmur3) murmur3Hash
else nativeHash
document.foreach { term =>
- val i = indexOf(term)
+ val i = Utils.nonNegativeMod(hashFunc(term), numFeatures)
--- End diff --
After this change, we can ensure ```transform()``` just checks the
```hashAlgorithm``` once (rather than on each call to the original
```indexOf```).
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]