{"action":"created","comment":{"url":"https://api.github.com/repos/chainer/chainer/pulls/comments/151300593","pull_request_review_id":76986145,"id":151300593,"diff_hunk":"@@ -18,34 +19,49 @@ def check_type_forward(self, in_types):\n         )\n \n     def forward_cpu(self, inputs):\n+        self.retain_inputs((0, 1))\n         x1, x2 = inputs\n         y = numpy.maximum(x1, x2)\n         return utils.force_array(y),\n \n-    def backward_cpu(self, inputs, grads):\n-        x1, x2 = inputs\n-        gy, = grads\n-        gx1 = gy * (x1 >= x2)\n-        gx2 = gy * (x1 < x2)\n-        return utils.force_array(gx1), utils.force_array(gx2)\n-\n     def forward_gpu(self, inputs):\n+        self.retain_inputs((0, 1))\n         x1, x2 = inputs\n         return cuda.cupy.maximum(x1, x2),\n \n-    def backward_gpu(self, inputs, grads):\n-        x1, x2 = inputs\n-        gy, = grads\n+    def backward(self, indexes, grad_outputs):\n+        x1, x2 = self.get_retained_inputs()\n+        return MaximumGrad(\n+            utils.force_array(x1.data >= x2.data)).apply((grad_outputs[0],))\n+\n+\n+class MaximumGrad(function_node.FunctionNode):\n+\n+    def __init__(self, cond):\n+        self.cond = cond\n+\n+    def forward_cpu(self, inputs):\n+        gy, = inputs\n+        gx1 = numpy.where(self.cond, gy, gy.dtype.type(0))\n+        gx2 = numpy.where(self.cond, gy.dtype.type(0), gy)\n+        return utils.force_array(gx1), utils.force_array(gx2)\n+\n+    def forward_gpu(self, inputs):\n+        gy, = inputs\n         gx1 = cuda.elementwise(\n-            'T x1, T x2, T gy', 'T gx1',\n-            'gx1 = (x1 >= x2) ? gy : (T)0.0',\n-            'maximum_bwd1')(x1, x2, gy)\n+            'S cond, T gy', 'T gx1',","path":"chainer/functions/math/maximum.py","position":null,"original_position":63,"commit_id":"c2ea66556d52513c087f31401aacee907b2a6742","original_commit_id":"16d42dd8cf08694965eba4bb606e68aa34ec1157","user":{"login":"kmaehashi","id":939877,"avatar_url":"https://avatars0.githubusercontent.com/u/939877?v=4","gravatar_id":"","url":"https://api.github.com/users/kmaehashi","html_url":"https://github.com/kmaehashi","followers_url":"https://api.github.com/users/kmaehashi/followers","following_url":"https://api.github.com/users/kmaehashi/following{/other_user}","gists_url":"https://api.github.com/users/kmaehashi/gists{/gist_id}","starred_url":"https://api.github.com/users/kmaehashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmaehashi/subscriptions","organizations_url":"https://api.github.com/users/kmaehashi/orgs","repos_url":"https://api.github.com/users/kmaehashi/repos","events_url":"https://api.github.com/users/kmaehashi/events{/privacy}","received_events_url":"https://api.github.com/users/kmaehashi/received_events","type":"User","site_admin":false},"body":"Thanks! Fixed as suggested.","created_at":"2017-11-16T01:26:34Z","updated_at":"2017-11-16T01:26:34Z","html_url":"https://github.com/chainer/chainer/pull/3533#discussion_r151300593","pull_request_url":"https://api.github.com/repos/chainer/chainer/pulls/3533","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/chainer/chainer/pulls/comments/151300593"},"html":{"href":"https://github.com/chainer/chainer/pull/3533#discussion_r151300593"},"pull_request":{"href":"https://api.github.com/repos/chainer/chainer/pulls/3533"}},"in_reply_to_id":151165398},"pull_request":{"url":"https://api.github.com/repos/chainer/chainer/pulls/3533","id":145623006,"html_url":"https://github.com/chainer/chainer/pull/3533","diff_url":"https://github.com/chainer/chainer/pull/3533.diff","patch_url":"https://github.com/chainer/chainer/pull/3533.patch","issue_url":"https://api.github.com/repos/chainer/chainer/issues/3533","number":3533,"state":"open","locked":false,"title":"new style maximum function","user":{"login":"kmaehashi","id":939877,"avatar_url":"https://avatars0.githubusercontent.com/u/939877?v=4","gravatar_id":"","url":"https://api.github.com/users/kmaehashi","html_url":"https://github.com/kmaehashi","followers_url":"https://api.github.com/users/kmaehashi/followers","following_url":"https://api.github.com/users/kmaehashi/following{/other_user}","gists_url":"https://api.github.com/users/kmaehashi/gists{/gist_id}","starred_url":"https://api.github.com/users/kmaehashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmaehashi/subscriptions","organizations_url":"https://api.github.com/users/kmaehashi/orgs","repos_url":"https://api.github.com/users/kmaehashi/repos","events_url":"https://api.github.com/users/kmaehashi/events{/privacy}","received_events_url":"https://api.github.com/users/kmaehashi/received_events","type":"User","site_admin":false},"body":"This PR implements new style `maximum` function.","created_at":"2017-10-10T08:02:38Z","updated_at":"2017-11-16T01:26:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"084af25a300893e6c618c61bd8ce376da69d5ae7","assignee":{"login":"takagi","id":1224375,"avatar_url":"https://avatars3.githubusercontent.com/u/1224375?v=4","gravatar_id":"","url":"https://api.github.com/users/takagi","html_url":"https://github.com/takagi","followers_url":"https://api.github.com/users/takagi/followers","following_url":"https://api.github.com/users/takagi/following{/other_user}","gists_url":"https://api.github.com/users/takagi/gists{/gist_id}","starred_url":"https://api.github.com/users/takagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takagi/subscriptions","organizations_url":"https://api.github.com/users/takagi/orgs","repos_url":"https://api.github.com/users/takagi/repos","events_url":"https://api.github.com/users/takagi/events{/privacy}","received_events_url":"https://api.github.com/users/takagi/received_events","type":"User","site_admin":false},"assignees":[{"login":"takagi","id":1224375,"avatar_url":"https://avatars3.githubusercontent.com/u/1224375?v=4","gravatar_id":"","url":"https://api.github.com/users/takagi","html_url":"https://github.com/takagi","followers_url":"https://api.github.com/users/takagi/followers","following_url":"https://api.github.com/users/takagi/following{/other_user}","gists_url":"https://api.github.com/users/takagi/gists{/gist_id}","starred_url":"https://api.github.com/users/takagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/takagi/subscriptions","organizations_url":"https://api.github.com/users/takagi/orgs","repos_url":"https://api.github.com/users/takagi/repos","events_url":"https://api.github.com/users/takagi/events{/privacy}","received_events_url":"https://api.github.com/users/takagi/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/chainer/chainer/pulls/3533/commits","review_comments_url":"https://api.github.com/repos/chainer/chainer/pulls/3533/comments","review_comment_url":"https://api.github.com/repos/chainer/chainer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chainer/chainer/issues/3533/comments","statuses_url":"https://api.github.com/repos/chainer/chainer/statuses/c2ea66556d52513c087f31401aacee907b2a6742","head":{"label":"kmaehashi:new-style-maximum","ref":"new-style-maximum","sha":"c2ea66556d52513c087f31401aacee907b2a6742","user":{"login":"kmaehashi","id":939877,"avatar_url":"https://avatars0.githubusercontent.com/u/939877?v=4","gravatar_id":"","url":"https://api.github.com/users/kmaehashi","html_url":"https://github.com/kmaehashi","followers_url":"https://api.github.com/users/kmaehashi/followers","following_url":"https://api.github.com/users/kmaehashi/following{/other_user}","gists_url":"https://api.github.com/users/kmaehashi/gists{/gist_id}","starred_url":"https://api.github.com/users/kmaehashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmaehashi/subscriptions","organizations_url":"https://api.github.com/users/kmaehashi/orgs","repos_url":"https://api.github.com/users/kmaehashi/repos","events_url":"https://api.github.com/users/kmaehashi/events{/privacy}","received_events_url":"https://api.github.com/users/kmaehashi/received_events","type":"User","site_admin":false},"repo":{"id":105627174,"name":"chainer","full_name":"kmaehashi/chainer","owner":{"login":"kmaehashi","id":939877,"avatar_url":"https://avatars0.githubusercontent.com/u/939877?v=4","gravatar_id":"","url":"https://api.github.com/users/kmaehashi","html_url":"https://github.com/kmaehashi","followers_url":"https://api.github.com/users/kmaehashi/followers","following_url":"https://api.github.com/users/kmaehashi/following{/other_user}","gists_url":"https://api.github.com/users/kmaehashi/gists{/gist_id}","starred_url":"https://api.github.com/users/kmaehashi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmaehashi/subscriptions","organizations_url":"https://api.github.com/users/kmaehashi/orgs","repos_url":"https://api.github.com/users/kmaehashi/repos","events_url":"https://api.github.com/users/kmaehashi/events{/privacy}","received_events_url":"https://api.github.com/users/kmaehashi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kmaehashi/chainer","description":"A flexible framework of neural networks for deep learning","fork":true,"url":"https://api.github.com/repos/kmaehashi/chainer","forks_url":"https://api.github.com/repos/kmaehashi/chainer/forks","keys_url":"https://api.github.com/repos/kmaehashi/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kmaehashi/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kmaehashi/chainer/teams","hooks_url":"https://api.github.com/repos/kmaehashi/chainer/hooks","issue_events_url":"https://api.github.com/repos/kmaehashi/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/kmaehashi/chainer/events","assignees_url":"https://api.github.com/repos/kmaehashi/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/kmaehashi/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/kmaehashi/chainer/tags","blobs_url":"https://api.github.com/repos/kmaehashi/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kmaehashi/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kmaehashi/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/kmaehashi/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kmaehashi/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/kmaehashi/chainer/languages","stargazers_url":"https://api.github.com/repos/kmaehashi/chainer/stargazers","contributors_url":"https://api.github.com/repos/kmaehashi/chainer/contributors","subscribers_url":"https://api.github.com/repos/kmaehashi/chainer/subscribers","subscription_url":"https://api.github.com/repos/kmaehashi/chainer/subscription","commits_url":"https://api.github.com/repos/kmaehashi/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/kmaehashi/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/kmaehashi/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/kmaehashi/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/kmaehashi/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/kmaehashi/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kmaehashi/chainer/merges","archive_url":"https://api.github.com/repos/kmaehashi/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kmaehashi/chainer/downloads","issues_url":"https://api.github.com/repos/kmaehashi/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/kmaehashi/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/kmaehashi/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/kmaehashi/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kmaehashi/chainer/labels{/name}","releases_url":"https://api.github.com/repos/kmaehashi/chainer/releases{/id}","deployments_url":"https://api.github.com/repos/kmaehashi/chainer/deployments","created_at":"2017-10-03T07:55:58Z","updated_at":"2017-10-03T07:56:03Z","pushed_at":"2017-11-16T01:26:16Z","git_url":"git://github.com/kmaehashi/chainer.git","ssh_url":"git@github.com:kmaehashi/chainer.git","clone_url":"https://github.com/kmaehashi/chainer.git","svn_url":"https://github.com/kmaehashi/chainer","homepage":"https://chainer.org","size":18638,"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,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"chainer:master","ref":"master","sha":"ff3e815bcb2a540dbaab862b5d7efa09a2484a81","user":{"login":"chainer","id":23183003,"avatar_url":"https://avatars3.githubusercontent.com/u/23183003?v=4","gravatar_id":"","url":"https://api.github.com/users/chainer","html_url":"https://github.com/chainer","followers_url":"https://api.github.com/users/chainer/followers","following_url":"https://api.github.com/users/chainer/following{/other_user}","gists_url":"https://api.github.com/users/chainer/gists{/gist_id}","starred_url":"https://api.github.com/users/chainer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chainer/subscriptions","organizations_url":"https://api.github.com/users/chainer/orgs","repos_url":"https://api.github.com/users/chainer/repos","events_url":"https://api.github.com/users/chainer/events{/privacy}","received_events_url":"https://api.github.com/users/chainer/received_events","type":"Organization","site_admin":false},"repo":{"id":36914478,"name":"chainer","full_name":"chainer/chainer","owner":{"login":"chainer","id":23183003,"avatar_url":"https://avatars3.githubusercontent.com/u/23183003?v=4","gravatar_id":"","url":"https://api.github.com/users/chainer","html_url":"https://github.com/chainer","followers_url":"https://api.github.com/users/chainer/followers","following_url":"https://api.github.com/users/chainer/following{/other_user}","gists_url":"https://api.github.com/users/chainer/gists{/gist_id}","starred_url":"https://api.github.com/users/chainer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chainer/subscriptions","organizations_url":"https://api.github.com/users/chainer/orgs","repos_url":"https://api.github.com/users/chainer/repos","events_url":"https://api.github.com/users/chainer/events{/privacy}","received_events_url":"https://api.github.com/users/chainer/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chainer/chainer","description":"A flexible framework of neural networks for deep learning","fork":false,"url":"https://api.github.com/repos/chainer/chainer","forks_url":"https://api.github.com/repos/chainer/chainer/forks","keys_url":"https://api.github.com/repos/chainer/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chainer/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chainer/chainer/teams","hooks_url":"https://api.github.com/repos/chainer/chainer/hooks","issue_events_url":"https://api.github.com/repos/chainer/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/chainer/chainer/events","assignees_url":"https://api.github.com/repos/chainer/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/chainer/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/chainer/chainer/tags","blobs_url":"https://api.github.com/repos/chainer/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chainer/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chainer/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/chainer/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chainer/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/chainer/chainer/languages","stargazers_url":"https://api.github.com/repos/chainer/chainer/stargazers","contributors_url":"https://api.github.com/repos/chainer/chainer/contributors","subscribers_url":"https://api.github.com/repos/chainer/chainer/subscribers","subscription_url":"https://api.github.com/repos/chainer/chainer/subscription","commits_url":"https://api.github.com/repos/chainer/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/chainer/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/chainer/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/chainer/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/chainer/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/chainer/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chainer/chainer/merges","archive_url":"https://api.github.com/repos/chainer/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chainer/chainer/downloads","issues_url":"https://api.github.com/repos/chainer/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/chainer/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/chainer/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/chainer/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chainer/chainer/labels{/name}","releases_url":"https://api.github.com/repos/chainer/chainer/releases{/id}","deployments_url":"https://api.github.com/repos/chainer/chainer/deployments","created_at":"2015-06-05T05:50:37Z","updated_at":"2017-11-15T19:52:41Z","pushed_at":"2017-11-16T01:26:17Z","git_url":"git://github.com/chainer/chainer.git","ssh_url":"git@github.com:chainer/chainer.git","clone_url":"https://github.com/chainer/chainer.git","svn_url":"https://github.com/chainer/chainer","homepage":"https://chainer.org","size":18833,"stargazers_count":3144,"watchers_count":3144,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":836,"mirror_url":null,"archived":false,"open_issues_count":438,"forks":836,"open_issues":438,"watchers":3144,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chainer/chainer/pulls/3533"},"html":{"href":"https://github.com/chainer/chainer/pull/3533"},"issue":{"href":"https://api.github.com/repos/chainer/chainer/issues/3533"},"comments":{"href":"https://api.github.com/repos/chainer/chainer/issues/3533/comments"},"review_comments":{"href":"https://api.github.com/repos/chainer/chainer/pulls/3533/comments"},"review_comment":{"href":"https://api.github.com/repos/chainer/chainer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chainer/chainer/pulls/3533/commits"},"statuses":{"href":"https://api.github.com/repos/chainer/chainer/statuses/c2ea66556d52513c087f31401aacee907b2a6742"}},"author_association":"OWNER"}}
{"actor":{"display_login":"kmaehashi"}}