{"action":"created","comment":{"url":"https://api.github.com/repos/pfnet/chainer/pulls/comments/49963254","id":49963254,"diff_hunk":"@@ -114,3 +115,131 @@ def assert_allclose(x, y, atol=1e-5, rtol=1e-4, verbose=True):\n     except Exception:\n         print('error:', numpy.abs(x - y).max())\n         raise\n+\n+\n+def _as_tuple(x):\n+    if isinstance(x, tuple):\n+        return x\n+    elif isinstance(x, list):\n+        return tuple(x)\n+    else:\n+        return (x,)\n+\n+\n+def check_backward(func, x_data, y_grad, params=(),\n+                   eps=1e-3, atol=1e-5, rtol=1e-4):\n+    \"\"\"Test backward procedure of a given function.\n+\n+    This function automatically check backward-process of a given function.\n+    For example, when you have a :class:`~chainer.Function` class ``MyFunc``,\n+    that gets two arguments and returns one value, you can make its test like\n+    this::\n+\n+    >> def test_my_func(self):\n+    >>   func = MyFunc()\n+    >>   x1_data = xp.array(...)\n+    >>   x2_data = xp.array(...)\n+    >>   gy_data = xp.array(...)\n+    >>   check_backward(func, (x1_data, x2_data), gy_data)\n+\n+    This method creates :class:`~chainer.Variable` objects with ``x_data``,\n+    and call ``func`` with the :class:`~chainer.Variable`s to get its result\n+    :class:`~chainer.Variable`.\n+    And then, set ``grad`` of the results with ``y_grad`` arrays and call\n+    ``backward`` method to get gradients of the inputs.\n+    To check correctness of the gradients, the function calls\n+    :func:`numerical_grad` and compares them with :func:`assert_allclose`.\n+    If an input object represents integer variable, its gradient is ignored.\n+\n+    You can simplify a test when ``MyFunc`` gets only one argument::\n+\n+    >>   check_backward(func, x1_data, gy_data)\n+","path":"chainer/gradient_check.py","position":51,"original_position":51,"commit_id":"349de13076b474678aa2f925570db5a20653c372","original_commit_id":"9e0d3ee7a8318e6a6c5111f598d48ce13f82f972","user":{"login":"delta2323","id":407052,"avatar_url":"https://avatars.githubusercontent.com/u/407052?v=3","gravatar_id":"","url":"https://api.github.com/users/delta2323","html_url":"https://github.com/delta2323","followers_url":"https://api.github.com/users/delta2323/followers","following_url":"https://api.github.com/users/delta2323/following{/other_user}","gists_url":"https://api.github.com/users/delta2323/gists{/gist_id}","starred_url":"https://api.github.com/users/delta2323/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/delta2323/subscriptions","organizations_url":"https://api.github.com/users/delta2323/orgs","repos_url":"https://api.github.com/users/delta2323/repos","events_url":"https://api.github.com/users/delta2323/events{/privacy}","received_events_url":"https://api.github.com/users/delta2323/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2016-01-18T05:31:07Z","updated_at":"2016-01-18T05:31:07Z","html_url":"https://github.com/pfnet/chainer/pull/848#discussion_r49963254","pull_request_url":"https://api.github.com/repos/pfnet/chainer/pulls/848","_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/comments/49963254"},"html":{"href":"https://github.com/pfnet/chainer/pull/848#discussion_r49963254"},"pull_request":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/848"}}},"pull_request":{"url":"https://api.github.com/repos/pfnet/chainer/pulls/848","id":55889991,"html_url":"https://github.com/pfnet/chainer/pull/848","diff_url":"https://github.com/pfnet/chainer/pull/848.diff","patch_url":"https://github.com/pfnet/chainer/pull/848.patch","issue_url":"https://api.github.com/repos/pfnet/chainer/issues/848","number":848,"state":"open","locked":false,"title":"Pep8 1.7.0","user":{"login":"unnonouno","id":740680,"avatar_url":"https://avatars.githubusercontent.com/u/740680?v=3","gravatar_id":"","url":"https://api.github.com/users/unnonouno","html_url":"https://github.com/unnonouno","followers_url":"https://api.github.com/users/unnonouno/followers","following_url":"https://api.github.com/users/unnonouno/following{/other_user}","gists_url":"https://api.github.com/users/unnonouno/gists{/gist_id}","starred_url":"https://api.github.com/users/unnonouno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unnonouno/subscriptions","organizations_url":"https://api.github.com/users/unnonouno/orgs","repos_url":"https://api.github.com/users/unnonouno/repos","events_url":"https://api.github.com/users/unnonouno/events{/privacy}","received_events_url":"https://api.github.com/users/unnonouno/received_events","type":"User","site_admin":false},"body":"fix #846 \r\n\r\nMain differences are below:\r\n- Fix operator position (W503)\r\n- Make a general backward-checking method and use it in test for functions and links (E731)\r\n- Replace lambda with def (E731)","created_at":"2016-01-13T12:17:42Z","updated_at":"2016-01-18T05:31:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"63cd960d51c9da9424a574ed9097174bc0c3a0c3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pfnet/chainer/pulls/848/commits","review_comments_url":"https://api.github.com/repos/pfnet/chainer/pulls/848/comments","review_comment_url":"https://api.github.com/repos/pfnet/chainer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pfnet/chainer/issues/848/comments","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/349de13076b474678aa2f925570db5a20653c372","head":{"label":"pfnet:pep8-1.7.0","ref":"pep8-1.7.0","sha":"349de13076b474678aa2f925570db5a20653c372","user":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"repo":{"id":36914478,"name":"chainer","full_name":"pfnet/chainer","owner":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pfnet/chainer","description":"A flexible framework of neural networks for deep learning","fork":false,"url":"https://api.github.com/repos/pfnet/chainer","forks_url":"https://api.github.com/repos/pfnet/chainer/forks","keys_url":"https://api.github.com/repos/pfnet/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pfnet/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pfnet/chainer/teams","hooks_url":"https://api.github.com/repos/pfnet/chainer/hooks","issue_events_url":"https://api.github.com/repos/pfnet/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/pfnet/chainer/events","assignees_url":"https://api.github.com/repos/pfnet/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/pfnet/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/pfnet/chainer/tags","blobs_url":"https://api.github.com/repos/pfnet/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pfnet/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pfnet/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/pfnet/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/pfnet/chainer/languages","stargazers_url":"https://api.github.com/repos/pfnet/chainer/stargazers","contributors_url":"https://api.github.com/repos/pfnet/chainer/contributors","subscribers_url":"https://api.github.com/repos/pfnet/chainer/subscribers","subscription_url":"https://api.github.com/repos/pfnet/chainer/subscription","commits_url":"https://api.github.com/repos/pfnet/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/pfnet/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/pfnet/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/pfnet/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/pfnet/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/pfnet/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pfnet/chainer/merges","archive_url":"https://api.github.com/repos/pfnet/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pfnet/chainer/downloads","issues_url":"https://api.github.com/repos/pfnet/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/pfnet/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/pfnet/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/pfnet/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pfnet/chainer/labels{/name}","releases_url":"https://api.github.com/repos/pfnet/chainer/releases{/id}","created_at":"2015-06-05T05:50:37Z","updated_at":"2016-01-17T19:13:02Z","pushed_at":"2016-01-18T04:24:34Z","git_url":"git://github.com/pfnet/chainer.git","ssh_url":"git@github.com:pfnet/chainer.git","clone_url":"https://github.com/pfnet/chainer.git","svn_url":"https://github.com/pfnet/chainer","homepage":"http://chainer.org","size":13237,"stargazers_count":1092,"watchers_count":1092,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":194,"mirror_url":null,"open_issues_count":128,"forks":194,"open_issues":128,"watchers":1092,"default_branch":"master"}},"base":{"label":"pfnet:master","ref":"master","sha":"6b27aa527e4aaa50acd57b62c30b43518db92a89","user":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"repo":{"id":36914478,"name":"chainer","full_name":"pfnet/chainer","owner":{"login":"pfnet","id":9739572,"avatar_url":"https://avatars.githubusercontent.com/u/9739572?v=3","gravatar_id":"","url":"https://api.github.com/users/pfnet","html_url":"https://github.com/pfnet","followers_url":"https://api.github.com/users/pfnet/followers","following_url":"https://api.github.com/users/pfnet/following{/other_user}","gists_url":"https://api.github.com/users/pfnet/gists{/gist_id}","starred_url":"https://api.github.com/users/pfnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pfnet/subscriptions","organizations_url":"https://api.github.com/users/pfnet/orgs","repos_url":"https://api.github.com/users/pfnet/repos","events_url":"https://api.github.com/users/pfnet/events{/privacy}","received_events_url":"https://api.github.com/users/pfnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pfnet/chainer","description":"A flexible framework of neural networks for deep learning","fork":false,"url":"https://api.github.com/repos/pfnet/chainer","forks_url":"https://api.github.com/repos/pfnet/chainer/forks","keys_url":"https://api.github.com/repos/pfnet/chainer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pfnet/chainer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pfnet/chainer/teams","hooks_url":"https://api.github.com/repos/pfnet/chainer/hooks","issue_events_url":"https://api.github.com/repos/pfnet/chainer/issues/events{/number}","events_url":"https://api.github.com/repos/pfnet/chainer/events","assignees_url":"https://api.github.com/repos/pfnet/chainer/assignees{/user}","branches_url":"https://api.github.com/repos/pfnet/chainer/branches{/branch}","tags_url":"https://api.github.com/repos/pfnet/chainer/tags","blobs_url":"https://api.github.com/repos/pfnet/chainer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pfnet/chainer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pfnet/chainer/git/refs{/sha}","trees_url":"https://api.github.com/repos/pfnet/chainer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pfnet/chainer/statuses/{sha}","languages_url":"https://api.github.com/repos/pfnet/chainer/languages","stargazers_url":"https://api.github.com/repos/pfnet/chainer/stargazers","contributors_url":"https://api.github.com/repos/pfnet/chainer/contributors","subscribers_url":"https://api.github.com/repos/pfnet/chainer/subscribers","subscription_url":"https://api.github.com/repos/pfnet/chainer/subscription","commits_url":"https://api.github.com/repos/pfnet/chainer/commits{/sha}","git_commits_url":"https://api.github.com/repos/pfnet/chainer/git/commits{/sha}","comments_url":"https://api.github.com/repos/pfnet/chainer/comments{/number}","issue_comment_url":"https://api.github.com/repos/pfnet/chainer/issues/comments{/number}","contents_url":"https://api.github.com/repos/pfnet/chainer/contents/{+path}","compare_url":"https://api.github.com/repos/pfnet/chainer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pfnet/chainer/merges","archive_url":"https://api.github.com/repos/pfnet/chainer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pfnet/chainer/downloads","issues_url":"https://api.github.com/repos/pfnet/chainer/issues{/number}","pulls_url":"https://api.github.com/repos/pfnet/chainer/pulls{/number}","milestones_url":"https://api.github.com/repos/pfnet/chainer/milestones{/number}","notifications_url":"https://api.github.com/repos/pfnet/chainer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pfnet/chainer/labels{/name}","releases_url":"https://api.github.com/repos/pfnet/chainer/releases{/id}","created_at":"2015-06-05T05:50:37Z","updated_at":"2016-01-17T19:13:02Z","pushed_at":"2016-01-18T04:24:34Z","git_url":"git://github.com/pfnet/chainer.git","ssh_url":"git@github.com:pfnet/chainer.git","clone_url":"https://github.com/pfnet/chainer.git","svn_url":"https://github.com/pfnet/chainer","homepage":"http://chainer.org","size":13237,"stargazers_count":1092,"watchers_count":1092,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":194,"mirror_url":null,"open_issues_count":128,"forks":194,"open_issues":128,"watchers":1092,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/848"},"html":{"href":"https://github.com/pfnet/chainer/pull/848"},"issue":{"href":"https://api.github.com/repos/pfnet/chainer/issues/848"},"comments":{"href":"https://api.github.com/repos/pfnet/chainer/issues/848/comments"},"review_comments":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/848/comments"},"review_comment":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pfnet/chainer/pulls/848/commits"},"statuses":{"href":"https://api.github.com/repos/pfnet/chainer/statuses/349de13076b474678aa2f925570db5a20653c372"}}}}