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 2019/07/18 19:31:36 UTC

[GitHub] [spark] kiszk commented on a change in pull request #25178: [SPARK-28421][ML] SparseVector.apply performance optimization

kiszk commented on a change in pull request #25178: [SPARK-28421][ML] SparseVector.apply performance optimization
URL: https://github.com/apache/spark/pull/25178#discussion_r305080682
 
 

 ##########
 File path: mllib-local/src/main/scala/org/apache/spark/ml/linalg/Vectors.scala
 ##########
 @@ -603,6 +603,19 @@ class SparseVector @Since("2.0.0") (
 
   private[spark] override def asBreeze: BV[Double] = new BSV[Double](indices, values, size)
 
+  override def apply(i: Int): Double = {
+    if (i < 0 || i >= size) {
+      throw new IndexOutOfBoundsException(s"Index $i out of bounds [0, $size)")
+    }
+
+    if (indices.isEmpty || i < indices(0) || i > indices(indices.length - 1)) {
 
 Review comment:
   I see. This performance improvement comes from avoiding to walk a binary tree if a `key` is not included in a given sorted array. It makes sense to me .
   
   One question. What do you mean `avoiding internal conversion` in the description?

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org