Skip to content

Commit

Permalink
[BE]: FURB187 Use inplace reverse on lists: faster, more readable. (#…
Browse files Browse the repository at this point in the history
…121140)

Use `reverse()` method as it's faster and inplace.

Pull Request resolved: #121140
Approved by: https://github.com/albanD
  • Loading branch information
Skylion007 authored and pytorchmergebot committed Mar 5, 2024
1 parent ec4146c commit 9deaa2e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion torch/_dynamo/bytecode_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def encode_exception_table_varint(n: int) -> List[int]:
while n > 0:
b.append(n & 63)
n >>= 6
b = list(reversed(b))
b.reverse()
for i in range(len(b) - 1):
b[i] |= 64
return b
Expand Down
2 changes: 1 addition & 1 deletion torch/_inductor/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,7 @@ def _dynamic_reshape_indexer(old_size, new_size):
var, size_new = stack_new.pop()
V.graph.sizevars.guard_equals(size_new, 1) # type: ignore[arg-type]

view_expr = list(reversed(view_expr))
view_expr.reverse()
assert len(view_expr) == len(old_size)

def reindex(index):
Expand Down
4 changes: 2 additions & 2 deletions torch/cuda/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ def make_graphed_callables(
per_callable_static_grad_inputs.append(static_grad_inputs)

# Reverses the most recent two lists
per_callable_static_grad_outputs = list(reversed(per_callable_static_grad_outputs))
per_callable_static_grad_inputs = list(reversed(per_callable_static_grad_inputs))
per_callable_static_grad_outputs.reverse()
per_callable_static_grad_inputs.reverse()
# Now for every per_callable list, per_callable_*[i] holds the stuff for the ith callable.

def make_graphed_autograd_function(
Expand Down

0 comments on commit 9deaa2e

Please sign in to comment.