{"action":"created","comment":{"url":"https://api.github.com/repos/numpy/numpy/pulls/comments/109668262","pull_request_review_id":30778670,"id":109668262,"diff_hunk":"@@ -330,5 +333,121 @@ def test_stack():\n                         stack, [m, m])\n \n \n+class TestBlock(TestCase):\n+    def test_block_simple_row_wise(self):\n+        A = np.ones((2, 2))\n+        B = 2 * A\n+        desired = np.array([[1, 1, 2, 2],\n+                            [1, 1, 2, 2]])\n+        result = block([A, B])\n+        assert_equal(desired, result)\n+        # with tuples\n+        result = block((A, B))\n+        assert_equal(desired, result)\n+\n+    def test_block_simple_column_wise(self):\n+        A = np.ones((2, 2))\n+        B = 2 * A\n+        expected = np.array([[1, 1],\n+                             [1, 1],\n+                             [2, 2],\n+                             [2, 2]])\n+        result = block([[A], [B]])\n+        assert_equal(expected, result)\n+\n+    def test_block_with_1d_arrays_row_wise(self):\n+        # # # 1-D vectors are treated as row arrays\n+        a = np.array([1, 2, 3])\n+        b = np.array([2, 3, 4])\n+        expected = np.array([1, 2, 3, 2, 3, 4])\n+        result = block([a, b])\n+        assert_equal(expected, result)\n+\n+    def test_block_with_1d_arrays_multiple_rows(self):\n+        a = np.array([1, 2, 3])\n+        b = np.array([2, 3, 4])\n+        expected = np.array([[1, 2, 3, 2, 3, 4],\n+                             [1, 2, 3, 2, 3, 4]])\n+        result = block([[a, b], [a, b]])\n+        assert_equal(expected, result)\n+\n+    def test_block_with_1d_arrays_column_wise(self):\n+        # # # 1-D vectors are treated as row arrays\n+        a = np.array([1, 2, 3])\n+        b = np.array([2, 3, 4])\n+        expected = np.array([[1, 2, 3],\n+                             [2, 3, 4]])\n+        result = block([[a], [b]])\n+        assert_equal(expected, result)\n+\n+    def test_block_mixed_1d_and_2d(self):\n+        A = np.ones((2, 2))\n+        B = np.array([2, 2])\n+        result = block([[A], [B]])\n+        expected = np.array([[1, 1],\n+                             [1, 1],\n+                             [2, 2]])\n+        assert_equal(expected, result)\n+\n+    def test_block_complicated(self):\n+        # a bit more complicated\n+        One = np.array([[1, 1, 1]])\n+        Two = np.array([[2, 2, 2]])\n+        Three = np.array([[3, 3, 3, 3, 3, 3]])\n+        four = np.array([4, 4, 4, 4, 4, 4])\n+        five = np.array([5])\n+        six = np.array([6, 6, 6, 6, 6])\n+        Zeros = np.zeros((2, 6))\n+\n+        result = block([[One, Two],\n+                        Three,\n+                        four,\n+                        [five, six],\n+                        Zeros])\n+        expected = np.array([[1, 1, 1, 2, 2, 2],\n+                             [3, 3, 3, 3, 3, 3],\n+                             [4, 4, 4, 4, 4, 4],\n+                             [5, 6, 6, 6, 6, 6],\n+                             [0, 0, 0, 0, 0, 0],\n+                             [0, 0, 0, 0, 0, 0]])\n+        assert_equal(result, expected)\n+\n+        # additional [] around rows should not have any influence\n+        result = block([[One, Two],\n+                        Three,\n+                        [four],\n+                        [five, six],\n+                        Zeros])\n+        assert_equal(result, expected)\n+\n+        result = block([[One, Two],\n+                        [Three],\n+                        [four],\n+                        [five, six],\n+                        Zeros])\n+        assert_equal(result, expected)\n+\n+        result = block([[One, Two],\n+                        [Three],\n+                        [four],\n+                        [five, six],\n+                        [Zeros]])\n+        assert_equal(result, expected)\n+\n+    def test_block_with_mismatched_shape(self):\n+        a = np.array([0, 0])\n+        b = np.eye(2)\n+        assert_raises(ValueError, np.block, (a, b))\n+        assert_raises(ValueError, np.block, (b, a))\n+\n+    def test_no_lists(self):\n+        assert_equal(np.block(1),         np.array(1))\n+        assert_equal(np.block(np.eye(3)), np.eye(3))\n+\n+    def test_empty_input(self):\n+        assert_raises(ValueError, np.block, [])\n+        assert_raises(ValueError, np.block, [[]])\n+\n+","path":"numpy/core/tests/test_shape_base.py","position":138,"original_position":138,"commit_id":"180acd70ca31f15e42015b9faaaf223a5b8a4ee1","original_commit_id":"180acd70ca31f15e42015b9faaaf223a5b8a4ee1","user":{"login":"madphysicist","id":4617010,"avatar_url":"https://avatars2.githubusercontent.com/u/4617010?v=3","gravatar_id":"","url":"https://api.github.com/users/madphysicist","html_url":"https://github.com/madphysicist","followers_url":"https://api.github.com/users/madphysicist/followers","following_url":"https://api.github.com/users/madphysicist/following{/other_user}","gists_url":"https://api.github.com/users/madphysicist/gists{/gist_id}","starred_url":"https://api.github.com/users/madphysicist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/madphysicist/subscriptions","organizations_url":"https://api.github.com/users/madphysicist/orgs","repos_url":"https://api.github.com/users/madphysicist/repos","events_url":"https://api.github.com/users/madphysicist/events{/privacy}","received_events_url":"https://api.github.com/users/madphysicist/received_events","type":"User","site_admin":false},"body":"For good measure, I would recommend adding a 3D case, but there is no end to that rabbit hole, so maybe it's better to leave it out.","created_at":"2017-04-04T13:55:01Z","updated_at":"2017-04-04T14:04:08Z","html_url":"https://github.com/numpy/numpy/pull/8886#discussion_r109668262","pull_request_url":"https://api.github.com/repos/numpy/numpy/pulls/8886","_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments/109668262"},"html":{"href":"https://github.com/numpy/numpy/pull/8886#discussion_r109668262"},"pull_request":{"href":"https://api.github.com/repos/numpy/numpy/pulls/8886"}}},"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/8886","id":113910909,"html_url":"https://github.com/numpy/numpy/pull/8886","diff_url":"https://github.com/numpy/numpy/pull/8886.diff","patch_url":"https://github.com/numpy/numpy/pull/8886.patch","issue_url":"https://api.github.com/repos/numpy/numpy/issues/8886","number":8886,"state":"open","locked":false,"title":"ENH: add np.block to improve upon np.bmat","user":{"login":"eric-wieser","id":425260,"avatar_url":"https://avatars0.githubusercontent.com/u/425260?v=3","gravatar_id":"","url":"https://api.github.com/users/eric-wieser","html_url":"https://github.com/eric-wieser","followers_url":"https://api.github.com/users/eric-wieser/followers","following_url":"https://api.github.com/users/eric-wieser/following{/other_user}","gists_url":"https://api.github.com/users/eric-wieser/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-wieser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-wieser/subscriptions","organizations_url":"https://api.github.com/users/eric-wieser/orgs","repos_url":"https://api.github.com/users/eric-wieser/repos","events_url":"https://api.github.com/users/eric-wieser/events{/privacy}","received_events_url":"https://api.github.com/users/eric-wieser/received_events","type":"User","site_admin":false},"body":"This continues where #7768 left off (which continues where #5057 left off). The first commit is just a rebase of #7768 onto master, with the release notes moved to the latest release.\r\n\r\nChanges since then:\r\n* 2D arrays are not special. This does not auto-promote results to 2D.\r\n* Works for ND arrays\r\n* No longer accepts `*args`, for consistency with `stack` and `concatenate`\r\n\r\n\r\nThe semantics are essentially:\r\n1. Normalize the list of lists to be of uniform depth\r\n2. `reshape` all the list elements to be at least as many dimensions as the list depth (#7804 ?)\r\n3. `concatenate` from the innermost list to the outermost, working backwards from the last dimension - elements can have extra leading dimensions\r\n\r\nProposals that we should decide on before merging:\r\n* Make tuples forbidden, require that inputs be lists of lists\r\n* Require that list depth match explicitly: make `np.block([[a, b], c])` illegal, must be spelt `np.block([[a, b], [c]])` (currently these are equivalent - this change would make step 1 a check, not a normalization)\r\n\r\nEnhancements that could be made in future, but don't need to be in the initial version:\r\n* Extra leading dimensions are broadcast. With two stacks of arrays, `A.shape == (3, 1, 2, 2)`, `B.shape = (1, 4, 2, 2)`, should `np.block([A, B]).shape == (3,3,2,4)`? (currently: `ValueError`)\r\n* Preallocate the result array to save redundant copies","created_at":"2017-04-03T11:38:51Z","updated_at":"2017-04-04T14:04:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fd0bc058d2430360ecf669f55d16786d5cd93646","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/numpy/numpy/pulls/8886/commits","review_comments_url":"https://api.github.com/repos/numpy/numpy/pulls/8886/comments","review_comment_url":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/8886/comments","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/180acd70ca31f15e42015b9faaaf223a5b8a4ee1","head":{"label":"eric-wieser:np-block","ref":"np-block","sha":"180acd70ca31f15e42015b9faaaf223a5b8a4ee1","user":{"login":"eric-wieser","id":425260,"avatar_url":"https://avatars0.githubusercontent.com/u/425260?v=3","gravatar_id":"","url":"https://api.github.com/users/eric-wieser","html_url":"https://github.com/eric-wieser","followers_url":"https://api.github.com/users/eric-wieser/followers","following_url":"https://api.github.com/users/eric-wieser/following{/other_user}","gists_url":"https://api.github.com/users/eric-wieser/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-wieser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-wieser/subscriptions","organizations_url":"https://api.github.com/users/eric-wieser/orgs","repos_url":"https://api.github.com/users/eric-wieser/repos","events_url":"https://api.github.com/users/eric-wieser/events{/privacy}","received_events_url":"https://api.github.com/users/eric-wieser/received_events","type":"User","site_admin":false},"repo":{"id":57262933,"name":"numpy","full_name":"eric-wieser/numpy","owner":{"login":"eric-wieser","id":425260,"avatar_url":"https://avatars0.githubusercontent.com/u/425260?v=3","gravatar_id":"","url":"https://api.github.com/users/eric-wieser","html_url":"https://github.com/eric-wieser","followers_url":"https://api.github.com/users/eric-wieser/followers","following_url":"https://api.github.com/users/eric-wieser/following{/other_user}","gists_url":"https://api.github.com/users/eric-wieser/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-wieser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-wieser/subscriptions","organizations_url":"https://api.github.com/users/eric-wieser/orgs","repos_url":"https://api.github.com/users/eric-wieser/repos","events_url":"https://api.github.com/users/eric-wieser/events{/privacy}","received_events_url":"https://api.github.com/users/eric-wieser/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eric-wieser/numpy","description":"Numpy main repository","fork":true,"url":"https://api.github.com/repos/eric-wieser/numpy","forks_url":"https://api.github.com/repos/eric-wieser/numpy/forks","keys_url":"https://api.github.com/repos/eric-wieser/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eric-wieser/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eric-wieser/numpy/teams","hooks_url":"https://api.github.com/repos/eric-wieser/numpy/hooks","issue_events_url":"https://api.github.com/repos/eric-wieser/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/eric-wieser/numpy/events","assignees_url":"https://api.github.com/repos/eric-wieser/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/eric-wieser/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/eric-wieser/numpy/tags","blobs_url":"https://api.github.com/repos/eric-wieser/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eric-wieser/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eric-wieser/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/eric-wieser/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eric-wieser/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/eric-wieser/numpy/languages","stargazers_url":"https://api.github.com/repos/eric-wieser/numpy/stargazers","contributors_url":"https://api.github.com/repos/eric-wieser/numpy/contributors","subscribers_url":"https://api.github.com/repos/eric-wieser/numpy/subscribers","subscription_url":"https://api.github.com/repos/eric-wieser/numpy/subscription","commits_url":"https://api.github.com/repos/eric-wieser/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/eric-wieser/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/eric-wieser/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/eric-wieser/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/eric-wieser/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/eric-wieser/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eric-wieser/numpy/merges","archive_url":"https://api.github.com/repos/eric-wieser/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eric-wieser/numpy/downloads","issues_url":"https://api.github.com/repos/eric-wieser/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/eric-wieser/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/eric-wieser/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/eric-wieser/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eric-wieser/numpy/labels{/name}","releases_url":"https://api.github.com/repos/eric-wieser/numpy/releases{/id}","deployments_url":"https://api.github.com/repos/eric-wieser/numpy/deployments","created_at":"2016-04-28T02:09:21Z","updated_at":"2016-12-13T18:03:29Z","pushed_at":"2017-04-04T10:25:19Z","git_url":"git://github.com/eric-wieser/numpy.git","ssh_url":"git@github.com:eric-wieser/numpy.git","clone_url":"https://github.com/eric-wieser/numpy.git","svn_url":"https://github.com/eric-wieser/numpy","homepage":"http://www.numpy.org/","size":47590,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"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":"numpy:master","ref":"master","sha":"6e17c7247d3d68afc580be650fbbe6cba3cbe941","user":{"login":"numpy","id":288276,"avatar_url":"https://avatars1.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"repo":{"id":908607,"name":"numpy","full_name":"numpy/numpy","owner":{"login":"numpy","id":288276,"avatar_url":"https://avatars1.githubusercontent.com/u/288276?v=3","gravatar_id":"","url":"https://api.github.com/users/numpy","html_url":"https://github.com/numpy","followers_url":"https://api.github.com/users/numpy/followers","following_url":"https://api.github.com/users/numpy/following{/other_user}","gists_url":"https://api.github.com/users/numpy/gists{/gist_id}","starred_url":"https://api.github.com/users/numpy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numpy/subscriptions","organizations_url":"https://api.github.com/users/numpy/orgs","repos_url":"https://api.github.com/users/numpy/repos","events_url":"https://api.github.com/users/numpy/events{/privacy}","received_events_url":"https://api.github.com/users/numpy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numpy/numpy","description":"Numpy main repository","fork":false,"url":"https://api.github.com/repos/numpy/numpy","forks_url":"https://api.github.com/repos/numpy/numpy/forks","keys_url":"https://api.github.com/repos/numpy/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numpy/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numpy/numpy/teams","hooks_url":"https://api.github.com/repos/numpy/numpy/hooks","issue_events_url":"https://api.github.com/repos/numpy/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/numpy/numpy/events","assignees_url":"https://api.github.com/repos/numpy/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/numpy/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/numpy/numpy/tags","blobs_url":"https://api.github.com/repos/numpy/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numpy/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numpy/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/numpy/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/numpy/numpy/languages","stargazers_url":"https://api.github.com/repos/numpy/numpy/stargazers","contributors_url":"https://api.github.com/repos/numpy/numpy/contributors","subscribers_url":"https://api.github.com/repos/numpy/numpy/subscribers","subscription_url":"https://api.github.com/repos/numpy/numpy/subscription","commits_url":"https://api.github.com/repos/numpy/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/numpy/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/numpy/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/numpy/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/numpy/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/numpy/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numpy/numpy/merges","archive_url":"https://api.github.com/repos/numpy/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numpy/numpy/downloads","issues_url":"https://api.github.com/repos/numpy/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/numpy/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/numpy/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/numpy/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numpy/numpy/labels{/name}","releases_url":"https://api.github.com/repos/numpy/numpy/releases{/id}","deployments_url":"https://api.github.com/repos/numpy/numpy/deployments","created_at":"2010-09-13T23:02:39Z","updated_at":"2017-04-04T08:49:00Z","pushed_at":"2017-04-04T12:37:33Z","git_url":"git://github.com/numpy/numpy.git","ssh_url":"git@github.com:numpy/numpy.git","clone_url":"https://github.com/numpy/numpy.git","svn_url":"https://github.com/numpy/numpy","homepage":"http://www.numpy.org/","size":48749,"stargazers_count":4167,"watchers_count":4167,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1971,"mirror_url":null,"open_issues_count":1479,"forks":1971,"open_issues":1479,"watchers":4167,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/8886"},"html":{"href":"https://github.com/numpy/numpy/pull/8886"},"issue":{"href":"https://api.github.com/repos/numpy/numpy/issues/8886"},"comments":{"href":"https://api.github.com/repos/numpy/numpy/issues/8886/comments"},"review_comments":{"href":"https://api.github.com/repos/numpy/numpy/pulls/8886/comments"},"review_comment":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numpy/numpy/pulls/8886/commits"},"statuses":{"href":"https://api.github.com/repos/numpy/numpy/statuses/180acd70ca31f15e42015b9faaaf223a5b8a4ee1"}}}}
{"actor":{"display_login":"madphysicist"}}