{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/37825862","id":37825862,"diff_hunk":"@@ -461,32 +461,41 @@ def __init__(self, size, *args):\n         self.size = int(size)\n         \"\"\" Size of the vector. \"\"\"\n         assert 1 <= len(args) <= 2, \"must pass either 2 or 3 arguments\"\n-        if len(args) == 1:\n-            pairs = args[0]\n-            if type(pairs) == dict:\n-                pairs = pairs.items()\n-            pairs = sorted(pairs)\n-            self.indices = np.array([p[0] for p in pairs], dtype=np.int32)\n-            \"\"\" A list of indices corresponding to active entries. \"\"\"\n-            self.values = np.array([p[1] for p in pairs], dtype=np.float64)\n-            \"\"\" A list of values corresponding to active entries. \"\"\"\n+        if isinstance(args[0], bytes):\n+            assert isinstance(args[1], bytes), \"values should be string too\"\n+            if args[0]:\n+                self.indices = np.frombuffer(args[0], np.int32)\n+                self.values = np.frombuffer(args[1], np.float64)\n+            else:\n+                # np.frombuffer() doesn't work well with empty string in older version\n+                self.indices = np.array([], dtype=np.int32)\n+                self.values = np.array([], dtype=np.float64)\n         else:\n-            if isinstance(args[0], bytes):\n-                assert isinstance(args[1], bytes), \"values should be string too\"\n-                if args[0]:\n-                    self.indices = np.frombuffer(args[0], np.int32)\n-                    self.values = np.frombuffer(args[1], np.float64)\n-                else:\n-                    # np.frombuffer() doesn't work well with empty string in older version\n-                    self.indices = np.array([], dtype=np.int32)\n-                    self.values = np.array([], dtype=np.float64)\n+            if len(args) == 1:\n+                args = args[0]\n+                if isinstance(args, dict):\n+                    args = args.items()\n+                args = list(zip(*args))\n+\n+            # Handle empty args case.\n+            if len(args) == 0:","path":"python/pyspark/mllib/linalg/__init__.py","position":39,"original_position":39,"commit_id":"f173c16b6dbc29175c93f39f3bff8410ff5ed906","original_commit_id":"f173c16b6dbc29175c93f39f3bff8410ff5ed906","user":{"login":"feynmanliang","id":990069,"avatar_url":"https://avatars.githubusercontent.com/u/990069?v=3","gravatar_id":"","url":"https://api.github.com/users/feynmanliang","html_url":"https://github.com/feynmanliang","followers_url":"https://api.github.com/users/feynmanliang/followers","following_url":"https://api.github.com/users/feynmanliang/following{/other_user}","gists_url":"https://api.github.com/users/feynmanliang/gists{/gist_id}","starred_url":"https://api.github.com/users/feynmanliang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feynmanliang/subscriptions","organizations_url":"https://api.github.com/users/feynmanliang/orgs","repos_url":"https://api.github.com/users/feynmanliang/repos","events_url":"https://api.github.com/users/feynmanliang/events{/privacy}","received_events_url":"https://api.github.com/users/feynmanliang/received_events","type":"User","site_admin":false},"body":"This is unnecessary since L463 checks that len(args) >= 1","created_at":"2015-08-25T01:56:15Z","updated_at":"2015-08-25T01:56:15Z","html_url":"https://github.com/apache/spark/pull/7854#discussion_r37825862","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/7854","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/37825862"},"html":{"href":"https://github.com/apache/spark/pull/7854#discussion_r37825862"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/7854"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/7854","id":41403154,"html_url":"https://github.com/apache/spark/pull/7854","diff_url":"https://github.com/apache/spark/pull/7854.diff","patch_url":"https://github.com/apache/spark/pull/7854.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/7854","number":7854,"state":"open","locked":false,"title":"[SPARK-9525] [PySpark] [MLlib] Optimize SparseVector initialization","user":{"login":"MechCoder","id":1867024,"avatar_url":"https://avatars.githubusercontent.com/u/1867024?v=3","gravatar_id":"","url":"https://api.github.com/users/MechCoder","html_url":"https://github.com/MechCoder","followers_url":"https://api.github.com/users/MechCoder/followers","following_url":"https://api.github.com/users/MechCoder/following{/other_user}","gists_url":"https://api.github.com/users/MechCoder/gists{/gist_id}","starred_url":"https://api.github.com/users/MechCoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MechCoder/subscriptions","organizations_url":"https://api.github.com/users/MechCoder/orgs","repos_url":"https://api.github.com/users/MechCoder/repos","events_url":"https://api.github.com/users/MechCoder/events{/privacy}","received_events_url":"https://api.github.com/users/MechCoder/received_events","type":"User","site_admin":false},"body":"1. Remove sorting of indices and assume that the user gives a sorted tuple of indices, values etc\r\n\r\n2. Avoid iterating twice to get the indices and values if the argument provided is a dict.\r\n\r\n3. Add checks such that the length of the indices should be less than the size provided.\r\n","created_at":"2015-08-01T15:28:45Z","updated_at":"2015-08-25T01:56:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1112f11d9fdab10fb90aaafcc5f92d63ab94b9a9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/7854/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/7854/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/7854/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/f173c16b6dbc29175c93f39f3bff8410ff5ed906","head":{"label":"MechCoder:init_sparse","ref":"init_sparse","sha":"f173c16b6dbc29175c93f39f3bff8410ff5ed906","user":{"login":"MechCoder","id":1867024,"avatar_url":"https://avatars.githubusercontent.com/u/1867024?v=3","gravatar_id":"","url":"https://api.github.com/users/MechCoder","html_url":"https://github.com/MechCoder","followers_url":"https://api.github.com/users/MechCoder/followers","following_url":"https://api.github.com/users/MechCoder/following{/other_user}","gists_url":"https://api.github.com/users/MechCoder/gists{/gist_id}","starred_url":"https://api.github.com/users/MechCoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MechCoder/subscriptions","organizations_url":"https://api.github.com/users/MechCoder/orgs","repos_url":"https://api.github.com/users/MechCoder/repos","events_url":"https://api.github.com/users/MechCoder/events{/privacy}","received_events_url":"https://api.github.com/users/MechCoder/received_events","type":"User","site_admin":false},"repo":{"id":23950071,"name":"spark","full_name":"MechCoder/spark","owner":{"login":"MechCoder","id":1867024,"avatar_url":"https://avatars.githubusercontent.com/u/1867024?v=3","gravatar_id":"","url":"https://api.github.com/users/MechCoder","html_url":"https://github.com/MechCoder","followers_url":"https://api.github.com/users/MechCoder/followers","following_url":"https://api.github.com/users/MechCoder/following{/other_user}","gists_url":"https://api.github.com/users/MechCoder/gists{/gist_id}","starred_url":"https://api.github.com/users/MechCoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MechCoder/subscriptions","organizations_url":"https://api.github.com/users/MechCoder/orgs","repos_url":"https://api.github.com/users/MechCoder/repos","events_url":"https://api.github.com/users/MechCoder/events{/privacy}","received_events_url":"https://api.github.com/users/MechCoder/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MechCoder/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/MechCoder/spark","forks_url":"https://api.github.com/repos/MechCoder/spark/forks","keys_url":"https://api.github.com/repos/MechCoder/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MechCoder/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MechCoder/spark/teams","hooks_url":"https://api.github.com/repos/MechCoder/spark/hooks","issue_events_url":"https://api.github.com/repos/MechCoder/spark/issues/events{/number}","events_url":"https://api.github.com/repos/MechCoder/spark/events","assignees_url":"https://api.github.com/repos/MechCoder/spark/assignees{/user}","branches_url":"https://api.github.com/repos/MechCoder/spark/branches{/branch}","tags_url":"https://api.github.com/repos/MechCoder/spark/tags","blobs_url":"https://api.github.com/repos/MechCoder/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MechCoder/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MechCoder/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/MechCoder/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MechCoder/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/MechCoder/spark/languages","stargazers_url":"https://api.github.com/repos/MechCoder/spark/stargazers","contributors_url":"https://api.github.com/repos/MechCoder/spark/contributors","subscribers_url":"https://api.github.com/repos/MechCoder/spark/subscribers","subscription_url":"https://api.github.com/repos/MechCoder/spark/subscription","commits_url":"https://api.github.com/repos/MechCoder/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/MechCoder/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/MechCoder/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/MechCoder/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/MechCoder/spark/contents/{+path}","compare_url":"https://api.github.com/repos/MechCoder/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MechCoder/spark/merges","archive_url":"https://api.github.com/repos/MechCoder/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MechCoder/spark/downloads","issues_url":"https://api.github.com/repos/MechCoder/spark/issues{/number}","pulls_url":"https://api.github.com/repos/MechCoder/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/MechCoder/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/MechCoder/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MechCoder/spark/labels{/name}","releases_url":"https://api.github.com/repos/MechCoder/spark/releases{/id}","created_at":"2014-09-12T06:52:44Z","updated_at":"2015-05-08T08:12:17Z","pushed_at":"2015-08-22T04:34:04Z","git_url":"git://github.com/MechCoder/spark.git","ssh_url":"git@github.com:MechCoder/spark.git","clone_url":"https://github.com/MechCoder/spark.git","svn_url":"https://github.com/MechCoder/spark","homepage":null,"size":115915,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"8765665015ef47a23e00f7d01d4d280c31bb236d","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-08-25T01:51:26Z","pushed_at":"2015-08-25T01:44:34Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1671125,"stargazers_count":5174,"watchers_count":5174,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4749,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":358,"forks":4749,"open_issues":358,"watchers":5174,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/7854"},"html":{"href":"https://github.com/apache/spark/pull/7854"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/7854"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/7854/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/7854/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/7854/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/f173c16b6dbc29175c93f39f3bff8410ff5ed906"}}}}