You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/02/25 03:32:15 UTC
[GitHub] [spark] zhengruifeng commented on a change in pull request #31588: [SPARK-34470][ML] VectorSlicer utilize ordering if possible
zhengruifeng commented on a change in pull request #31588:
URL: https://github.com/apache/spark/pull/31588#discussion_r582497661
##########
File path: mllib/src/main/scala/org/apache/spark/ml/feature/VectorSlicer.scala
##########
@@ -110,22 +110,21 @@ final class VectorSlicer @Since("1.5.0") (@Since("1.5.0") override val uid: Stri
}
// Prepare output attributes
- val inds = getSelectedFeatureIndices(dataset.schema)
- val selectedAttrs = inputAttr.attributes.map { attrs =>
- inds.map(index => attrs(index))
- }
+ val selectedIndices = getSelectedFeatureIndices(dataset.schema)
+ val selectedAttrs = inputAttr.attributes.map { attrs => selectedIndices.map(attrs.apply) }
val outputAttr = selectedAttrs match {
case Some(attrs) => new AttributeGroup($(outputCol), attrs)
- case None => new AttributeGroup($(outputCol), inds.length)
+ case None => new AttributeGroup($(outputCol), selectedIndices.length)
}
- // Select features
+ val sorted = selectedIndices.length > 1 && selectedIndices.sliding(2).forall(t => t(1) > t(0))
Review comment:
> just 'remember' internally whether it is sorted.
I am not sure, but if we want to make it 'remember' internally whether it is sorted, I guess we need to add a new class `VectorSlicer(val indices: Array[Int]) { def slice(vec: Vector): Vector }`
Currently, `slice` is just a method of `SparseVector`, we may not make each `SparseVector` remember this sortedness?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org