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

    https://github.com/apache/spark/pull/661#discussion_r12311565
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala 
---
    @@ -136,7 +136,7 @@ object Vectors {
               new DenseVector(v.toArray)  // Can't use underlying array 
directly, so make a new one
             }
           case v: BSV[Double] =>
    -        new SparseVector(v.length, v.index, v.data)
    +        new SparseVector(v.length, v.index.slice(0, v.used), 
v.data.slice(0, v.used))
    --- End diff --
    
    That makes sense. And I just found that it failed the test "Should not copy 
data".  SparseVector from VectorBuilder has this problem of size inconsistency. 
It uses a dynamic growing approach to resize the index/data array and fills the 
unused slot zeros. So I think there is no way to completely avoid new 
allocation. 


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to