srowen 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_r311807341
##########
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:
Yeah I'm neutral on it. As a matter of software design, reusing `indexOf`
makes sense. It may be more performant to inline it. Is there evidence it makes
a performance difference?
----------------------------------------------------------------
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]