未验证 提交 af6f262d 编写于 作者: I Infinity_lee 提交者: GitHub

[CodeStyle][C413][C414] Unnecessary <list/reversed> call around...

[CodeStyle][C413][C414] Unnecessary <list/reversed> call around sorted(),<list/reversed/set/sorted/tuple> call within <list/set/sorted/tuple>() (#52065)
上级 e1674e8b
......@@ -109,7 +109,7 @@ class ProcessGroup:
not self.is_instantiate()
), "Cannot add new ranks after instantiating the process group"
self._ranks.extend(new_ranks)
self._ranks = sorted(list(set(self.ranks)))
self._ranks = sorted(set(self.ranks))
def local_rank(self, global_rank):
if global_rank in self.ranks:
......
......@@ -750,7 +750,7 @@ class OperatorClusteringUtil:
@staticmethod
def get_ranks(seq):
"""Get rank array of the given seq by doubled algorithm."""
ordered_seq = sorted(list(set(seq)))
ordered_seq = sorted(set(seq))
item_to_rank = {item: idx for idx, item in enumerate(ordered_seq)}
inter_ranks = [item_to_rank[item] for item in seq]
......
......@@ -99,7 +99,7 @@ class RecomputeState(ProgramStats):
segments.append([segment_idx[0], segment_idx[-1] + 1])
self._checkpoints.extend(self.ops[segment_idx[-1]].output_arg_names)
for i in reversed(sorted(no_recompute_segments)):
for i in sorted(no_recompute_segments, reverse=True):
assert i < len(
segments
), "the no_recompute_segments idx [{}] should be lower the number of segment [{}]".format(
......
......@@ -271,7 +271,7 @@ def dynamic_flops(model, inputs, custom_ops=None, print_detail=False):
'total_params',
'input_shape',
'output_shape',
}.issubset(set(list(m._buffers.keys()))):
}.issubset(set(m._buffers.keys())):
total_ops += m.total_ops
total_params += m.total_params
......@@ -292,7 +292,7 @@ def dynamic_flops(model, inputs, custom_ops=None, print_detail=False):
'total_params',
'input_shape',
'output_shape',
}.issubset(set(list(m._buffers.keys()))):
}.issubset(set(m._buffers.keys())):
table.add_row(
[
m.full_name(),
......
......@@ -339,8 +339,8 @@ def transform_if_else(node, root):
"""
# TODO(liym27): Consider variable like `self.a` modified in if/else node.
return_name_ids = sorted(list(node.pd_scope.modified_vars()))
push_pop_ids = sorted(list(node.pd_scope.variadic_length_vars()))
return_name_ids = sorted(node.pd_scope.modified_vars())
push_pop_ids = sorted(node.pd_scope.variadic_length_vars())
nonlocal_names = list(return_name_ids)
nonlocal_names.sort()
# NOTE: All var in return_name_ids should be in nonlocal_names.
......
......@@ -157,7 +157,7 @@ class Cifar10(Dataset):
each_item.name for each_item in f if self.flag in each_item.name
)
names = sorted(list(names))
names = sorted(names)
for name in names:
batch = pickle.load(f.extractfile(name), encoding='bytes')
......
......@@ -164,7 +164,7 @@ def get_all_api(root_path='paddle', attr="__all__"):
)
return [
(sorted(list(api_info['all_names']))[0], md5(api_info['docstring']))
(sorted(api_info['all_names'])[0], md5(api_info['docstring']))
for api_info in api_info_dict.values()
]
......@@ -380,7 +380,7 @@ if __name__ == '__main__':
for k, api_info in api_info_dict.items():
# 1. the shortest suggested_name may be renamed;
# 2. some api's fullname is not accessable, the module name of it is overrided by the function with the same name;
api_name = sorted(list(api_info['all_names']))[0]
api_name = sorted(api_info['all_names'])[0]
all_api_names_to_k[api_name] = k
all_api_names_sorted = sorted(all_api_names_to_k.keys())
for api_name in all_api_names_sorted:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册