huaxingao commented on a change in pull request #25324:
[SPARK-21481][ML][FOLLOWUP] HashingTF Cleanup and Tiny Optimizations
URL: https://github.com/apache/spark/pull/25324#discussion_r311771584
##########
File path: mllib/src/main/scala/org/apache/spark/ml/feature/HashingTF.scala
##########
@@ -100,19 +100,20 @@ class HashingTF @Since("1.4.0") (@Since("1.4.0")
override val uid: String)
@Since("2.0.0")
override def transform(dataset: Dataset[_]): DataFrame = {
val outputSchema = transformSchema(dataset.schema)
+ val localNumFeatures = $(numFeatures)
+ val localBinary = $(binary)
+
val hashUDF = udf { terms: Seq[_] =>
- val numOfFeatures = $(numFeatures)
- val isBinary = $(binary)
val termFrequencies = mutable.HashMap.empty[Int,
Double].withDefaultValue(0.0)
terms.foreach { term =>
- val i = indexOf(term)
- if (isBinary) {
+ val i = Utils.nonNegativeMod(hashFunc(term), localNumFeatures)
Review comment:
Since we now have ```indexOf```, I guess it might be slight better to reuse
this method.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]