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_r311138530
##########
File path: mllib/src/main/scala/org/apache/spark/ml/feature/HashingTF.scala
##########
@@ -100,19 +100,26 @@ 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 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 localNumFeatures = $(numFeatures)
+
+ val hashUDF = if ($(binary)) {
Review comment:
I guess I'm saying, is it worth duplicating the UDF definition to lift this
check out? just make a local `val binary = $(binary)` if you want to avoid
referencing the property every time.
----------------------------------------------------------------
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]