Skip to content

Commit d7c7875

Browse files
ArmavicaricardoV94
authored andcommitted
Fix PERF403: dict comprehensions when appropriate
1 parent f2bf051 commit d7c7875

File tree

4 files changed

+4
-13
lines changed

4 files changed

+4
-13
lines changed

pytensor/link/vm.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1055,12 +1055,7 @@ def make_vm(
10551055
for v in self.fgraph.inputs + self.fgraph.outputs:
10561056
vars_idx.setdefault(v, len(vars_idx))
10571057

1058-
nodes_idx_inv = {}
1059-
vars_idx_inv = {}
1060-
for node, i in nodes_idx.items():
1061-
nodes_idx_inv[i] = node
1062-
for var, i in vars_idx.items():
1063-
vars_idx_inv[i] = var
1058+
vars_idx_inv = {i: var for var, i in vars_idx.items()}
10641059

10651060
# put storage_map and compute_map into a int-based scheme
10661061
storage_map_list = [

pytensor/scalar/basic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4434,8 +4434,7 @@ def apply(self, fgraph):
44344434
)
44354435
# make sure we don't produce any float16.
44364436
assert not any(o.dtype == "float16" for o in new_node.outputs)
4437-
for o, no in zip(node.outputs, new_node.outputs):
4438-
mapping[o] = no
4437+
mapping.update(zip(node.outputs, new_node.outputs))
44394438

44404439
new_ins = [mapping[inp] for inp in fgraph.inputs]
44414440
new_outs = [mapping[out] for out in fgraph.outputs]

pytensor/scan/op.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2240,8 +2240,7 @@ def infer_shape(self, fgraph, node, input_shapes):
22402240
# Non-sequences have a direct equivalent from self.inner_inputs in
22412241
# node.inputs
22422242
inner_non_sequences = self.inner_inputs[len(seqs_shape) + len(outs_shape) :]
2243-
for in_ns, out_ns in zip(inner_non_sequences, node.inputs[offset:]):
2244-
out_equivalent[in_ns] = out_ns
2243+
out_equivalent.update(zip(inner_non_sequences, node.inputs[offset:]))
22452244

22462245
if info.as_while:
22472246
self_outs = self.inner_outputs[:-1]

pytensor/scan/rewriting.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,7 @@ def scan_save_mem(fgraph, node):
16231623
(inps, outs, info, node_ins, compress_map) = compress_outs(
16241624
op, not_required, nw_inputs
16251625
)
1626-
inv_compress_map = {}
1627-
for k, v in compress_map.items():
1628-
inv_compress_map[v] = k
1626+
inv_compress_map = {v: k for k, v in compress_map.items()}
16291627

16301628
# 3.6 Compose the new scan
16311629
# TODO: currently we don't support scan with 0 step. So

0 commit comments

Comments
 (0)