Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ ignore = [
"F811",
"F821",
"F901",
"C408",
"C417",
enkilee marked this conversation as resolved.
Show resolved Hide resolved
"PLR0402",
"PLC0414",
"PLE1205",
]
"tools/cinn/**" = [
"F401",
"C416",
"PLR0402",

]
2 changes: 1 addition & 1 deletion test/cinn/fusion/fusion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, *args, **kwargs):

def init_input_data(self):
"""Set feed data"""
self.feed_data = dict()
self.feed_data = {}
logger.warn("No Input Data")

def build_program(self, builder, target):
Expand Down
26 changes: 13 additions & 13 deletions test/cinn/op_mappers/op_mapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def set_op_inputs(self) -> dict:
x2 = paddle.static.data(name='x2', shape=[1, 2], dtype='float32')
return {'X' : [x1, x2]}
```"""
return dict()
return {}

def set_op_attrs(self) -> dict:
"""Map from attribute name to attribute value:\n
Expand All @@ -86,7 +86,7 @@ def set_op_attrs(self) -> dict:
return {'axis' : 0}
```
"""
return dict()
return {}

def set_op_outputs(self) -> dict:
"""Map from output parameter name to argument type, the argument type should be represented by a string.\n
Expand All @@ -113,7 +113,7 @@ def set_inplace_outputs(self) -> dict:
return {'MeanOut' : 'Mean'}
```
"""
return dict()
return {}

def __set_paddle_op(self):
# paddle C++ op type
Expand All @@ -130,8 +130,8 @@ def __set_paddle_op(self):
self.inplace_outputs = self.set_inplace_outputs()
# collect some important infomation
self.input_arg_map = self.__get_arguments_map(self.inputs)
self.fetch_targets = list()
self.skip_check_list = list()
self.fetch_targets = []
self.skip_check_list = []
self.op_desc = None

def __check_valid(self):
Expand Down Expand Up @@ -194,7 +194,7 @@ def __check_valid(self):
)

def __get_arguments_map(self, param_maps):
arg_maps = dict()
arg_maps = {}
for args in param_maps.values():
self.assertIsInstance(
args,
Expand All @@ -219,7 +219,7 @@ def __init_paddle_op(self):
self.__check_valid()

def __remove_skip_outputs(self, results):
check_outputs = list()
check_outputs = []
for i in range(len(self.fetch_targets)):
if self.fetch_targets[i].name not in self.skip_check_list:
check_outputs.append(results[i])
Expand Down Expand Up @@ -259,14 +259,14 @@ def build_paddle_program(self, target):
self.__init_paddle_op()
helper = LayerHelper(self.op_type)

self.outputs = dict()
self.outputs = {}
for var_name, dtypes in self.output_dtypes.items():
self.assertIsInstance(
dtypes,
list,
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:
out_var = helper.create_variable_for_type_inference(dtype)
self.fetch_targets.append(out_var)
Expand Down Expand Up @@ -356,7 +356,7 @@ def build_cinn_program(self, target):
cinn_feed_datas.append(self.feed_data[name])

# get the CINN output list
fetch_names = list()
fetch_names = []
inplace_start = 0
for dtypes in self.output_dtypes.values():
inplace_start += len(dtypes)
Expand All @@ -374,7 +374,7 @@ def build_cinn_program(self, target):
self.assertGreater(
len(fetch_names), 0, msg="The program's output cannot be empty!"
)
cinn_output_vars = list()
cinn_output_vars = []
for name in fetch_names:
cinn_name = convertor.get_cinn_name(name)

Expand All @@ -394,7 +394,7 @@ def build_cinn_program(self, target):
cinn_inputs,
cinn_feed_datas,
cinn_output_vars,
passes=list(),
passes=[],
scope=scope,
)

Expand All @@ -403,7 +403,7 @@ def build_cinn_program(self, target):

@staticmethod
def get_program_vars(program) -> dict:
vars = dict()
vars = {}
for i in range(program.size()):
instr = program[i]
for var in instr.get_inputs():
Expand Down
4 changes: 2 additions & 2 deletions test/cinn/op_mappers/test_fill_constant_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_check_results(self):

class TestFillConstantCase1(TestFillConstantOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [10, 10]
self.value = np.random.default_rng(12345).integers(low=0, high=10000)
self.str_value = ""
Expand All @@ -62,7 +62,7 @@ def init_input_data(self):

class TestFillConstantCase2(TestFillConstantOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [10, 10]
self.value = 0
self.str_value = "0.123456"
Expand Down
6 changes: 3 additions & 3 deletions test/cinn/op_mappers/test_gaussian_random_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class TestGaussianRandomOp(OpMapperTest):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3]
self.mean = 0.0
self.std = 1.0
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_check_results(self):

class TestGaussianRandomCase1(TestGaussianRandomOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3, 4]
self.mean = 1.0
self.std = 2.0
Expand All @@ -69,7 +69,7 @@ def init_input_data(self):

class TestGaussianRandomCase2(TestGaussianRandomOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3, 4]
self.mean = 2.0
self.std = 3.0
Expand Down
6 changes: 3 additions & 3 deletions test/cinn/op_mappers/test_randint_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class TestRandIntOp(OpMapperTest):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3]
self.min = 1
self.max = 5
Expand Down Expand Up @@ -61,7 +61,7 @@ def test_check_results(self):

class TestRandIntCase1(TestRandIntOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3, 4]
self.min = 1
self.max = 9
Expand All @@ -71,7 +71,7 @@ def init_input_data(self):

class TestRandIntCase2(TestRandIntOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3, 4]
self.min = 1
self.max = 9
Expand Down
6 changes: 3 additions & 3 deletions test/cinn/op_mappers/test_uniform_random_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class TestUniformRandomOp(OpMapperTest):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3]
self.min = -1.0
self.max = 1.0
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_check_results(self):

class TestUniformRandomCase1(TestUniformRandomOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3, 4]
self.min = -5.5
self.max = 5.5
Expand All @@ -78,7 +78,7 @@ def init_input_data(self):

class TestUniformRandomCase2(TestUniformRandomOp):
def init_input_data(self):
self.feed_data = dict()
self.feed_data = {}
self.shape = [2, 3, 4]
self.min = -10.0
self.max = 10.0
Expand Down
7 changes: 1 addition & 6 deletions test/cinn/ops/test_clz_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ def prepare_inputs(self):
low = INT32_MIN if dtype == "int32" else INT64_MIN
high = INT32_MAX if dtype == "int32" else INT64_MAX
x = self.random(self.case["shape"], dtype, low=low, high=high)
y = list(
map(
lambda num: count_leading_zeros(num, dtype),
x.reshape(-1).tolist(),
)
)
y = [count_leading_zeros(num, dtype) for num in x.reshape(-1).tolist()]
self.inputs = {"x": x}
self.outputs = {"y": np.array(y).reshape(x.shape).astype(dtype)}

Expand Down
2 changes: 1 addition & 1 deletion test/cinn/ops/test_matmul_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def build_cinn_program(self, target):
out = self.cinn_func(builder, x, y)
prog = builder.build()
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

Expand Down
2 changes: 1 addition & 1 deletion test/cinn/ops/test_popc_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def prepare_inputs(self):
low = INT32_MIN if dtype == "int32" else INT64_MIN
high = INT32_MAX if dtype == "int32" else INT64_MAX
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.outputs = {"y": np.array(y).reshape(x.shape).astype(dtype)}

Expand Down
4 changes: 2 additions & 2 deletions test/cinn/passes/pass_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, *args, **kwargs):

def init_input_data(self) -> dict:
"""Set feed data"""
self.feed_data = dict()
self.feed_data = {}
logger.warn("No Input Data")

def build_program(self, builder, target):
Expand Down Expand Up @@ -64,7 +64,7 @@ def run_program(self):
def get_pass_outputs(self, passes):
pass_prog, inputs, outputs = self.run_program()

feed_list = list()
feed_list = []
for var in inputs:
self.assertIn(
var.name(),
Expand Down
4 changes: 2 additions & 2 deletions test/cinn/test_paddle_model_convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_paddle_op_attrs(self, op):
return attr_map

def init_case(self):
self.feed_data = dict()
self.feed_data = {}
for i in range(len(self.feed_names)):
# check no repeat variable
self.assertNotIn(
Expand Down Expand Up @@ -204,7 +204,7 @@ def build_cinn_program(self, target):
msg="CINN only support single block now",
)

feed_with_param = list()
feed_with_param = []

convertor = PaddleModelConvertor(target)
for i in range(len(self.feed_names)):
Expand Down
2 changes: 1 addition & 1 deletion tools/cinn/gen_c++_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def generate(self):

class Content(ContentGenerator):
def __init__(self):
self.lines = [line for line in sys.stdin]
self.lines = list(sys.stdin)
self.cur = 0

def has_next(self):
Expand Down