Skip to content

Commit 3c66aa6

Browse files
committed
Remove useless int() in f-strings
1 parent 246714b commit 3c66aa6

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

pytensor/scalar/basic.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4333,17 +4333,17 @@ def __str__(self):
43334333

43344334
# Rename internal variables
43354335
for i, r in enumerate(self.fgraph.inputs):
4336-
r.name = f"i{int(i)}"
4336+
r.name = f"i{i}"
43374337
for i, r in enumerate(self.fgraph.outputs):
4338-
r.name = f"o{int(i)}"
4338+
r.name = f"o{i}"
43394339
io = set(self.fgraph.inputs + self.fgraph.outputs)
43404340
for i, r in enumerate(self.fgraph.variables):
43414341
if (
43424342
not isinstance(r, Constant)
43434343
and r not in io
43444344
and len(self.fgraph.clients[r]) > 1
43454345
):
4346-
r.name = f"t{int(i)}"
4346+
r.name = f"t{i}"
43474347

43484348
if len(self.fgraph.outputs) > 1 or len(self.fgraph.apply_nodes) > 10:
43494349
self._name = "Composite{...}"
@@ -4431,7 +4431,7 @@ def c_code_template(self):
44314431
return self._c_code
44324432

44334433
fg = self.fgraph
4434-
subd = {e: f"%(i{int(i)})s" for i, e in enumerate(fg.inputs)}
4434+
subd = {e: f"%(i{i})s" for i, e in enumerate(fg.inputs)}
44354435

44364436
for var in fg.variables:
44374437
if var.owner is None:
@@ -4458,26 +4458,26 @@ def c_code_template(self):
44584458
for output in node.outputs:
44594459
if output not in subd:
44604460
i += 1
4461-
name = f"V%(id)s_tmp{int(i)}"
4461+
name = f"V%(id)s_tmp{i}"
44624462
subd[output] = name
44634463
_c_code += f"{output.type.dtype_specs()[1]} {name};\n"
44644464

4465-
nodename = f"%(nodename)s_subnode{int(j)}"
4465+
nodename = f"%(nodename)s_subnode{j}"
44664466
nodenames.append(nodename)
44674467

44684468
s = node.op.c_code(
44694469
node,
44704470
nodename,
44714471
[subd[input] for input in node.inputs],
44724472
[subd[output] for output in node.outputs],
4473-
dict(fail="%(fail)s", id=f"%(id)s_{int(j)}"),
4473+
dict(fail="%(fail)s", id=f"%(id)s_{j}"),
44744474
)
44754475
_c_code += s
44764476
_c_code += "\n"
44774477

44784478
# Copy the temporary outputs to the real outputs
44794479
for i, output in enumerate(fg.outputs):
4480-
_c_code += f"%(o{int(i)})s = {subd[output]};\n"
4480+
_c_code += f"%(o{i})s = {subd[output]};\n"
44814481

44824482
_c_code += "}\n"
44834483

@@ -4488,8 +4488,8 @@ def c_code_template(self):
44884488
def c_code(self, node, nodename, inames, onames, sub):
44894489
d = dict(
44904490
chain(
4491-
zip((f"i{int(i)}" for i in range(len(inames))), inames, strict=True),
4492-
zip((f"o{int(i)}" for i in range(len(onames))), onames, strict=True),
4491+
zip((f"i{i}" for i in range(len(inames))), inames, strict=True),
4492+
zip((f"o{i}" for i in range(len(onames))), onames, strict=True),
44934493
),
44944494
**sub,
44954495
)

pytensor/scalar/loop.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,13 @@ def c_code_template(self):
212212
# The first input is `n_steps` so we skip it in the mapping dictionary
213213
n_update = len(self.outputs) - (1 if self.is_while else 0)
214214
carry_subd = {
215-
c: f"%(i{int(i)})s" for i, c in enumerate(fgraph.inputs[:n_update], start=1)
215+
c: f"%(i{i})s" for i, c in enumerate(fgraph.inputs[:n_update], start=1)
216216
}
217217
constant_subd = {
218-
c: f"%(i{int(i)})s"
218+
c: f"%(i{i})s"
219219
for i, c in enumerate(fgraph.inputs[n_update:], start=n_update + 1)
220220
}
221-
out_subd = {
222-
u: f"%(o{int(i)})s" for i, u in enumerate(fgraph.outputs[:n_update])
223-
}
221+
out_subd = {u: f"%(o{i})s" for i, u in enumerate(fgraph.outputs[:n_update])}
224222
until_subd = {u: "until" for u in fgraph.outputs[n_update:]}
225223
subd = {**carry_subd, **constant_subd, **until_subd}
226224

@@ -267,11 +265,11 @@ def c_code_template(self):
267265
for output in node.outputs:
268266
if output not in subd:
269267
i += 1
270-
name = f"V%(id)s_tmp{int(i)}"
268+
name = f"V%(id)s_tmp{i}"
271269
subd[output] = name
272270
_c_code += f"{output.type.dtype_specs()[1]} {name};\n"
273271

274-
nodename = f"%(nodename)s_subnode{int(j)}"
272+
nodename = f"%(nodename)s_subnode{j}"
275273
nodenames.append(nodename)
276274

277275
s = node.op.c_code(
@@ -281,7 +279,7 @@ def c_code_template(self):
281279
# The initial value of `update` was set to `init` before the loop
282280
[subd[input] for input in node.inputs],
283281
[subd[output] for output in node.outputs],
284-
dict(fail="%(fail)s", id=f"%(id)s_{int(j)}"),
282+
dict(fail="%(fail)s", id=f"%(id)s_{j}"),
285283
)
286284
_c_code += s
287285
_c_code += "\n"
@@ -320,8 +318,8 @@ def c_code_template(self):
320318
def c_code(self, node, nodename, inames, onames, sub):
321319
d = dict(
322320
chain(
323-
zip((f"i{int(i)}" for i in range(len(inames))), inames, strict=True),
324-
zip((f"o{int(i)}" for i in range(len(onames))), onames, strict=True),
321+
zip((f"i{i}" for i in range(len(inames))), inames, strict=True),
322+
zip((f"o{i}" for i in range(len(onames))), onames, strict=True),
325323
),
326324
**sub,
327325
)

0 commit comments

Comments
 (0)