Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/3791#discussion_r22257875
--- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala
---
@@ -173,11 +173,13 @@ object Vectors {
* Creates a sparse vector providing its index array and value array.
*
* @param size vector size.
- * @param indices index array, must be strictly increasing.
- * @param values value array, must have the same length as indices.
+ * @param indices index array.
+ * @param values value array.
*/
- def sparse(size: Int, indices: Array[Int], values: Array[Double]):
Vector =
- new SparseVector(size, indices, values)
+ def sparse(size: Int, indices: Array[Int], values: Array[Double]):
Vector = {
+ val (newIndices, newValues) = indices.zip(values).sortBy(_._1).unzip
--- End diff --
This is non-trivial overhead to introduce every time a vector is made, when
the common case is that the indices are sorted, and the other cases are really
caller error. I'd still suggest merely checking the sorting. There are lots of
one-liners but this may be among the most efficient `require((1 until
indices.length).forall(i => indices(i-1) <= indices(i)))`
---
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]