Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/7972#discussion_r36363088
--- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala
---
@@ -766,6 +767,28 @@ class SparseVector(
maxIdx
}
}
+
+ /**
+ * Create a slice of this vector based on the given indices.
+ * @param selectedIndices Sorted list of indices into the vector. This
does NOT do bound checking.
+ * @return New SparseVector with values in the order specified by the
given indices.
+ *
+ * NOTE: The API needs to be discussed before making this public.
+ */
+ private[spark] def slice(selectedIndices: Array[Int]): SparseVector = {
+ var currentIdx = 0
+ val (sliceInds, sliceVals) = selectedIndices.flatMap { origIdx =>
--- End diff --
Also leave a TODO to optimize the implementation. If we assume input
indices are ordered (or sort it), then this should be a merge intersection.
---
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]