{"action":"created","comment":{"url":"https://api.github.com/repos/Theano/Theano/pulls/comments/22860353","id":22860353,"diff_hunk":"@@ -894,6 +894,68 @@ def make_all(self, profiler=None, input_storage=None,\n             compute_map[k] = [k.owner is None]\n \n         thunks = []\n+\n+        if self.allow_gc:\n+\n+            viewed_by = {}\n+            for var in fgraph.variables:\n+                viewed_by[var] = []\n+            view_of = {}\n+\n+            for idx in range(len(order)):\n+                node = order[idx]\n+                dmap = getattr(node.op, 'destroy_map', None)\n+                vmap = getattr(node.op, 'view_map', None)\n+                reallocated_ins = set([])\n+\n+                idx_o = 0\n+                for out in node.outputs:\n+                    ins = None\n+                    if dmap and idx_o in dmap:\n+                        idx_v = dmap[idx_o]\n+                        assert len(idx_v) == 1, \"Here we only support the possibility to destroy one input\"\n+                        ins = node.inputs[idx_v[0]]\n+                    if vmap and idx_o in vmap:\n+                        assert ins is None\n+                        idx_v = vmap[idx_o]\n+                        assert len(idx_v) == 1, \"Here we only support the possibility to view one input\"\n+                        ins = node.inputs[idx_v[0]]\n+                    if ins:\n+                        assert isinstance(ins, theano.Variable)\n+                        origin = view_of.get(ins, ins)\n+                        view_of[out] = origin\n+                        viewed_by[origin].append(out)\n+                idx_o += 1                        \n+\n+                for ins in node.inputs:\n+                    assert not (ins in view_of and viewed_by[ins])\n+                    if (ins.ndim == 0 and storage_map[ins][0] and ins not in fgraph.outputs and ins.owner):\n+                        reuse_outs = []\n+                        if ins not in view_of and not viewed_by.get(ins, []):\n+                            # where gc\n+                            for i in range(idx + 1, len(order)):\n+                                for outs in order[i].outputs:\n+                                    if outs.ndim == 0:\n+                                        reuse_outs.append(outs)\n+                        elif ins in view_of:\n+                            origin = view_of[ins]\n+                            viewed_by[origin].remove(ins)\n+                            if (not viewed_by[origin] and\n+                                    origin not in fgraph.inputs and\n+                                    not isinstance(origin, theano.Constant)):\n+                                #where gc\n+                                for i in range(idx + 1, len(order)):\n+                                    for outs in order[i].outputs:\n+                                        if outs.ndim == 0:\n+                                            reuse_outs.append(outs)\n+\n+                        if reuse_outs:\n+                            # if reusable output variable exists\n+                            reallocated_ins.add(ins)","path":"theano/gof/vm.py","position":61,"original_position":61,"commit_id":"9a0adc230192cd2e53c2c0162149bae6402ffc53","original_commit_id":"9a0adc230192cd2e53c2c0162149bae6402ffc53","user":{"login":"RoyXue","id":4725561,"avatar_url":"https://avatars.githubusercontent.com/u/4725561?v=3","gravatar_id":"","url":"https://api.github.com/users/RoyXue","html_url":"https://github.com/RoyXue","followers_url":"https://api.github.com/users/RoyXue/followers","following_url":"https://api.github.com/users/RoyXue/following{/other_user}","gists_url":"https://api.github.com/users/RoyXue/gists{/gist_id}","starred_url":"https://api.github.com/users/RoyXue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoyXue/subscriptions","organizations_url":"https://api.github.com/users/RoyXue/orgs","repos_url":"https://api.github.com/users/RoyXue/repos","events_url":"https://api.github.com/users/RoyXue/events{/privacy}","received_events_url":"https://api.github.com/users/RoyXue/received_events","type":"User","site_admin":false},"body":"@nouiz \r\nhere, my origin idea is use this reallocated_ins as a if condition.\r\nfor a input variable if it's in reallocated_ins it means it had been reallocated, then we can skip this variable.\r\n\r\nI didnt make sense of why we should also put reuse_outs info here.","created_at":"2015-01-13T13:11:16Z","updated_at":"2015-01-13T13:11:16Z","html_url":"https://github.com/Theano/Theano/pull/2287#discussion_r22860353","pull_request_url":"https://api.github.com/repos/Theano/Theano/pulls/2287","_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments/22860353"},"html":{"href":"https://github.com/Theano/Theano/pull/2287#discussion_r22860353"},"pull_request":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2287"}}},"pull_request":{"url":"https://api.github.com/repos/Theano/Theano/pulls/2287","id":24910552,"html_url":"https://github.com/Theano/Theano/pull/2287","diff_url":"https://github.com/Theano/Theano/pull/2287.diff","patch_url":"https://github.com/Theano/Theano/pull/2287.patch","issue_url":"https://api.github.com/repos/Theano/Theano/issues/2287","number":2287,"state":"open","locked":false,"title":"Reduce the number of allocation/reuse allocation of ndarray #1943","user":{"login":"RoyXue","id":4725561,"avatar_url":"https://avatars.githubusercontent.com/u/4725561?v=3","gravatar_id":"","url":"https://api.github.com/users/RoyXue","html_url":"https://github.com/RoyXue","followers_url":"https://api.github.com/users/RoyXue/followers","following_url":"https://api.github.com/users/RoyXue/following{/other_user}","gists_url":"https://api.github.com/users/RoyXue/gists{/gist_id}","starred_url":"https://api.github.com/users/RoyXue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoyXue/subscriptions","organizations_url":"https://api.github.com/users/RoyXue/orgs","repos_url":"https://api.github.com/users/RoyXue/repos","events_url":"https://api.github.com/users/RoyXue/events{/privacy}","received_events_url":"https://api.github.com/users/RoyXue/received_events","type":"User","site_admin":false},"body":"#1943 \r\n@nouiz \r\n\r\nHey, Fred, this is my draft idea, is the direction right?\r\n\r\nIf the direction is right, what I wanna do in the future is fill the details, and optimize it to reduce the \"if\" inside the loop.","created_at":"2014-11-24T01:49:05Z","updated_at":"2015-01-13T13:11:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"03b70d717f8f2d30842faf1d060c943b0c64a2f8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Theano/Theano/pulls/2287/commits","review_comments_url":"https://api.github.com/repos/Theano/Theano/pulls/2287/comments","review_comment_url":"https://api.github.com/repos/Theano/Theano/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Theano/Theano/issues/2287/comments","statuses_url":"https://api.github.com/repos/Theano/Theano/statuses/9a0adc230192cd2e53c2c0162149bae6402ffc53","head":{"label":"RoyXue:reduce_ndarray_allocation","ref":"reduce_ndarray_allocation","sha":"9a0adc230192cd2e53c2c0162149bae6402ffc53","user":{"login":"RoyXue","id":4725561,"avatar_url":"https://avatars.githubusercontent.com/u/4725561?v=3","gravatar_id":"","url":"https://api.github.com/users/RoyXue","html_url":"https://github.com/RoyXue","followers_url":"https://api.github.com/users/RoyXue/followers","following_url":"https://api.github.com/users/RoyXue/following{/other_user}","gists_url":"https://api.github.com/users/RoyXue/gists{/gist_id}","starred_url":"https://api.github.com/users/RoyXue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoyXue/subscriptions","organizations_url":"https://api.github.com/users/RoyXue/orgs","repos_url":"https://api.github.com/users/RoyXue/repos","events_url":"https://api.github.com/users/RoyXue/events{/privacy}","received_events_url":"https://api.github.com/users/RoyXue/received_events","type":"User","site_admin":false},"repo":{"id":19733368,"name":"Theano","full_name":"RoyXue/Theano","owner":{"login":"RoyXue","id":4725561,"avatar_url":"https://avatars.githubusercontent.com/u/4725561?v=3","gravatar_id":"","url":"https://api.github.com/users/RoyXue","html_url":"https://github.com/RoyXue","followers_url":"https://api.github.com/users/RoyXue/followers","following_url":"https://api.github.com/users/RoyXue/following{/other_user}","gists_url":"https://api.github.com/users/RoyXue/gists{/gist_id}","starred_url":"https://api.github.com/users/RoyXue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoyXue/subscriptions","organizations_url":"https://api.github.com/users/RoyXue/orgs","repos_url":"https://api.github.com/users/RoyXue/repos","events_url":"https://api.github.com/users/RoyXue/events{/privacy}","received_events_url":"https://api.github.com/users/RoyXue/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RoyXue/Theano","description":"Optimizing GPU-meta-programming code generating array oriented optimizing math compiler in Python","fork":true,"url":"https://api.github.com/repos/RoyXue/Theano","forks_url":"https://api.github.com/repos/RoyXue/Theano/forks","keys_url":"https://api.github.com/repos/RoyXue/Theano/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RoyXue/Theano/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RoyXue/Theano/teams","hooks_url":"https://api.github.com/repos/RoyXue/Theano/hooks","issue_events_url":"https://api.github.com/repos/RoyXue/Theano/issues/events{/number}","events_url":"https://api.github.com/repos/RoyXue/Theano/events","assignees_url":"https://api.github.com/repos/RoyXue/Theano/assignees{/user}","branches_url":"https://api.github.com/repos/RoyXue/Theano/branches{/branch}","tags_url":"https://api.github.com/repos/RoyXue/Theano/tags","blobs_url":"https://api.github.com/repos/RoyXue/Theano/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RoyXue/Theano/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RoyXue/Theano/git/refs{/sha}","trees_url":"https://api.github.com/repos/RoyXue/Theano/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RoyXue/Theano/statuses/{sha}","languages_url":"https://api.github.com/repos/RoyXue/Theano/languages","stargazers_url":"https://api.github.com/repos/RoyXue/Theano/stargazers","contributors_url":"https://api.github.com/repos/RoyXue/Theano/contributors","subscribers_url":"https://api.github.com/repos/RoyXue/Theano/subscribers","subscription_url":"https://api.github.com/repos/RoyXue/Theano/subscription","commits_url":"https://api.github.com/repos/RoyXue/Theano/commits{/sha}","git_commits_url":"https://api.github.com/repos/RoyXue/Theano/git/commits{/sha}","comments_url":"https://api.github.com/repos/RoyXue/Theano/comments{/number}","issue_comment_url":"https://api.github.com/repos/RoyXue/Theano/issues/comments/{number}","contents_url":"https://api.github.com/repos/RoyXue/Theano/contents/{+path}","compare_url":"https://api.github.com/repos/RoyXue/Theano/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RoyXue/Theano/merges","archive_url":"https://api.github.com/repos/RoyXue/Theano/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RoyXue/Theano/downloads","issues_url":"https://api.github.com/repos/RoyXue/Theano/issues{/number}","pulls_url":"https://api.github.com/repos/RoyXue/Theano/pulls{/number}","milestones_url":"https://api.github.com/repos/RoyXue/Theano/milestones{/number}","notifications_url":"https://api.github.com/repos/RoyXue/Theano/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RoyXue/Theano/labels{/name}","releases_url":"https://api.github.com/repos/RoyXue/Theano/releases{/id}","created_at":"2014-05-13T09:31:54Z","updated_at":"2014-06-25T08:52:42Z","pushed_at":"2015-01-06T15:03:22Z","git_url":"git://github.com/RoyXue/Theano.git","ssh_url":"git@github.com:RoyXue/Theano.git","clone_url":"https://github.com/RoyXue/Theano.git","svn_url":"https://github.com/RoyXue/Theano","homepage":"http://www.deeplearning.net/software/theano","size":23723,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"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":"Theano:master","ref":"master","sha":"aa892a7e3f1ce45d980719a901533458ddeb41ad","user":{"login":"Theano","id":970517,"avatar_url":"https://avatars.githubusercontent.com/u/970517?v=3","gravatar_id":"","url":"https://api.github.com/users/Theano","html_url":"https://github.com/Theano","followers_url":"https://api.github.com/users/Theano/followers","following_url":"https://api.github.com/users/Theano/following{/other_user}","gists_url":"https://api.github.com/users/Theano/gists{/gist_id}","starred_url":"https://api.github.com/users/Theano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Theano/subscriptions","organizations_url":"https://api.github.com/users/Theano/orgs","repos_url":"https://api.github.com/users/Theano/repos","events_url":"https://api.github.com/users/Theano/events{/privacy}","received_events_url":"https://api.github.com/users/Theano/received_events","type":"Organization","site_admin":false},"repo":{"id":2183193,"name":"Theano","full_name":"Theano/Theano","owner":{"login":"Theano","id":970517,"avatar_url":"https://avatars.githubusercontent.com/u/970517?v=3","gravatar_id":"","url":"https://api.github.com/users/Theano","html_url":"https://github.com/Theano","followers_url":"https://api.github.com/users/Theano/followers","following_url":"https://api.github.com/users/Theano/following{/other_user}","gists_url":"https://api.github.com/users/Theano/gists{/gist_id}","starred_url":"https://api.github.com/users/Theano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Theano/subscriptions","organizations_url":"https://api.github.com/users/Theano/orgs","repos_url":"https://api.github.com/users/Theano/repos","events_url":"https://api.github.com/users/Theano/events{/privacy}","received_events_url":"https://api.github.com/users/Theano/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Theano/Theano","description":"Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.","fork":false,"url":"https://api.github.com/repos/Theano/Theano","forks_url":"https://api.github.com/repos/Theano/Theano/forks","keys_url":"https://api.github.com/repos/Theano/Theano/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Theano/Theano/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Theano/Theano/teams","hooks_url":"https://api.github.com/repos/Theano/Theano/hooks","issue_events_url":"https://api.github.com/repos/Theano/Theano/issues/events{/number}","events_url":"https://api.github.com/repos/Theano/Theano/events","assignees_url":"https://api.github.com/repos/Theano/Theano/assignees{/user}","branches_url":"https://api.github.com/repos/Theano/Theano/branches{/branch}","tags_url":"https://api.github.com/repos/Theano/Theano/tags","blobs_url":"https://api.github.com/repos/Theano/Theano/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Theano/Theano/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Theano/Theano/git/refs{/sha}","trees_url":"https://api.github.com/repos/Theano/Theano/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Theano/Theano/statuses/{sha}","languages_url":"https://api.github.com/repos/Theano/Theano/languages","stargazers_url":"https://api.github.com/repos/Theano/Theano/stargazers","contributors_url":"https://api.github.com/repos/Theano/Theano/contributors","subscribers_url":"https://api.github.com/repos/Theano/Theano/subscribers","subscription_url":"https://api.github.com/repos/Theano/Theano/subscription","commits_url":"https://api.github.com/repos/Theano/Theano/commits{/sha}","git_commits_url":"https://api.github.com/repos/Theano/Theano/git/commits{/sha}","comments_url":"https://api.github.com/repos/Theano/Theano/comments{/number}","issue_comment_url":"https://api.github.com/repos/Theano/Theano/issues/comments/{number}","contents_url":"https://api.github.com/repos/Theano/Theano/contents/{+path}","compare_url":"https://api.github.com/repos/Theano/Theano/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Theano/Theano/merges","archive_url":"https://api.github.com/repos/Theano/Theano/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Theano/Theano/downloads","issues_url":"https://api.github.com/repos/Theano/Theano/issues{/number}","pulls_url":"https://api.github.com/repos/Theano/Theano/pulls{/number}","milestones_url":"https://api.github.com/repos/Theano/Theano/milestones{/number}","notifications_url":"https://api.github.com/repos/Theano/Theano/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Theano/Theano/labels{/name}","releases_url":"https://api.github.com/repos/Theano/Theano/releases{/id}","created_at":"2011-08-10T03:48:06Z","updated_at":"2015-01-13T08:50:45Z","pushed_at":"2015-01-12T19:20:40Z","git_url":"git://github.com/Theano/Theano.git","ssh_url":"git@github.com:Theano/Theano.git","clone_url":"https://github.com/Theano/Theano.git","svn_url":"https://github.com/Theano/Theano","homepage":"http://www.deeplearning.net/software/theano","size":35922,"stargazers_count":1056,"watchers_count":1056,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":392,"mirror_url":null,"open_issues_count":318,"forks":392,"open_issues":318,"watchers":1056,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2287"},"html":{"href":"https://github.com/Theano/Theano/pull/2287"},"issue":{"href":"https://api.github.com/repos/Theano/Theano/issues/2287"},"comments":{"href":"https://api.github.com/repos/Theano/Theano/issues/2287/comments"},"review_comments":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2287/comments"},"review_comment":{"href":"https://api.github.com/repos/Theano/Theano/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Theano/Theano/pulls/2287/commits"},"statuses":{"href":"https://api.github.com/repos/Theano/Theano/statuses/9a0adc230192cd2e53c2c0162149bae6402ffc53"}}}}