{"action":"created","comment":{"url":"https://api.github.com/repos/numpy/numpy/pulls/comments/53454973","id":53454973,"diff_hunk":"@@ -222,6 +223,101 @@ def test_floor_division_complex(self):\n         assert_equal(y, [1.e+110, 0], err_msg=msg)\n \n \n+class TestRemainder(TestCase):\n+\n+    def test_remainder_basic(self):\n+        dt = np.typecodes['AllInteger'] + np.typecodes['Float']\n+        for dt1, dt2 in itertools.product(dt, dt):\n+            for sg1, sg2 in itertools.product((+1, -1), (+1, -1)):\n+                if sg1 == -1 and dt1 in np.typecodes['UnsignedInteger']:\n+                    continue\n+                if sg2 == -1 and dt2 in np.typecodes['UnsignedInteger']:\n+                    continue\n+                fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s'\n+                msg = fmt % (dt1, dt2, sg1, sg2)\n+                a = np.array(sg1*71, dtype=dt1)\n+                b = np.array(sg2*19, dtype=dt2)\n+                div = np.floor(a/b)\n+                rem = np.remainder(a, b)\n+                assert_allclose(div*b + rem, a, err_msg=msg)\n+                if sg2 == -1:\n+                    assert_(b < rem <= 0, msg)\n+                else:\n+                    assert_(b > rem >= 0, msg)\n+\n+    def test_float_remainder_exact(self):\n+        # test that float results are exact for small integers. This also\n+        # holds for the same integers scaled by powers of two.\n+        nlst = list(range(-127, 0))\n+        plst = list(range(1, 128))\n+        dividend = nlst + [0] + plst\n+        divisor = nlst + plst\n+        arg = list(itertools.product(dividend, divisor))\n+        tgt = list(divmod(*t) for t in arg)\n+\n+        a, b = np.array(arg, dtype=int).T\n+        # convert exact integer results from Python to float so that\n+        # signed zero can be used, it is checked.\n+        tgtdiv, tgtrem = np.array(tgt, dtype=float).T\n+        tgtdiv = np.where((tgtdiv == 0.0) & ((b < 0) ^ (a < 0)), -0.0, tgtdiv)\n+        tgtrem = np.where((tgtrem == 0.0) & (b < 0), -0.0, tgtrem)\n+\n+        for dt in np.typecodes['Float']:\n+            msg = 'dtype: %s' % (dt,)\n+            fa = a.astype(dt)\n+            fb = b.astype(dt)\n+            div = np.floor(fa/fb)\n+            rem = np.remainder(fa, fb)\n+            assert_equal(div, tgtdiv, err_msg=msg)\n+            assert_equal(rem, tgtrem, err_msg=msg)\n+\n+    def test_float_remainder_roundoff(self):\n+        # gh-6127\n+        dt = np.typecodes['Float']\n+        for dt1, dt2 in itertools.product(dt, dt):\n+            for sg1, sg2 in itertools.product((+1, -1), (+1, -1)):\n+                fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s'\n+                msg = fmt % (dt1, dt2, sg1, sg2)\n+                a = np.array(sg1*78*6e-8, dtype=dt1)\n+                b = np.array(sg2*6e-8, dtype=dt2)\n+                div = np.floor_divide(a, b)\n+                rem = np.remainder(a, b)\n+                assert_allclose(div*b + rem, a, err_msg=msg)","path":"numpy/core/tests/test_umath.py","position":71,"original_position":71,"commit_id":"bb05b602c1ccaee9f8b9790fc16de8e315d25853","original_commit_id":"dc9d6ed6872280e0637584355ae56ca63c419db9","user":{"login":"pv","id":35046,"avatar_url":"https://avatars.githubusercontent.com/u/35046?v=3","gravatar_id":"","url":"https://api.github.com/users/pv","html_url":"https://github.com/pv","followers_url":"https://api.github.com/users/pv/followers","following_url":"https://api.github.com/users/pv/following{/other_user}","gists_url":"https://api.github.com/users/pv/gists{/gist_id}","starred_url":"https://api.github.com/users/pv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pv/subscriptions","organizations_url":"https://api.github.com/users/pv/orgs","repos_url":"https://api.github.com/users/pv/repos","events_url":"https://api.github.com/users/pv/events{/privacy}","received_events_url":"https://api.github.com/users/pv/received_events","type":"User","site_admin":false},"body":"The test passes for me also with `assert_equal`.","created_at":"2016-02-19T12:27:47Z","updated_at":"2016-02-19T12:27:47Z","html_url":"https://github.com/numpy/numpy/pull/7258#discussion_r53454973","pull_request_url":"https://api.github.com/repos/numpy/numpy/pulls/7258","_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments/53454973"},"html":{"href":"https://github.com/numpy/numpy/pull/7258#discussion_r53454973"},"pull_request":{"href":"https://api.github.com/repos/numpy/numpy/pulls/7258"}}},"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/7258","id":59435664,"html_url":"https://github.com/numpy/numpy/pull/7258","diff_url":"https://github.com/numpy/numpy/pull/7258.diff","patch_url":"https://github.com/numpy/numpy/pull/7258.patch","issue_url":"https://api.github.com/repos/numpy/numpy/issues/7258","number":7258,"state":"open","locked":false,"title":"ENH: Make numpy floor_divide and remainder agree with Python `//` and `%`.","user":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"body":"This fixes the problems with divmod in #7224 and brings divmod for numpy float64 scalars and arrays into agreement with divmod for Python floats. Tests are added to enforce the new behavior and assures that the results for small integers scaled by powers of two are exact. \r\n\r\nToo keep the scalar and array math in sync, both the scalar math and loop code is based on a new `npy_divmod` function in `npy_math`.\r\n\r\nEDIT: I changed the name to `npy_divmod`.\r\n\r\ndivmod example, Python floats\r\n```\r\n    In [1]: a = 78 * 6e-8\r\n\r\n    In [2]: b = 6e-8\r\n\r\n    In [3]: divmod(a, b)\r\n    Out[3]: (77.0, 5.999999999999965e-08)\r\n```\r\nBefore this commit numpy float64 gave\r\n```\r\n    In [4]: divmod(float64(a), float64(b))\r\n    Out[4]: (78.0, 0.0)\r\n```\r\nAfter this commit numpy float64 gives\r\n```\r\n    In [4]: divmod(float64(a), float64(b))\r\n    Out[4]: (77.0, 5.9999999999999651e-08)\r\n```","created_at":"2016-02-16T02:27:25Z","updated_at":"2016-02-19T12:27:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ddc0210181f753ddbd67013988e87101156dc91c","assignee":null,"milestone":{"url":"https://api.github.com/repos/numpy/numpy/milestones/36","html_url":"https://github.com/numpy/numpy/milestones/1.11.0%20release","labels_url":"https://api.github.com/repos/numpy/numpy/milestones/36/labels","id":1094191,"number":36,"title":"1.11.0 release","description":"","creator":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":87,"state":"open","created_at":"2015-05-03T18:13:58Z","updated_at":"2016-02-19T04:34:14Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/numpy/numpy/pulls/7258/commits","review_comments_url":"https://api.github.com/repos/numpy/numpy/pulls/7258/comments","review_comment_url":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/7258/comments","statuses_url":"https://api.github.com/repos/numpy/numpy/statuses/bb05b602c1ccaee9f8b9790fc16de8e315d25853","head":{"label":"charris:python-compatible-floor_divide","ref":"python-compatible-floor_divide","sha":"bb05b602c1ccaee9f8b9790fc16de8e315d25853","user":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"repo":{"id":908701,"name":"numpy","full_name":"charris/numpy","owner":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/charris/numpy","description":"Fork of numpy/numpy","fork":true,"url":"https://api.github.com/repos/charris/numpy","forks_url":"https://api.github.com/repos/charris/numpy/forks","keys_url":"https://api.github.com/repos/charris/numpy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/charris/numpy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/charris/numpy/teams","hooks_url":"https://api.github.com/repos/charris/numpy/hooks","issue_events_url":"https://api.github.com/repos/charris/numpy/issues/events{/number}","events_url":"https://api.github.com/repos/charris/numpy/events","assignees_url":"https://api.github.com/repos/charris/numpy/assignees{/user}","branches_url":"https://api.github.com/repos/charris/numpy/branches{/branch}","tags_url":"https://api.github.com/repos/charris/numpy/tags","blobs_url":"https://api.github.com/repos/charris/numpy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/charris/numpy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/charris/numpy/git/refs{/sha}","trees_url":"https://api.github.com/repos/charris/numpy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/charris/numpy/statuses/{sha}","languages_url":"https://api.github.com/repos/charris/numpy/languages","stargazers_url":"https://api.github.com/repos/charris/numpy/stargazers","contributors_url":"https://api.github.com/repos/charris/numpy/contributors","subscribers_url":"https://api.github.com/repos/charris/numpy/subscribers","subscription_url":"https://api.github.com/repos/charris/numpy/subscription","commits_url":"https://api.github.com/repos/charris/numpy/commits{/sha}","git_commits_url":"https://api.github.com/repos/charris/numpy/git/commits{/sha}","comments_url":"https://api.github.com/repos/charris/numpy/comments{/number}","issue_comment_url":"https://api.github.com/repos/charris/numpy/issues/comments{/number}","contents_url":"https://api.github.com/repos/charris/numpy/contents/{+path}","compare_url":"https://api.github.com/repos/charris/numpy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/charris/numpy/merges","archive_url":"https://api.github.com/repos/charris/numpy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/charris/numpy/downloads","issues_url":"https://api.github.com/repos/charris/numpy/issues{/number}","pulls_url":"https://api.github.com/repos/charris/numpy/pulls{/number}","milestones_url":"https://api.github.com/repos/charris/numpy/milestones{/number}","notifications_url":"https://api.github.com/repos/charris/numpy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/charris/numpy/labels{/name}","releases_url":"https://api.github.com/repos/charris/numpy/releases{/id}","deployments_url":"https://api.github.com/repos/charris/numpy/deployments","created_at":"2010-09-13T23:57:46Z","updated_at":"2015-05-02T19:17:10Z","pushed_at":"2016-02-19T05:04:56Z","git_url":"git://github.com/charris/numpy.git","ssh_url":"git@github.com:charris/numpy.git","clone_url":"https://github.com/charris/numpy.git","svn_url":"https://github.com/charris/numpy","homepage":"","size":43024,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":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":1,"default_branch":"master"}},"base":{"label":"numpy:master","ref":"master","sha":"711b2a9ccfb54c09cdc483ee511035bda60f3f0b","user":{"login":"numpy","id":288276,"avatar_url":"https://avatars.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://avatars.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":"2016-02-19T09:57:19Z","pushed_at":"2016-02-19T08:28:40Z","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":64839,"stargazers_count":2642,"watchers_count":2642,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1370,"mirror_url":null,"open_issues_count":1141,"forks":1370,"open_issues":1141,"watchers":2642,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numpy/numpy/pulls/7258"},"html":{"href":"https://github.com/numpy/numpy/pull/7258"},"issue":{"href":"https://api.github.com/repos/numpy/numpy/issues/7258"},"comments":{"href":"https://api.github.com/repos/numpy/numpy/issues/7258/comments"},"review_comments":{"href":"https://api.github.com/repos/numpy/numpy/pulls/7258/comments"},"review_comment":{"href":"https://api.github.com/repos/numpy/numpy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numpy/numpy/pulls/7258/commits"},"statuses":{"href":"https://api.github.com/repos/numpy/numpy/statuses/bb05b602c1ccaee9f8b9790fc16de8e315d25853"}}}}