未验证 提交 df6c74c3 编写于 作者: C cyberslack_lee 提交者: GitHub

[CodeStyle][CINN] fix Ruff lint errors (flake8-comprehensions rules) (#55087)

上级 2265d7bc
...@@ -107,14 +107,12 @@ ignore = [ ...@@ -107,14 +107,12 @@ ignore = [
"F403", "F403",
"F632", "F632",
"F811", "F811",
"C408",
"C417",
"PLR0402", "PLR0402",
"PLC0414", "PLC0414",
"PLE1205", "PLE1205",
] ]
"tools/cinn/**" = [ "tools/cinn/**" = [
"F401", "F401",
"C416",
"PLR0402", "PLR0402",
] ]
...@@ -26,7 +26,7 @@ class FusionTest(PassTest): ...@@ -26,7 +26,7 @@ class FusionTest(PassTest):
def init_input_data(self): def init_input_data(self):
"""Set feed data""" """Set feed data"""
self.feed_data = dict() self.feed_data = {}
logger.warn("No Input Data") logger.warn("No Input Data")
def build_program(self, builder, target): def build_program(self, builder, target):
......
...@@ -77,7 +77,7 @@ class OpMapperTest(OpTest): ...@@ -77,7 +77,7 @@ class OpMapperTest(OpTest):
x2 = paddle.static.data(name='x2', shape=[1, 2], dtype='float32') x2 = paddle.static.data(name='x2', shape=[1, 2], dtype='float32')
return {'X' : [x1, x2]} return {'X' : [x1, x2]}
```""" ```"""
return dict() return {}
def set_op_attrs(self) -> dict: def set_op_attrs(self) -> dict:
"""Map from attribute name to attribute value:\n """Map from attribute name to attribute value:\n
...@@ -86,7 +86,7 @@ class OpMapperTest(OpTest): ...@@ -86,7 +86,7 @@ class OpMapperTest(OpTest):
return {'axis' : 0} return {'axis' : 0}
``` ```
""" """
return dict() return {}
def set_op_outputs(self) -> dict: def set_op_outputs(self) -> dict:
"""Map from output parameter name to argument type, the argument type should be represented by a string.\n """Map from output parameter name to argument type, the argument type should be represented by a string.\n
...@@ -113,7 +113,7 @@ class OpMapperTest(OpTest): ...@@ -113,7 +113,7 @@ class OpMapperTest(OpTest):
return {'MeanOut' : 'Mean'} return {'MeanOut' : 'Mean'}
``` ```
""" """
return dict() return {}
def __set_paddle_op(self): def __set_paddle_op(self):
# paddle C++ op type # paddle C++ op type
...@@ -130,8 +130,8 @@ class OpMapperTest(OpTest): ...@@ -130,8 +130,8 @@ class OpMapperTest(OpTest):
self.inplace_outputs = self.set_inplace_outputs() self.inplace_outputs = self.set_inplace_outputs()
# collect some important infomation # collect some important infomation
self.input_arg_map = self.__get_arguments_map(self.inputs) self.input_arg_map = self.__get_arguments_map(self.inputs)
self.fetch_targets = list() self.fetch_targets = []
self.skip_check_list = list() self.skip_check_list = []
self.op_desc = None self.op_desc = None
def __check_valid(self): def __check_valid(self):
...@@ -194,7 +194,7 @@ class OpMapperTest(OpTest): ...@@ -194,7 +194,7 @@ class OpMapperTest(OpTest):
) )
def __get_arguments_map(self, param_maps): def __get_arguments_map(self, param_maps):
arg_maps = dict() arg_maps = {}
for args in param_maps.values(): for args in param_maps.values():
self.assertIsInstance( self.assertIsInstance(
args, args,
...@@ -219,7 +219,7 @@ class OpMapperTest(OpTest): ...@@ -219,7 +219,7 @@ class OpMapperTest(OpTest):
self.__check_valid() self.__check_valid()
def __remove_skip_outputs(self, results): def __remove_skip_outputs(self, results):
check_outputs = list() check_outputs = []
for i in range(len(self.fetch_targets)): for i in range(len(self.fetch_targets)):
if self.fetch_targets[i].name not in self.skip_check_list: if self.fetch_targets[i].name not in self.skip_check_list:
check_outputs.append(results[i]) check_outputs.append(results[i])
...@@ -259,14 +259,14 @@ class OpMapperTest(OpTest): ...@@ -259,14 +259,14 @@ class OpMapperTest(OpTest):
self.__init_paddle_op() self.__init_paddle_op()
helper = LayerHelper(self.op_type) helper = LayerHelper(self.op_type)
self.outputs = dict() self.outputs = {}
for var_name, dtypes in self.output_dtypes.items(): for var_name, dtypes in self.output_dtypes.items():
self.assertIsInstance( self.assertIsInstance(
dtypes, dtypes,
list, list,
msg="The set_op_outputs should be return dict(OutName, list(OutDtype)), where OutName and OutDtype are string", msg="The set_op_outputs should be return dict(OutName, list(OutDtype)), where OutName and OutDtype are string",
) )
self.outputs[var_name] = list() self.outputs[var_name] = []
for dtype in dtypes: for dtype in dtypes:
out_var = helper.create_variable_for_type_inference(dtype) out_var = helper.create_variable_for_type_inference(dtype)
self.fetch_targets.append(out_var) self.fetch_targets.append(out_var)
...@@ -356,7 +356,7 @@ class OpMapperTest(OpTest): ...@@ -356,7 +356,7 @@ class OpMapperTest(OpTest):
cinn_feed_datas.append(self.feed_data[name]) cinn_feed_datas.append(self.feed_data[name])
# get the CINN output list # get the CINN output list
fetch_names = list() fetch_names = []
inplace_start = 0 inplace_start = 0
for dtypes in self.output_dtypes.values(): for dtypes in self.output_dtypes.values():
inplace_start += len(dtypes) inplace_start += len(dtypes)
...@@ -374,7 +374,7 @@ class OpMapperTest(OpTest): ...@@ -374,7 +374,7 @@ class OpMapperTest(OpTest):
self.assertGreater( self.assertGreater(
len(fetch_names), 0, msg="The program's output cannot be empty!" len(fetch_names), 0, msg="The program's output cannot be empty!"
) )
cinn_output_vars = list() cinn_output_vars = []
for name in fetch_names: for name in fetch_names:
cinn_name = convertor.get_cinn_name(name) cinn_name = convertor.get_cinn_name(name)
...@@ -394,7 +394,7 @@ class OpMapperTest(OpTest): ...@@ -394,7 +394,7 @@ class OpMapperTest(OpTest):
cinn_inputs, cinn_inputs,
cinn_feed_datas, cinn_feed_datas,
cinn_output_vars, cinn_output_vars,
passes=list(), passes=[],
scope=scope, scope=scope,
) )
...@@ -403,7 +403,7 @@ class OpMapperTest(OpTest): ...@@ -403,7 +403,7 @@ class OpMapperTest(OpTest):
@staticmethod @staticmethod
def get_program_vars(program) -> dict: def get_program_vars(program) -> dict:
vars = dict() vars = {}
for i in range(program.size()): for i in range(program.size()):
instr = program[i] instr = program[i]
for var in instr.get_inputs(): for var in instr.get_inputs():
......
...@@ -53,7 +53,7 @@ class TestFillConstantOp(OpMapperTest): ...@@ -53,7 +53,7 @@ class TestFillConstantOp(OpMapperTest):
class TestFillConstantCase1(TestFillConstantOp): class TestFillConstantCase1(TestFillConstantOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [10, 10] self.shape = [10, 10]
self.value = np.random.default_rng(12345).integers(low=0, high=10000) self.value = np.random.default_rng(12345).integers(low=0, high=10000)
self.str_value = "" self.str_value = ""
...@@ -62,7 +62,7 @@ class TestFillConstantCase1(TestFillConstantOp): ...@@ -62,7 +62,7 @@ class TestFillConstantCase1(TestFillConstantOp):
class TestFillConstantCase2(TestFillConstantOp): class TestFillConstantCase2(TestFillConstantOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [10, 10] self.shape = [10, 10]
self.value = 0 self.value = 0
self.str_value = "0.123456" self.str_value = "0.123456"
......
...@@ -24,7 +24,7 @@ import paddle ...@@ -24,7 +24,7 @@ import paddle
class TestGaussianRandomOp(OpMapperTest): class TestGaussianRandomOp(OpMapperTest):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3] self.shape = [2, 3]
self.mean = 0.0 self.mean = 0.0
self.std = 1.0 self.std = 1.0
...@@ -59,7 +59,7 @@ class TestGaussianRandomOp(OpMapperTest): ...@@ -59,7 +59,7 @@ class TestGaussianRandomOp(OpMapperTest):
class TestGaussianRandomCase1(TestGaussianRandomOp): class TestGaussianRandomCase1(TestGaussianRandomOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3, 4] self.shape = [2, 3, 4]
self.mean = 1.0 self.mean = 1.0
self.std = 2.0 self.std = 2.0
...@@ -69,7 +69,7 @@ class TestGaussianRandomCase1(TestGaussianRandomOp): ...@@ -69,7 +69,7 @@ class TestGaussianRandomCase1(TestGaussianRandomOp):
class TestGaussianRandomCase2(TestGaussianRandomOp): class TestGaussianRandomCase2(TestGaussianRandomOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3, 4] self.shape = [2, 3, 4]
self.mean = 2.0 self.mean = 2.0
self.std = 3.0 self.std = 3.0
......
...@@ -24,7 +24,7 @@ import paddle ...@@ -24,7 +24,7 @@ import paddle
class TestRandIntOp(OpMapperTest): class TestRandIntOp(OpMapperTest):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3] self.shape = [2, 3]
self.min = 1 self.min = 1
self.max = 5 self.max = 5
...@@ -61,7 +61,7 @@ class TestRandIntOp(OpMapperTest): ...@@ -61,7 +61,7 @@ class TestRandIntOp(OpMapperTest):
class TestRandIntCase1(TestRandIntOp): class TestRandIntCase1(TestRandIntOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3, 4] self.shape = [2, 3, 4]
self.min = 1 self.min = 1
self.max = 9 self.max = 9
...@@ -71,7 +71,7 @@ class TestRandIntCase1(TestRandIntOp): ...@@ -71,7 +71,7 @@ class TestRandIntCase1(TestRandIntOp):
class TestRandIntCase2(TestRandIntOp): class TestRandIntCase2(TestRandIntOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3, 4] self.shape = [2, 3, 4]
self.min = 1 self.min = 1
self.max = 9 self.max = 9
......
...@@ -24,7 +24,7 @@ import paddle ...@@ -24,7 +24,7 @@ import paddle
class TestUniformRandomOp(OpMapperTest): class TestUniformRandomOp(OpMapperTest):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3] self.shape = [2, 3]
self.min = -1.0 self.min = -1.0
self.max = 1.0 self.max = 1.0
...@@ -65,7 +65,7 @@ class TestUniformRandomOp(OpMapperTest): ...@@ -65,7 +65,7 @@ class TestUniformRandomOp(OpMapperTest):
class TestUniformRandomCase1(TestUniformRandomOp): class TestUniformRandomCase1(TestUniformRandomOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3, 4] self.shape = [2, 3, 4]
self.min = -5.5 self.min = -5.5
self.max = 5.5 self.max = 5.5
...@@ -78,7 +78,7 @@ class TestUniformRandomCase1(TestUniformRandomOp): ...@@ -78,7 +78,7 @@ class TestUniformRandomCase1(TestUniformRandomOp):
class TestUniformRandomCase2(TestUniformRandomOp): class TestUniformRandomCase2(TestUniformRandomOp):
def init_input_data(self): def init_input_data(self):
self.feed_data = dict() self.feed_data = {}
self.shape = [2, 3, 4] self.shape = [2, 3, 4]
self.min = -10.0 self.min = -10.0
self.max = 10.0 self.max = 10.0
......
...@@ -60,12 +60,7 @@ class TestClzOp(OpTest): ...@@ -60,12 +60,7 @@ class TestClzOp(OpTest):
low = INT32_MIN if dtype == "int32" else INT64_MIN low = INT32_MIN if dtype == "int32" else INT64_MIN
high = INT32_MAX if dtype == "int32" else INT64_MAX high = INT32_MAX if dtype == "int32" else INT64_MAX
x = self.random(self.case["shape"], dtype, low=low, high=high) x = self.random(self.case["shape"], dtype, low=low, high=high)
y = list( y = [count_leading_zeros(num, dtype) for num in x.reshape(-1).tolist()]
map(
lambda num: count_leading_zeros(num, dtype),
x.reshape(-1).tolist(),
)
)
self.inputs = {"x": x} self.inputs = {"x": x}
self.outputs = {"y": np.array(y).reshape(x.shape).astype(dtype)} self.outputs = {"y": np.array(y).reshape(x.shape).astype(dtype)}
......
...@@ -72,7 +72,7 @@ class TestMatmulOp(OpTest): ...@@ -72,7 +72,7 @@ class TestMatmulOp(OpTest):
out = self.cinn_func(builder, x, y) out = self.cinn_func(builder, x, y)
prog = builder.build() prog = builder.build()
res = self.get_cinn_output( res = self.get_cinn_output(
prog, target, [x, y], [self.x_np, self.y_np], [out], passes=list() prog, target, [x, y], [self.x_np, self.y_np], [out], passes=[]
) )
self.cinn_outputs = res self.cinn_outputs = res
......
...@@ -61,7 +61,7 @@ class TestPopcOp(OpTest): ...@@ -61,7 +61,7 @@ class TestPopcOp(OpTest):
low = INT32_MIN if dtype == "int32" else INT64_MIN low = INT32_MIN if dtype == "int32" else INT64_MIN
high = INT32_MAX if dtype == "int32" else INT64_MAX high = INT32_MAX if dtype == "int32" else INT64_MAX
x = self.random(self.case["shape"], dtype, low=low, high=high) x = self.random(self.case["shape"], dtype, low=low, high=high)
y = list(map(lambda num: popcount(num, dtype), x.reshape(-1).tolist())) y = [popcount(num, dtype) for num in x.reshape(-1).tolist()]
self.inputs = {"x": x} self.inputs = {"x": x}
self.outputs = {"y": np.array(y).reshape(x.shape).astype(dtype)} self.outputs = {"y": np.array(y).reshape(x.shape).astype(dtype)}
......
...@@ -34,7 +34,7 @@ class PassTest(OpTest): ...@@ -34,7 +34,7 @@ class PassTest(OpTest):
def init_input_data(self) -> dict: def init_input_data(self) -> dict:
"""Set feed data""" """Set feed data"""
self.feed_data = dict() self.feed_data = {}
logger.warn("No Input Data") logger.warn("No Input Data")
def build_program(self, builder, target): def build_program(self, builder, target):
...@@ -64,7 +64,7 @@ class PassTest(OpTest): ...@@ -64,7 +64,7 @@ class PassTest(OpTest):
def get_pass_outputs(self, passes): def get_pass_outputs(self, passes):
pass_prog, inputs, outputs = self.run_program() pass_prog, inputs, outputs = self.run_program()
feed_list = list() feed_list = []
for var in inputs: for var in inputs:
self.assertIn( self.assertIn(
var.name(), var.name(),
......
...@@ -128,7 +128,7 @@ class TestPaddleModel(OpMapperTest): ...@@ -128,7 +128,7 @@ class TestPaddleModel(OpMapperTest):
return attr_map return attr_map
def init_case(self): def init_case(self):
self.feed_data = dict() self.feed_data = {}
for i in range(len(self.feed_names)): for i in range(len(self.feed_names)):
# check no repeat variable # check no repeat variable
self.assertNotIn( self.assertNotIn(
...@@ -208,7 +208,7 @@ class TestPaddleModel(OpMapperTest): ...@@ -208,7 +208,7 @@ class TestPaddleModel(OpMapperTest):
msg="CINN only support single block now", msg="CINN only support single block now",
) )
feed_with_param = list() feed_with_param = []
convertor = PaddleModelConvertor(target) convertor = PaddleModelConvertor(target)
for i in range(len(self.feed_names)): for i in range(len(self.feed_names)):
......
...@@ -201,7 +201,7 @@ if __name__ == '__main__': ...@@ -201,7 +201,7 @@ if __name__ == '__main__':
class Content(ContentGenerator): class Content(ContentGenerator):
def __init__(self): def __init__(self):
self.lines = [line for line in sys.stdin] self.lines = list(sys.stdin)
self.cur = 0 self.cur = 0
def has_next(self): def has_next(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册