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

    https://github.com/apache/spark/pull/8166#discussion_r37781102
  
    --- Diff: python/pyspark/mllib/linalg/__init__.py ---
    @@ -841,6 +930,41 @@ def parse(s):
         def zeros(size):
             return DenseVector(np.zeros(size))
     
    +    @staticmethod
    +    def equals(v1_indices, v1_values, v2_indices, v2_values):
    +        """
    +        Check equality between sparse/dense vectors
    +
    +        >>> indices = [1, 2, 4]
    +        >>> values = [1., 3., 2.]
    +        >>> Vectors.equals(indices, values, list(range(5)), [0., 1., 3., 
0., 2.])
    +        True
    +        >>> Vectors.equals(indices, values, list(range(5)), [0., 3., 1., 
0., 2.])
    +        False
    +        >>> Vectors.equals(indices, values, list(range(5)), [0., 3., 0., 
2.])
    +        False
    +        >>> Vectors.equals(indices, values, list(range(5)), [0., 1., 3., 
2., 2.])
    +        False
    +        """
    +        v1_size = len(v1_values)
    +        v2_size = len(v2_values)
    +        k1 = 0
    +        k2 = 0
    +        all_equal = True
    +        while all_equal:
    +            while k1 < v1_size and v1_values[k1] == 0:
    +                k1 += 1
    +            while k2 < v2_size and v2_values[k2] == 0:
    +                k2 += 1
    +
    +            if k1 >= v1_size or k2 >= v2_size:
    --- End diff --
    
    nit: since `k1` will be at most `== v1_size` due to the earlier `while`, 
checking for `==` here will suffice and is easier to read


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

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

Reply via email to