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

    https://github.com/apache/spark/pull/5872#discussion_r29812034
  
    --- Diff: python/pyspark/mllib/linalg.py ---
    @@ -387,8 +415,50 @@ def __init__(self, size, *args):
                     if self.indices[i] >= self.indices[i + 1]:
                         raise TypeError("indices array must be sorted")
     
    +    def numNonzeros(self):
    +        return np.count_nonzero(self.values)
    +
    +    def norm(self, p):
    +        """
    +        Calculte the norm of a SparseVector.
    +
    +        >>> a = SparseVector(4, [0, 1], [3., -4.])
    +        >>> a.norm(1)
    +        7.0
    +        >>> a.norm(2)
    +        5.0
    +        """
    +        return np.linalg.norm(self.values, p)
    +
         def __reduce__(self):
    -        return (SparseVector, (self.size, self.indices.tostring(), 
self.values.tostring()))
    +        return (
    +            SparseVector,
    +            (self.size, self.indices.tostring(), self.values.tostring()))
    +
    +    @staticmethod
    +    def parse(vectorString):
    --- End diff --
    
    parse() needs to print out error messages upon failed parses; please see 
the Scala version, which prints the full line which failed to parse.
    
    Can the argument please be "s" to match Scala?


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