未验证 提交 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: ...@@ -109,7 +109,7 @@ class ProcessGroup:
not self.is_instantiate() not self.is_instantiate()
), "Cannot add new ranks after instantiating the process group" ), "Cannot add new ranks after instantiating the process group"
self._ranks.extend(new_ranks) self._ranks.extend(new_ranks)
self._ranks = sorted(list(set(self.ranks))) self._ranks = sorted(set(self.ranks))
def local_rank(self, global_rank): def local_rank(self, global_rank):
if global_rank in self.ranks: if global_rank in self.ranks:
......
...@@ -750,7 +750,7 @@ class OperatorClusteringUtil: ...@@ -750,7 +750,7 @@ class OperatorClusteringUtil:
@staticmethod @staticmethod
def get_ranks(seq): def get_ranks(seq):
"""Get rank array of the given seq by doubled algorithm.""" """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)} item_to_rank = {item: idx for idx, item in enumerate(ordered_seq)}
inter_ranks = [item_to_rank[item] for item in seq] inter_ranks = [item_to_rank[item] for item in seq]
......
...@@ -99,7 +99,7 @@ class RecomputeState(ProgramStats): ...@@ -99,7 +99,7 @@ class RecomputeState(ProgramStats):
segments.append([segment_idx[0], segment_idx[-1] + 1]) segments.append([segment_idx[0], segment_idx[-1] + 1])
self._checkpoints.extend(self.ops[segment_idx[-1]].output_arg_names) 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( assert i < len(
segments segments
), "the no_recompute_segments idx [{}] should be lower the number of segment [{}]".format( ), "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): ...@@ -271,7 +271,7 @@ def dynamic_flops(model, inputs, custom_ops=None, print_detail=False):
'total_params', 'total_params',
'input_shape', 'input_shape',
'output_shape', 'output_shape',
}.issubset(set(list(m._buffers.keys()))): }.issubset(set(m._buffers.keys())):
total_ops += m.total_ops total_ops += m.total_ops
total_params += m.total_params total_params += m.total_params
...@@ -292,7 +292,7 @@ def dynamic_flops(model, inputs, custom_ops=None, print_detail=False): ...@@ -292,7 +292,7 @@ def dynamic_flops(model, inputs, custom_ops=None, print_detail=False):
'total_params', 'total_params',
'input_shape', 'input_shape',
'output_shape', 'output_shape',
}.issubset(set(list(m._buffers.keys()))): }.issubset(set(m._buffers.keys())):
table.add_row( table.add_row(
[ [
m.full_name(), m.full_name(),
......
...@@ -339,8 +339,8 @@ def transform_if_else(node, root): ...@@ -339,8 +339,8 @@ def transform_if_else(node, root):
""" """
# TODO(liym27): Consider variable like `self.a` modified in if/else node. # TODO(liym27): Consider variable like `self.a` modified in if/else node.
return_name_ids = sorted(list(node.pd_scope.modified_vars())) return_name_ids = sorted(node.pd_scope.modified_vars())
push_pop_ids = sorted(list(node.pd_scope.variadic_length_vars())) push_pop_ids = sorted(node.pd_scope.variadic_length_vars())
nonlocal_names = list(return_name_ids) nonlocal_names = list(return_name_ids)
nonlocal_names.sort() nonlocal_names.sort()
# NOTE: All var in return_name_ids should be in nonlocal_names. # NOTE: All var in return_name_ids should be in nonlocal_names.
......
...@@ -157,7 +157,7 @@ class Cifar10(Dataset): ...@@ -157,7 +157,7 @@ class Cifar10(Dataset):
each_item.name for each_item in f if self.flag in each_item.name 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: for name in names:
batch = pickle.load(f.extractfile(name), encoding='bytes') batch = pickle.load(f.extractfile(name), encoding='bytes')
......
...@@ -164,7 +164,7 @@ def get_all_api(root_path='paddle', attr="__all__"): ...@@ -164,7 +164,7 @@ def get_all_api(root_path='paddle', attr="__all__"):
) )
return [ 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() for api_info in api_info_dict.values()
] ]
...@@ -380,7 +380,7 @@ if __name__ == '__main__': ...@@ -380,7 +380,7 @@ if __name__ == '__main__':
for k, api_info in api_info_dict.items(): for k, api_info in api_info_dict.items():
# 1. the shortest suggested_name may be renamed; # 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; # 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_to_k[api_name] = k
all_api_names_sorted = sorted(all_api_names_to_k.keys()) all_api_names_sorted = sorted(all_api_names_to_k.keys())
for api_name in all_api_names_sorted: 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.
先完成此消息的编辑!
想要评论请 注册