Skip to content

Commit e27a43a

Browse files
committed
Apply the ruff auto fixes
1 parent 207b5e0 commit e27a43a

32 files changed

+270
-274
lines changed

pytensor/compile/function/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pytensor.graph import Variable
1313

1414

15-
__all__ = ["types", "pfunc"]
15+
__all__ = ["pfunc", "types"]
1616

1717
__docformat__ = "restructuredtext en"
1818
_logger = logging.getLogger("pytensor.compile.function")

pytensor/compile/function/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def add_supervisor_to_fgraph(
215215
input
216216
for spec, input in zip(input_specs, fgraph.inputs, strict=True)
217217
if not (
218-
spec.mutable or has_destroy_handler and fgraph.has_destroyers([input])
218+
spec.mutable or (has_destroy_handler and fgraph.has_destroyers([input]))
219219
)
220220
)
221221
)

pytensor/link/c/type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def get_aliases(self):
481481
return tuple(sorted(self.aliases))
482482

483483
def __repr__(self):
484-
names_to_aliases = {constant_name: "" for constant_name in self}
484+
names_to_aliases = dict.fromkeys(self, "")
485485
for alias in self.aliases:
486486
names_to_aliases[self.aliases[alias]] = f"({alias})"
487487
args = ", ".join(f"{k}{names_to_aliases[k]}:{self[k]}" for k in sorted(self))

pytensor/misc/ordered_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(self, iterable: Iterable | None = None) -> None:
99
if iterable is None:
1010
self.values = {}
1111
else:
12-
self.values = {value: None for value in iterable}
12+
self.values = dict.fromkeys(iterable)
1313

1414
def __contains__(self, value) -> bool:
1515
return value in self.values

pytensor/printing.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ def debugprint(
295295
if hasattr(var.owner, "op"):
296296
if (
297297
isinstance(var.owner.op, HasInnerGraph)
298-
or hasattr(var.owner.op, "scalar_op")
299-
and isinstance(var.owner.op.scalar_op, HasInnerGraph)
298+
or (
299+
hasattr(var.owner.op, "scalar_op")
300+
and isinstance(var.owner.op.scalar_op, HasInnerGraph)
301+
)
300302
) and var not in inner_graph_vars:
301303
inner_graph_vars.append(var)
302304
if print_op_info:
@@ -675,8 +677,10 @@ def get_id_str(
675677
if hasattr(in_var, "owner") and hasattr(in_var.owner, "op"):
676678
if (
677679
isinstance(in_var.owner.op, HasInnerGraph)
678-
or hasattr(in_var.owner.op, "scalar_op")
679-
and isinstance(in_var.owner.op.scalar_op, HasInnerGraph)
680+
or (
681+
hasattr(in_var.owner.op, "scalar_op")
682+
and isinstance(in_var.owner.op.scalar_op, HasInnerGraph)
683+
)
680684
) and in_var not in inner_graph_ops:
681685
inner_graph_ops.append(in_var)
682686

@@ -882,7 +886,9 @@ def process(self, output, pstate):
882886
max_i = len(node.inputs) - 1
883887
for i, input in enumerate(node.inputs):
884888
new_precedence = self.precedence
885-
if self.assoc == "left" and i != 0 or self.assoc == "right" and i != max_i:
889+
if (self.assoc == "left" and i != 0) or (
890+
self.assoc == "right" and i != max_i
891+
):
886892
new_precedence += 1e-6
887893

888894
with set_precedence(pstate, new_precedence):

pytensor/scalar/loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def c_code_template(self):
219219
for i, c in enumerate(fgraph.inputs[n_update:], start=n_update + 1)
220220
}
221221
out_subd = {u: f"%(o{i})s" for i, u in enumerate(fgraph.outputs[:n_update])}
222-
until_subd = {u: "until" for u in fgraph.outputs[n_update:]}
222+
until_subd = dict.fromkeys(fgraph.outputs[n_update:], "until")
223223
subd = {**carry_subd, **constant_subd, **until_subd}
224224

225225
for var in fgraph.variables:

pytensor/tensor/basic.py

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4577,73 +4577,73 @@ def ix_(*args):
45774577

45784578

45794579
__all__ = [
4580-
"take_along_axis",
4581-
"expand_dims",
4582-
"atleast_Nd",
4580+
"alloc",
4581+
"arange",
4582+
"as_tensor",
4583+
"as_tensor_variable",
45834584
"atleast_1d",
45844585
"atleast_2d",
45854586
"atleast_3d",
4587+
"atleast_Nd",
4588+
"cast",
45864589
"choose",
4587-
"swapaxes",
4588-
"moveaxis",
4589-
"stacklists",
4590+
"concatenate",
4591+
"constant",
4592+
"default",
45904593
"diag",
45914594
"diagonal",
4592-
"inverse_permutation",
4593-
"permute_row_elements",
4594-
"mgrid",
4595-
"ogrid",
4596-
"arange",
4597-
"tile",
4595+
"empty",
4596+
"empty_like",
4597+
"expand_dims",
4598+
"extract_diag",
4599+
"eye",
4600+
"fill",
4601+
"flatnonzero",
45984602
"flatten",
4599-
"is_flat",
4600-
"vertical_stack",
4601-
"horizontal_stack",
4603+
"full",
4604+
"full_like",
4605+
"get_scalar_constant_value",
4606+
"get_underlying_scalar_constant_value",
46024607
"get_vector_length",
4603-
"concatenate",
4604-
"stack",
4605-
"roll",
4606-
"join",
4607-
"split",
4608-
"transpose",
4609-
"matrix_transpose",
4610-
"default",
4611-
"tensor_copy",
4608+
"horizontal_stack",
46124609
"identity",
4613-
"transfer",
4614-
"alloc",
46154610
"identity_like",
4616-
"eye",
4617-
"triu",
4618-
"tril",
4619-
"tri",
4620-
"nonzero_values",
4621-
"flatnonzero",
4611+
"inverse_permutation",
4612+
"is_flat",
4613+
"join",
4614+
"matrix_transpose",
4615+
"mgrid",
4616+
"moveaxis",
46224617
"nonzero",
4618+
"nonzero_values",
4619+
"ogrid",
46234620
"ones",
4624-
"zeros",
4625-
"zeros_like",
46264621
"ones_like",
4627-
"fill",
4622+
"permute_row_elements",
4623+
"roll",
4624+
"scalar_from_tensor",
46284625
"second",
4629-
"where",
4626+
"split",
4627+
"stack",
4628+
"stacklists",
4629+
"swapaxes",
46304630
"switch",
4631-
"cast",
4632-
"scalar_from_tensor",
4631+
"take_along_axis",
4632+
"tensor_copy",
46334633
"tensor_from_scalar",
4634-
"get_scalar_constant_value",
4635-
"get_underlying_scalar_constant_value",
4636-
"constant",
4637-
"as_tensor_variable",
4638-
"as_tensor",
4639-
"extract_diag",
4640-
"full",
4641-
"full_like",
4642-
"empty",
4643-
"empty_like",
4634+
"tile",
46444635
"trace",
4636+
"transfer",
4637+
"transpose",
4638+
"tri",
4639+
"tril",
46454640
"tril_indices",
46464641
"tril_indices_from",
4642+
"triu",
46474643
"triu_indices",
46484644
"triu_indices_from",
4645+
"vertical_stack",
4646+
"where",
4647+
"zeros",
4648+
"zeros_like",
46494649
]

pytensor/tensor/elemwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def _c_all(self, node, nodename, inames, onames, sub):
821821
# for each input:
822822
# same as range(ndim), but with 'x' at all broadcastable positions
823823
orders = [
824-
[s == 1 and "x" or i for i, s in enumerate(input.type.shape)]
824+
[(s == 1 and "x") or i for i, s in enumerate(input.type.shape)]
825825
for input in inputs
826826
]
827827

pytensor/tensor/extra_ops.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ def broadcast_shape_iter(
15581558
(one,) * (max_dims - len(a))
15591559
+ tuple(
15601560
one
1561-
if sh == 1 or isinstance(sh, Constant) and sh.value == 1
1561+
if sh == 1 or (isinstance(sh, Constant) and sh.value == 1)
15621562
else (ps.as_scalar(sh) if not isinstance(sh, Variable) else sh)
15631563
for sh in a
15641564
)
@@ -2067,25 +2067,25 @@ def concat_with_broadcast(tensor_list, axis=0):
20672067

20682068

20692069
__all__ = [
2070-
"searchsorted",
2071-
"cumsum",
2072-
"cumprod",
2073-
"diff",
2074-
"bincount",
2075-
"squeeze",
2076-
"compress",
2077-
"repeat",
20782070
"bartlett",
2079-
"fill_diagonal",
2080-
"fill_diagonal_offset",
2081-
"unique",
2082-
"unravel_index",
2083-
"ravel_multi_index",
2071+
"bincount",
2072+
"broadcast_arrays",
20842073
"broadcast_shape",
20852074
"broadcast_to",
2075+
"compress",
20862076
"concat_with_broadcast",
2077+
"cumprod",
2078+
"cumsum",
2079+
"diff",
2080+
"fill_diagonal",
2081+
"fill_diagonal_offset",
20872082
"geomspace",
2088-
"logspace",
20892083
"linspace",
2090-
"broadcast_arrays",
2084+
"logspace",
2085+
"ravel_multi_index",
2086+
"repeat",
2087+
"searchsorted",
2088+
"squeeze",
2089+
"unique",
2090+
"unravel_index",
20912091
]

0 commit comments

Comments
 (0)