Skip to content

Commit 103e33d

Browse files
ArmavicaricardoV94
authored andcommitted
Remove OrderedDict in graph/destroyhandler
1 parent cfc3d4b commit 103e33d

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

pytensor/graph/destroyhandler.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import itertools
8-
from collections import OrderedDict, deque
8+
from collections import deque
99

1010
import pytensor
1111
from pytensor.configdefaults import config
@@ -306,7 +306,7 @@ def __init__(self, do_imports_on_attach=True, algo=None):
306306
TODO: change name to var_to_vroot.
307307
308308
"""
309-
self.droot = OrderedDict()
309+
self.droot = {}
310310

311311
"""
312312
Maps a variable to all variables that are indirect or direct views of it
@@ -317,19 +317,19 @@ def __init__(self, do_imports_on_attach=True, algo=None):
317317
TODO: rename to x_to_views after reverse engineering what x is
318318
319319
"""
320-
self.impact = OrderedDict()
320+
self.impact = {}
321321

322322
"""
323323
If a var is destroyed, then this dict will map
324324
droot[var] to the apply node that destroyed var
325325
TODO: rename to vroot_to_destroyer
326326
327327
"""
328-
self.root_destroyer = OrderedDict()
328+
self.root_destroyer = {}
329329
if algo is None:
330330
algo = config.cycle_detection
331331
self.algo = algo
332-
self.fail_validate = OrderedDict()
332+
self.fail_validate = {}
333333

334334
def clone(self):
335335
return type(self)(self.do_imports_on_attach, self.algo)
@@ -370,7 +370,7 @@ def on_attach(self, fgraph):
370370
self.view_i = {} # variable -> variable used in calculation
371371
self.view_o = {} # variable -> set of variables that use this one as a direct input
372372
# clients: how many times does an apply use a given variable
373-
self.clients = OrderedDict() # variable -> apply -> ninputs
373+
self.clients = {} # variable -> apply -> ninputs
374374
self.stale_droot = True
375375

376376
self.debug_all_apps = set()
@@ -527,11 +527,11 @@ def on_import(self, fgraph, app, reason):
527527

528528
# update self.clients
529529
for i, input in enumerate(app.inputs):
530-
self.clients.setdefault(input, OrderedDict()).setdefault(app, 0)
530+
self.clients.setdefault(input, {}).setdefault(app, 0)
531531
self.clients[input][app] += 1
532532

533533
for i, output in enumerate(app.outputs):
534-
self.clients.setdefault(output, OrderedDict())
534+
self.clients.setdefault(output, {})
535535

536536
self.stale_droot = True
537537

@@ -591,7 +591,7 @@ def on_change_input(self, fgraph, app, i, old_r, new_r, reason):
591591
if self.clients[old_r][app] == 0:
592592
del self.clients[old_r][app]
593593

594-
self.clients.setdefault(new_r, OrderedDict()).setdefault(app, 0)
594+
self.clients.setdefault(new_r, {}).setdefault(app, 0)
595595
self.clients[new_r][app] += 1
596596

597597
# UPDATE self.view_i, self.view_o
@@ -632,7 +632,7 @@ def validate(self, fgraph):
632632
if self.algo == "fast":
633633
if self.fail_validate:
634634
app_err_pairs = self.fail_validate
635-
self.fail_validate = OrderedDict()
635+
self.fail_validate = {}
636636
# self.fail_validate can only be a hint that maybe/probably
637637
# there is a cycle.This is because inside replace() we could
638638
# record many reasons to not accept a change, but we don't
@@ -674,12 +674,8 @@ def orderings(self, fgraph, ordered=True):
674674
c) an Apply destroys (illegally) one of its own inputs by aliasing
675675
676676
"""
677-
if ordered:
678-
set_type = OrderedSet
679-
rval = OrderedDict()
680-
else:
681-
set_type = set
682-
rval = dict()
677+
set_type = OrderedSet if ordered else set
678+
rval = {}
683679

684680
if self.destroyers:
685681
# BUILD DATA STRUCTURES

0 commit comments

Comments
 (0)