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

    https://github.com/apache/spark/pull/3643#discussion_r21863318
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/util/MLUtils.scala ---
    @@ -264,6 +263,92 @@ object MLUtils {
         }
         Vectors.fromBreeze(vector1)
       }
    + 
    +  /**
    +   * Returns the squared distance between two Vectors.
    +   */
    +  private[util] def vectorSquaredDistance(v1: Vector, v2: Vector): Double 
= {
    +    var squaredDistance = 0.0
    +    (v1, v2) match { 
    +      case (v1: SparseVector, v2: SparseVector) =>
    +        val v1Values = v1.values
    +        val v1Indices = v1.indices
    +        val v2Values = v2.values
    +        val v2Indices = v2.indices
    +        val nnzv1 = v1Indices.size
    +        val nnzv2 = v2Indices.size
    +        
    +        var kv1 = 0
    +        var kv2 = 0
    +        var score = 0.0
    +        while (kv1 < nnzv1) {
    --- End diff --
    
    Is this loop logic correct?  What if v1 runs out of indices, but v2 has 
some left.  You'll need a check for this after the loop.  But a better way to 
write it might be to have the outer loop check ```kv1 < nnzv1 || kv2 < nnzv2``` 
and handle 1 non-zero index per iteration of the loop.  (That would also let 
you have only 1 line updating ```squaredDistance```


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

Reply via email to