提交 103e33d5 authored 作者: Virgile Andreani's avatar Virgile Andreani 提交者: Ricardo Vieira

Remove OrderedDict in graph/destroyhandler

上级 cfc3d4b6
...@@ -5,7 +5,7 @@ and inplace operations. ...@@ -5,7 +5,7 @@ and inplace operations.
""" """
import itertools import itertools
from collections import OrderedDict, deque from collections import deque
import pytensor import pytensor
from pytensor.configdefaults import config from pytensor.configdefaults import config
...@@ -306,7 +306,7 @@ class DestroyHandler(Bookkeeper): ...@@ -306,7 +306,7 @@ class DestroyHandler(Bookkeeper):
TODO: change name to var_to_vroot. TODO: change name to var_to_vroot.
""" """
self.droot = OrderedDict() self.droot = {}
""" """
Maps a variable to all variables that are indirect or direct views of it Maps a variable to all variables that are indirect or direct views of it
...@@ -317,7 +317,7 @@ class DestroyHandler(Bookkeeper): ...@@ -317,7 +317,7 @@ class DestroyHandler(Bookkeeper):
TODO: rename to x_to_views after reverse engineering what x is TODO: rename to x_to_views after reverse engineering what x is
""" """
self.impact = OrderedDict() self.impact = {}
""" """
If a var is destroyed, then this dict will map If a var is destroyed, then this dict will map
...@@ -325,11 +325,11 @@ class DestroyHandler(Bookkeeper): ...@@ -325,11 +325,11 @@ class DestroyHandler(Bookkeeper):
TODO: rename to vroot_to_destroyer TODO: rename to vroot_to_destroyer
""" """
self.root_destroyer = OrderedDict() self.root_destroyer = {}
if algo is None: if algo is None:
algo = config.cycle_detection algo = config.cycle_detection
self.algo = algo self.algo = algo
self.fail_validate = OrderedDict() self.fail_validate = {}
def clone(self): def clone(self):
return type(self)(self.do_imports_on_attach, self.algo) return type(self)(self.do_imports_on_attach, self.algo)
...@@ -370,7 +370,7 @@ class DestroyHandler(Bookkeeper): ...@@ -370,7 +370,7 @@ class DestroyHandler(Bookkeeper):
self.view_i = {} # variable -> variable used in calculation self.view_i = {} # variable -> variable used in calculation
self.view_o = {} # variable -> set of variables that use this one as a direct input self.view_o = {} # variable -> set of variables that use this one as a direct input
# clients: how many times does an apply use a given variable # clients: how many times does an apply use a given variable
self.clients = OrderedDict() # variable -> apply -> ninputs self.clients = {} # variable -> apply -> ninputs
self.stale_droot = True self.stale_droot = True
self.debug_all_apps = set() self.debug_all_apps = set()
...@@ -527,11 +527,11 @@ class DestroyHandler(Bookkeeper): ...@@ -527,11 +527,11 @@ class DestroyHandler(Bookkeeper):
# update self.clients # update self.clients
for i, input in enumerate(app.inputs): for i, input in enumerate(app.inputs):
self.clients.setdefault(input, OrderedDict()).setdefault(app, 0) self.clients.setdefault(input, {}).setdefault(app, 0)
self.clients[input][app] += 1 self.clients[input][app] += 1
for i, output in enumerate(app.outputs): for i, output in enumerate(app.outputs):
self.clients.setdefault(output, OrderedDict()) self.clients.setdefault(output, {})
self.stale_droot = True self.stale_droot = True
...@@ -591,7 +591,7 @@ class DestroyHandler(Bookkeeper): ...@@ -591,7 +591,7 @@ class DestroyHandler(Bookkeeper):
if self.clients[old_r][app] == 0: if self.clients[old_r][app] == 0:
del self.clients[old_r][app] del self.clients[old_r][app]
self.clients.setdefault(new_r, OrderedDict()).setdefault(app, 0) self.clients.setdefault(new_r, {}).setdefault(app, 0)
self.clients[new_r][app] += 1 self.clients[new_r][app] += 1
# UPDATE self.view_i, self.view_o # UPDATE self.view_i, self.view_o
...@@ -632,7 +632,7 @@ class DestroyHandler(Bookkeeper): ...@@ -632,7 +632,7 @@ class DestroyHandler(Bookkeeper):
if self.algo == "fast": if self.algo == "fast":
if self.fail_validate: if self.fail_validate:
app_err_pairs = self.fail_validate app_err_pairs = self.fail_validate
self.fail_validate = OrderedDict() self.fail_validate = {}
# self.fail_validate can only be a hint that maybe/probably # self.fail_validate can only be a hint that maybe/probably
# there is a cycle.This is because inside replace() we could # there is a cycle.This is because inside replace() we could
# record many reasons to not accept a change, but we don't # record many reasons to not accept a change, but we don't
...@@ -674,12 +674,8 @@ class DestroyHandler(Bookkeeper): ...@@ -674,12 +674,8 @@ class DestroyHandler(Bookkeeper):
c) an Apply destroys (illegally) one of its own inputs by aliasing c) an Apply destroys (illegally) one of its own inputs by aliasing
""" """
if ordered: set_type = OrderedSet if ordered else set
set_type = OrderedSet rval = {}
rval = OrderedDict()
else:
set_type = set
rval = dict()
if self.destroyers: if self.destroyers:
# BUILD DATA STRUCTURES # BUILD DATA STRUCTURES
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论