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

[CodeStyle][UP027] Replace unpacked list comprehension with a generator expression (#52025)

* codestyle up027

* add to pyproject.toml
上级 85e20755
......@@ -45,7 +45,7 @@ def parse_arg(op_name: str, s: str) -> Dict[str, str]:
1. typename name
2. typename name = default_value
"""
typename, rest = [item.strip() for item in s.split(" ", 1)]
typename, rest = (item.strip() for item in s.split(" ", 1))
assert (
len(typename) > 0
), f"The arg typename should not be empty. Please check the args of {op_name} in yaml."
......@@ -54,7 +54,7 @@ def parse_arg(op_name: str, s: str) -> Dict[str, str]:
rest.count("=") <= 1
), f"There is more than 1 = in an arg in {op_name}"
if rest.count("=") == 1:
name, default_value = [item.strip() for item in rest.split("=", 1)]
name, default_value = (item.strip() for item in rest.split("=", 1))
assert (
len(name) > 0
), f"The arg name should not be empty. Please check the args of {op_name} in yaml."
......
......@@ -66,7 +66,7 @@ select = [
"UP021",
"UP022",
"UP023",
# "UP024",
"UP024",
"UP025",
"UP026",
# "UP027",
......
......@@ -594,9 +594,9 @@ class TestLACModel(unittest.TestCase):
input=crf_decode, label=targets, seq_length=length
)
outputs = [avg_cost, precision, recall, f1_score]
avg_cost, precision, recall, f1_score = [
avg_cost, precision, recall, f1_score = (
np.mean(x.numpy()) for x in outputs
]
)
print(
"[train] step = %d, loss = %f, P: %f, R: %f, F1: %f, elapsed time %f"
......
......@@ -195,7 +195,7 @@ class TestDygraphDeepCF(unittest.TestCase):
num_items = -1
with open(self.data_path, 'r') as f:
for l in f.readlines():
uid, iid, rating = [int(v) for v in l.split('\t')]
uid, iid, rating = (int(v) for v in l.split('\t'))
num_users = max(num_users, uid + 1)
num_items = max(num_items, iid + 1)
if float(rating) > 0.0:
......
......@@ -67,9 +67,9 @@ class TestSampleLogitsOp(OpTest):
def test_check_output(self):
places = self._get_places()
for p in places:
(Samples, Probabilities, SampledLogits, SampledLabels) = [
(Samples, Probabilities, SampledLogits, SampledLabels) = (
np.array(o) for o in self.calc_output(p)
]
)
assert (
Samples.dtype == np.int64
......
......@@ -29,8 +29,8 @@ from paddle.nn.layer.transformer import (
def generate_basic_params(mode="attn", self_attention=True):
batch_size, query_length = [np.random.randint(2, 10) for _ in range(2)]
d_head, num_heads = [np.random.randint(3, 10) for _ in range(2)]
batch_size, query_length = (np.random.randint(2, 10) for _ in range(2))
d_head, num_heads = (np.random.randint(3, 10) for _ in range(2))
attn_dropout = 0.0
embed_dim = d_head * num_heads
if mode == "attn":
......@@ -38,7 +38,7 @@ def generate_basic_params(mode="attn", self_attention=True):
kdim, vdim = embed_dim, embed_dim
key_length, value_length = query_length, query_length
else:
kdim, vdim = [np.random.randint(5, 20) for _ in range(2)]
kdim, vdim = (np.random.randint(5, 20) for _ in range(2))
key_length = np.random.randint(2, 10)
value_length = key_length
return (
......
......@@ -337,7 +337,7 @@ def plan_matmul(plan, g_view, op1, op2, g_supports, g_shape, I, J1, J2, K):
# Then apply matmul(x, y, transpose_x=False, tranpose_y=True)
var1, var2 = f'op{op1}', f'op{op2}'
op1_view, op2_view = [g_view[op] for op in (op1, op2)]
op1_view, op2_view = (g_view[op] for op in (op1, op2))
I1 = [idx for idx in I if op1_view[idx] >= 0]
I2 = [idx for idx in I if op2_view[idx] >= 0]
......@@ -347,7 +347,7 @@ def plan_matmul(plan, g_view, op1, op2, g_supports, g_shape, I, J1, J2, K):
op2_view = np.array(op2_view)
op2_dims = op2_view[I2 + J2 + K]
op1_mask, op2_mask = [g_supports[op] for op in (op1, op2)]
op1_mask, op2_mask = (g_supports[op] for op in (op1, op2))
op1_vshape = np.array([s if m else 1 for s, m in zip(g_shape, op1_mask)])
op2_vshape = np.array([s if m else 1 for s, m in zip(g_shape, op2_mask)])
vshape = np.maximum(op1_vshape, op2_vshape)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册