Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/10146#discussion_r46708243
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/stat/test/ChiSqTest.scala ---
@@ -109,9 +109,10 @@ private[stat] object ChiSqTest extends Logging {
}
i += 1
distinctLabels += label
- features.toArray.view.zipWithIndex.slice(startCol, endCol).map {
case (feature, col) =>
- allDistinctFeatures(col) += feature
- (col, feature, label)
+ features.toArray.slice(startCol, endCol).zip(startCol until
endCol).map {
--- End diff --
`slice` is going to make a copy, and then `zip` will make another one. If
the goal is to improve performance, I think it makes the most sense to iterate
over the range you want directly:
```scala
val arr = features.toArray
(startCol until endCol).map { col =>
val feaure = arr(col)
allDistinctFeatures(col) += feature
(col, feature, label)
}
```
or even go a step further and pre-allocate the result array, to avoid all
the copying from dynamically growing it.
also `toArray` is going to be horrible on sparse vectors -- it might make
more sense to use `toBreeze`, which won't create so much wasted space (though
still suboptimal looping). Better would be special handling. But that is
independent from the main issue here.
---
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]