Skip to content

Commit e6b7004

Browse files
committed
Apply rule UP031
1 parent ad9491d commit e6b7004

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

pytensor/compile/profiling.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,12 @@ def summary_class(self, file=sys.stderr, N=None):
514514
# While this carries over less information, it is arranged such
515515
# that it is way more readable than the previous output of the
516516
# profiler
517+
nb_classes = max(0, len(otimes) - N)
518+
percent_total = sum(f for f, t, a, ci, nb_call, nb_op in otimes[N:])
519+
time_total = sum(t for f, t, a, ci, nb_call, nb_op in otimes[N:])
517520
print(
518-
" ... (remaining %i Classes account for %6.2f%%(%.2fs) of "
519-
"the runtime)"
520-
% (
521-
max(0, len(otimes) - N),
522-
sum(f for f, t, a, ci, nb_call, nb_op in otimes[N:]),
523-
sum(t for f, t, a, ci, nb_call, nb_op in otimes[N:]),
524-
),
521+
f" ... (remaining {nb_classes} Classes account for "
522+
f"{percent_total:6.2f}%%({time_total:.2f}s) of the runtime)",
525523
file=file,
526524
)
527525
print("", file=file)
@@ -607,14 +605,12 @@ def summary_ops(self, file=sys.stderr, N=None):
607605
# While this carries over less information, it is arranged such
608606
# that it is way more readable than the previous output of the
609607
# profiler
608+
nb_ops = max(0, len(otimes) - N)
609+
percent_total = sum(f for f, t, a, ci, nb_call, nb_op in otimes[N:])
610+
time_total = sum(t for f, t, a, ci, nb_call, nb_op in otimes[N:])
610611
print(
611-
" ... (remaining %i Ops account for %6.2f%%(%.2fs) of "
612-
"the runtime)"
613-
% (
614-
max(0, len(otimes) - N),
615-
sum(f for f, t, a, ci, nb_call, nb_op in otimes[N:]),
616-
sum(t for f, t, a, ci, nb_call, nb_op in otimes[N:]),
617-
),
612+
f" ... (remaining {nb_ops} Ops account for "
613+
f"{percent_total:6.2f}%%({time_total:.2f}s) of the runtime)",
618614
file=file,
619615
)
620616
print("", file=file)

pytensor/link/c/basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ def failure_code(sub, use_goto=True):
108108
be careful to avoid executing incorrect code.
109109
110110
"""
111+
id = sub["id"]
112+
failure_var = sub["failure_var"]
111113
if use_goto:
112-
goto_statement = "goto __label_%(id)i;" % sub
114+
goto_statement = f"goto __label_{id};"
113115
else:
114116
goto_statement = ""
115-
id = sub["id"]
116-
failure_var = sub["failure_var"]
117117
return f"""{{
118118
{failure_var} = {id};
119119
if (!PyErr_Occurred()) {{

tests/tensor/rewriting/test_elemwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ def test_elemwise_fusion(self, case, nb_repeat=1, assert_len_topo=True):
10761076

10771077
def test_fusion_35_inputs(self):
10781078
r"""Make sure we don't fuse too many `Op`\s and go past the 31 function arguments limit."""
1079-
inpts = vectors(["i%i" % i for i in range(35)])
1079+
inpts = vectors([f"i{i}" for i in range(35)])
10801080

10811081
# Make an elemwise graph looking like:
10821082
# sin(i34 + sin(i33 + sin(... i1 + sin(i0) ...)))

0 commit comments

Comments
 (0)