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][Ruff][BUAA][G-[201-208]] Fix ruff RUF005 diagnostic for 8 files in python/test/legacy_test/ #67122

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion test/legacy_test/test_crf_decoding_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def init_lod(self):

def seq_pad(data, length):
max_len = np.max(length)
shape = [len(length), max_len] + list(data.shape[1:])
shape = [len(length), max_len, *data.shape[1:]]
padded = np.zeros(shape).astype(data.dtype)
offset = 0
for i, l in enumerate(length):
Expand Down
18 changes: 9 additions & 9 deletions test/legacy_test/test_cross_entropy_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ def init_x(self):
self.X_2d = randomize_probability(self.ins_num, self.class_num).astype(
self.dtype
)
self.x = self.X_2d.reshape(self.shape + [self.class_num])
self.x = self.X_2d.reshape([*self.shape, self.class_num])

def init_label(self):
self.label_2d = np.random.randint(
0, self.class_num, (self.ins_num, 1), dtype="int64"
)
self.label = self.label_2d.reshape(self.shape + [1])
self.label = self.label_2d.reshape([*self.shape, 1])

def get_cross_entropy(self):
cross_entropy_2d = np.array(
Expand All @@ -195,7 +195,7 @@ def get_cross_entropy(self):
]
).astype(self.dtype)
self.cross_entropy = np.array(cross_entropy_2d).reshape(
self.shape + [1]
[*self.shape, 1]
)

def init_attr_type(self):
Expand Down Expand Up @@ -236,14 +236,14 @@ def init_x(self):
self.X_2d = randomize_probability(self.ins_num, self.class_num).astype(
self.dtype
)
self.x = self.X_2d.reshape(self.shape + [self.class_num])
self.x = self.X_2d.reshape([*self.shape, self.class_num])

def init_label(self):
self.label_2d = np.random.uniform(
0.1, 1.0, [self.ins_num, self.class_num]
).astype(self.dtype)
self.label_2d /= self.label_2d.sum(axis=1, keepdims=True)
self.label = self.label_2d.reshape(self.shape + [self.class_num])
self.label = self.label_2d.reshape([*self.shape, self.class_num])

def get_cross_entropy(self):
cross_entropy_2d = (
Expand All @@ -252,7 +252,7 @@ def get_cross_entropy(self):
.astype(self.dtype)
)
self.cross_entropy = np.array(cross_entropy_2d).reshape(
self.shape + [1]
[*self.shape, 1]
)

def init_attr_type(self):
Expand All @@ -279,15 +279,15 @@ def init_x(self):
self.X_2d = randomize_probability(self.ins_num, self.class_num).astype(
self.dtype
)
self.x = self.X_2d.reshape(self.shape + [self.class_num])
self.x = self.X_2d.reshape([*self.shape, self.class_num])

def init_label(self):
self.label_index_2d = np.random.randint(
0, self.class_num, (self.ins_num), dtype="int64"
)
label_2d = np.zeros(self.X_2d.shape)
label_2d[np.arange(self.ins_num), self.label_index_2d] = 1
self.label = label_2d.reshape(self.shape + [self.class_num]).astype(
self.label = label_2d.reshape([*self.shape, self.class_num]).astype(
self.dtype
)

Expand All @@ -300,7 +300,7 @@ def get_cross_entropy(self):
)
self.cross_entropy = (
np.array(cross_entropy_2d)
.reshape(self.shape + [1])
.reshape([*self.shape, 1])
.astype(self.dtype)
)

Expand Down
111 changes: 63 additions & 48 deletions test/legacy_test/test_dataset_consistency_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ def reader():
pos_context_fea = pos_context_feas[p]
yield zip(
feature_name,
[[1]]
+ sparse_query_feature
+ pos_url_fea
+ pos_click_fea
+ pos_context_fea
+ pos_url_fea
+ pos_click_fea
+ pos_context_fea,
[
[1],
*sparse_query_feature,
*pos_url_fea,
*pos_click_fea,
*pos_context_fea,
*pos_url_fea,
*pos_click_fea,
*pos_context_fea,
],
)
for n in range(len(neg_url_feas)):
feature_name = ["click"]
Expand All @@ -181,14 +183,16 @@ def reader():
neg_context_fea = neg_context_feas[n]
yield zip(
feature_name,
[[0]]
+ sparse_query_feature
+ neg_url_fea
+ neg_click_fea
+ neg_context_fea
+ neg_url_fea
+ neg_click_fea
+ neg_context_fea,
[
[0],
*sparse_query_feature,
*neg_url_fea,
*neg_click_fea,
*neg_context_fea,
*neg_url_fea,
*neg_click_fea,
*neg_context_fea,
],
)
elif self.test == 0:
for p in range(len(pos_url_feas)):
Expand All @@ -215,14 +219,16 @@ def reader():
yield list(
zip(
feature_name,
[[1]]
+ sparse_query_feature
+ pos_url_fea
+ pos_click_fea
+ pos_context_fea
+ neg_url_fea
+ neg_click_fea
+ neg_context_fea,
[
[1],
*sparse_query_feature,
*pos_url_fea,
*pos_click_fea,
*pos_context_fea,
*neg_url_fea,
*neg_click_fea,
*neg_context_fea,
],
)
)
elif self.test == 2:
Expand Down Expand Up @@ -250,14 +256,17 @@ def reader():
yield list(
zip(
feature_name,
[[1], [2]]
+ sparse_query_feature
+ pos_url_fea
+ pos_click_fea
+ pos_context_fea
+ neg_url_fea
+ neg_click_fea
+ neg_context_fea,
[
[1],
[2],
*sparse_query_feature,
*pos_url_fea,
*pos_click_fea,
*pos_context_fea,
*neg_url_fea,
*neg_click_fea,
*neg_context_fea,
],
)
)
elif self.test == 3:
Expand Down Expand Up @@ -285,14 +294,17 @@ def reader():
yield list(
zip(
feature_name,
[[1], [2.0]]
+ sparse_query_feature
+ pos_url_fea
+ pos_click_fea
+ pos_context_fea
+ neg_url_fea
+ neg_click_fea
+ neg_context_fea,
[
[1],
[2.0],
*sparse_query_feature,
*pos_url_fea,
*pos_click_fea,
*pos_context_fea,
*neg_url_fea,
*neg_click_fea,
*neg_context_fea,
],
)
)
elif self.test == 4:
Expand Down Expand Up @@ -320,14 +332,17 @@ def reader():
yield list(
zip(
feature_name,
[[], [2.0]]
+ sparse_query_feature
+ pos_url_fea
+ pos_click_fea
+ pos_context_fea
+ neg_url_fea
+ neg_click_fea
+ neg_context_fea,
[
[],
[2.0],
*sparse_query_feature,
*pos_url_fea,
*pos_click_fea,
*pos_context_fea,
*neg_url_fea,
*neg_click_fea,
*neg_context_fea,
],
)
)
elif self.test == 5:
Expand Down
11 changes: 7 additions & 4 deletions test/legacy_test/test_deform_conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def prepare(self):
self.weight = np.random.uniform(
-1,
1,
(self.out_channels, self.in_channels // self.groups) + filter_shape,
(self.out_channels, self.in_channels // self.groups, *filter_shape),
).astype(self.dtype)
if not self.no_bias:
self.bias = np.random.uniform(-1, 1, (self.out_channels,)).astype(
Expand Down Expand Up @@ -87,17 +87,20 @@ def out_size(
self.input_shape = (
self.batch_size,
self.in_channels,
) + self.spatial_shape
*self.spatial_shape,
)

self.offset_shape = (
self.batch_size,
self.deformable_groups * 2 * filter_shape[0] * filter_shape[1],
) + out_shape
*out_shape,
)

self.mask_shape = (
self.batch_size,
self.deformable_groups * filter_shape[0] * filter_shape[1],
) + out_shape
*out_shape,
)

self.input = np.random.uniform(-1, 1, self.input_shape).astype(
self.dtype
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def static_distribute_fpn_proposals(self, rois_np, rois_num_np):
refer_scale=224,
rois_num=rois_num,
)
fetch_list = multi_rois + [restore_ind] + rois_num_per_level
fetch_list = [*multi_rois, restore_ind, *rois_num_per_level]
output_stat = self.get_static_graph_result(
feed={'rois': rois_np, 'rois_num': rois_num_np},
fetch_list=fetch_list,
Expand Down Expand Up @@ -210,7 +210,7 @@ def dynamic_distribute_fpn_proposals(self, rois_np, rois_num_np):
rois_num=rois_num_dy,
)
print(type(multi_rois_dy))
output_dy = multi_rois_dy + [restore_ind_dy] + rois_num_per_level_dy
output_dy = [*multi_rois_dy, restore_ind_dy, *rois_num_per_level_dy]
output_dy_np = []
for output in output_dy:
output_np = output.numpy()
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_distribute_fpn_proposals_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_dygraph_with_static(self):
refer_scale=224,
rois_num=rois_num,
)
fetch_list = multi_rois + [restore_ind] + rois_num_per_level
fetch_list = [*multi_rois, restore_ind, *rois_num_per_level]

exe = paddle.static.Executor()
output_stat = exe.run(
Expand Down Expand Up @@ -250,7 +250,7 @@ def test_dygraph_with_static(self):
refer_scale=224,
rois_num=rois_num_dy,
)
output_dy = multi_rois_dy + [restore_ind_dy] + rois_num_per_level_dy
output_dy = [*multi_rois_dy, restore_ind_dy, *rois_num_per_level_dy]
output_dy_np = []
for output in output_dy:
output_np = output.numpy()
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_dygraph_spectral_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def set_data(self):
data_name = desc[0]
data_shape = desc[1]
data_value = np.random.random(
size=[self.batch_size] + data_shape
size=[self.batch_size, *data_shape]
).astype('float32')
self.data[data_name] = data_value

Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_dygraph_weight_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def set_data(self):
data_name = desc[0]
data_shape = desc[1]
data_value = np.random.random(
size=[self.batch_size] + data_shape
size=[self.batch_size, *data_shape]
).astype('float32')
self.data[data_name] = data_value

Expand Down