Return-Path: X-Original-To: apmail-spark-reviews-archive@minotaur.apache.org Delivered-To: apmail-spark-reviews-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 10A4C18077 for ; Fri, 11 Sep 2015 01:30:49 +0000 (UTC) Received: (qmail 64434 invoked by uid 500); 11 Sep 2015 01:30:49 -0000 Delivered-To: apmail-spark-reviews-archive@spark.apache.org Received: (qmail 64414 invoked by uid 500); 11 Sep 2015 01:30:49 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 64402 invoked by uid 99); 11 Sep 2015 01:30:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Sep 2015 01:30:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8FAF7E1082; Fri, 11 Sep 2015 01:30:48 +0000 (UTC) From: MechCoder To: reviews@spark.apache.org Reply-To: reviews@spark.apache.org References: In-Reply-To: Subject: [GitHub] spark pull request: [SPARK-9525] [PySpark] [MLlib] Optimize Sparse... Content-Type: text/plain Message-Id: <20150911013048.8FAF7E1082@git1-us-west.apache.org> Date: Fri, 11 Sep 2015 01:30:48 +0000 (UTC) Github user MechCoder commented on a diff in the pull request: https://github.com/apache/spark/pull/7854#discussion_r39233952 --- 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: + indices = [] + values = [] else: - self.indices = np.array(args[0], dtype=np.int32) - self.values = np.array(args[1], dtype=np.float64) - assert len(self.indices) == len(self.values), "index and value arrays not same length" - for i in xrange(len(self.indices) - 1): - if self.indices[i] >= self.indices[i + 1]: - raise TypeError("indices array must be sorted") --- End diff -- hey, I'll update it definitely in a while (I sent you a mail regarding how much time I would be able to allocate from now on) --- 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