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

    https://github.com/apache/spark/pull/7854#discussion_r37828718
  
    --- Diff: python/pyspark/mllib/linalg/__init__.py ---
    @@ -461,32 +461,41 @@ def __init__(self, size, *args):
             self.size = int(size)
             """ Size of the vector. """
             assert 1 <= len(args) <= 2, "must pass either 2 or 3 arguments"
    -        if len(args) == 1:
    -            pairs = args[0]
    -            if type(pairs) == dict:
    -                pairs = pairs.items()
    -            pairs = sorted(pairs)
    -            self.indices = np.array([p[0] for p in pairs], dtype=np.int32)
    -            """ A list of indices corresponding to active entries. """
    -            self.values = np.array([p[1] for p in pairs], dtype=np.float64)
    -            """ A list of values corresponding to active entries. """
    +        if isinstance(args[0], bytes):
    +            assert isinstance(args[1], bytes), "values should be string 
too"
    +            if args[0]:
    +                self.indices = np.frombuffer(args[0], np.int32)
    +                self.values = np.frombuffer(args[1], np.float64)
    +            else:
    +                # np.frombuffer() doesn't work well with empty string in 
older version
    +                self.indices = np.array([], dtype=np.int32)
    +                self.values = np.array([], dtype=np.float64)
             else:
    -            if isinstance(args[0], bytes):
    -                assert isinstance(args[1], bytes), "values should be 
string too"
    -                if args[0]:
    -                    self.indices = np.frombuffer(args[0], np.int32)
    -                    self.values = np.frombuffer(args[1], np.float64)
    -                else:
    -                    # np.frombuffer() doesn't work well with empty string 
in older version
    -                    self.indices = np.array([], dtype=np.int32)
    -                    self.values = np.array([], dtype=np.float64)
    +            if len(args) == 1:
    +                args = args[0]
    +                if isinstance(args, dict):
    +                    args = args.items()
    +                args = list(zip(*args))
    +
    +            # Handle empty args case.
    +            if len(args) == 0:
    --- End diff --
    
    `lens(args)` will never be zero because of L463


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