Github user karlhigley commented on a diff in the pull request: https://github.com/apache/spark/pull/9843#discussion_r46013493 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/feature/IDF.scala --- @@ -211,14 +213,16 @@ private object IDFModel { val n = v.size v match { case SparseVector(size, indices, values) => - val nnz = indices.size - val newValues = new Array[Double](nnz) + val newElements = new ArrayBuffer[(Int, Double)] var k = 0 - while (k < nnz) { - newValues(k) = values(k) * idf(indices(k)) + while (k < indices.size) { + val newValue = values(k) * idf(indices(k)) --- End diff -- Good point about `indices.size`, I've added a commit to move that outside the loop. The purpose of this ticket and PR is to remove explicit zeros from the output of `IDFModel.transform`. There may be further performance optimizations to be done in this section of code (e.g. the four cases as you suggest). It's not clear to me that the code in this PR is significantly less performant than what was already there, or that the suggested optimized code addresses the original issue. Maybe I'm missing something?
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org