Skip to content

Commit 3647c98

Browse files
ArmavicaricardoV94
authored andcommitted
Fix PERF102: useless calls to dict.items()
1 parent 223b739 commit 3647c98

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

pytensor/compile/debugmode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def _check_inputs(
478478
"""
479479
destroyed_idx_list = []
480480
destroy_map = node.op.destroy_map
481-
for o_pos, i_pos_list in destroy_map.items():
481+
for i_pos_list in destroy_map.values():
482482
destroyed_idx_list.extend(i_pos_list)
483483
destroyed_res_list = [node.inputs[i] for i in destroyed_idx_list]
484484

@@ -598,7 +598,7 @@ def _check_viewmap(fgraph, node, storage_map):
598598
# TODO: make sure this is correct
599599
# According to OB, duplicate inputs are rejected on build graph time
600600
# if they cause problems. So if they are here it should be ok.
601-
for key, val in good_alias.items():
601+
for key in good_alias:
602602
bad_alias.pop(key, None)
603603
if bad_alias:
604604
raise BadViewMap(node, oi, outstorage, list(bad_alias.values()))

pytensor/compile/profiling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,9 @@ def print_stats(stats1, stats2):
13801380
items.sort(key=lambda a: a[1], reverse=True)
13811381
for idx, ((fgraph, node), node_outputs_size) in enumerate(items[:N]):
13821382
code = ["c"] * len(node.outputs)
1383-
for out, inp in node.op.destroy_map.items():
1383+
for out in node.op.destroy_map:
13841384
code[out] = "i"
1385-
for out, inp in node.op.view_map.items():
1385+
for out in node.op.view_map:
13861386
code[out] = "v"
13871387
shapes = str(fct_shapes[fgraph][node])
13881388

pytensor/graph/destroyhandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def _build_droot_impact(destroy_handler):
182182
root_destroyer = {} # root -> destroyer apply
183183

184184
for app in destroy_handler.destroyers:
185-
for output_idx, input_idx_list in app.op.destroy_map.items():
185+
for input_idx_list in app.op.destroy_map.values():
186186
if len(input_idx_list) != 1:
187187
raise NotImplementedError()
188188
input_idx = input_idx_list[0]
@@ -698,7 +698,7 @@ def orderings(self, fgraph, ordered=True):
698698
# keep track of clients that should run before the current Apply
699699
root_clients = set_type()
700700
# for each destroyed input...
701-
for output_idx, input_idx_list in app.op.destroy_map.items():
701+
for input_idx_list in app.op.destroy_map.values():
702702
destroyed_idx = input_idx_list[0]
703703
destroyed_variable = app.inputs[destroyed_idx]
704704
root = droot[destroyed_variable]

pytensor/link/vm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def __call__(self, output_subset=None):
545545
# Add the outputs that are needed for the in-place updates of the
546546
# inputs in `self.update_vars`
547547
output_subset = list(output_subset)
548-
for inp, out in self.update_vars.items():
548+
for out in self.update_vars.values():
549549
out_idx = self.fgraph.outputs.index(out)
550550
if out_idx not in output_subset:
551551
output_subset.append(out_idx)

tests/tensor/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def test_good(self):
528528

529529
@pytest.mark.skipif(skip, reason="Skipped")
530530
def test_bad_build(self):
531-
for testname, inputs in self.bad_build.items():
531+
for inputs in self.bad_build.values():
532532
inputs = [copy(input) for input in inputs]
533533
inputrs = [shared(input) for input in inputs]
534534
with pytest.raises(Exception):

0 commit comments

Comments
 (0)