Github user sethah commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15831#discussion_r88530411
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/feature/ChiSqSelector.scala ---
    @@ -243,6 +244,42 @@ final class ChiSqSelectorModel private[ml] (
         StructType(outputFields)
       }
     
    +  private def compress(features: Vector): Vector = {
    +    features match {
    +      case SparseVector(_, indices, values) =>
    +        val newSize = selectedFeatures.length
    +        val newValues = new ArrayBuilder.ofDouble
    +        val newIndices = new ArrayBuilder.ofInt
    +        var i = 0
    +        var j = 0
    +        var indicesIdx = 0
    +        var filterIndicesIdx = 0
    +        while (i < indices.length && j < newSize) {
    +          indicesIdx = indices(i)
    +          filterIndicesIdx = selectedFeatures(j)
    +          if (indicesIdx == filterIndicesIdx) {
    +            newIndices += j
    +            newValues += values(i)
    +            j += 1
    +            i += 1
    +          } else {
    +            if (indicesIdx > filterIndicesIdx) {
    +              j += 1
    +            } else {
    +              i += 1
    +            }
    +          }
    +        }
    +        Vectors.sparse(newSize, newIndices.result(), newValues.result())
    +      case DenseVector(values) =>
    +        val values = features.toArray
    +        Vectors.dense(selectedFeatures.map(i => values(i)))
    +      case other =>
    --- End diff --
    
    btw there is no reason to have this case since `Vector` is a sealed trait


---
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]

Reply via email to