You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by MechCoder <gi...@git.apache.org> on 2016/06/30 17:38:42 UTC

[GitHub] spark pull request #13997: [SPARK-16328][ML][MLLIB][PYSPARK] Add 'asML' and ...

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

    https://github.com/apache/spark/pull/13997#discussion_r69176457
  
    --- Diff: python/pyspark/mllib/linalg/__init__.py ---
    @@ -846,6 +890,33 @@ def dense(*elements):
             return DenseVector(elements)
     
         @staticmethod
    +    def fromML(vec):
    +        """
    +        Convert a vector from the new mllib-local representation.
    +        This does NOT copy the data; it copies references.
    +
    +        >>> mllibDV1 = Vectors.dense([1, 2, 3])
    +        >>> mlDV = newlinalg.Vectors.dense([1, 2, 3])
    +        >>> mllibDV2 = Vectors.fromML(mlDV)
    +        >>> mllibDV1 == mllibDV2
    +        True
    +        >>> mllibSV1 = Vectors.sparse(4, {1: 1.0, 3: 5.5})
    +        >>> mlSV = newlinalg.Vectors.sparse(4, {1: 1.0, 3: 5.5})
    +        >>> mllibSV2 = Vectors.fromML(mlSV)
    +        >>> mllibSV1 == mllibSV2
    +        True
    +
    +        :param vec: a :py:class:`pyspark.ml.linalg.Vector`
    +        :return: a :py:class:`pyspark.mllib.linalg.Vector`
    +        """
    +        if type(vec) == newlinalg.DenseVector:
    --- End diff --
    
    It's a common pythonic practise to use `isinstance` in such cases. If we inherit something from `DenseVector`, then this check will fail.


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

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