Skip to content

Commit

Permalink
minor speed by not checking the already checked nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReyhaneAskari committed Jun 5, 2017
1 parent 10573b9 commit 6090615
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions theano/gof/destroyhandler.py
Expand Up @@ -394,19 +394,25 @@ def get_destroyers_of(r):
return []
fgraph.destroyers = get_destroyers_of

def recursive_destroys_finder(clients_list):
for (app, idx) in clients_list:
if app == 'output':
continue
destroy_maps = getattr(app.op, 'destroy_map', {}).values()
if idx in [dmap for sublist in destroy_maps for dmap in sublist]:
return True
for var in getattr(app.op, 'view_map', {}).keys():
if recursive_destroys_finder(app.outputs[var].clients):
def has_destroyers(protected_list):
visited_app_set = set()

def recursive_destroys_finder(clients_list):
for (app, idx) in clients_list:
if app in visited_app_set:
continue
else:
visited_app_set.add(app)
if app == 'output':
continue
destroy_maps = getattr(app.op, 'destroy_map', {}).values()
if idx in [dmap for sublist in destroy_maps for dmap in sublist]:
return True
return False
for var in getattr(app.op, 'view_map', {}).keys():
if recursive_destroys_finder(app.outputs[var].clients):
return True
return False

def has_destroyers(protected_list):
for protected_var in protected_list:
if recursive_destroys_finder(protected_var.clients):
return True
Expand Down

0 comments on commit 6090615

Please sign in to comment.