@@ -67,6 +67,9 @@ def mapping_type_to_description(mapping_type):
67
67
REFERENCE_PATTERN = re .compile (
68
68
r"^\| *REFERENCE-MAPPING-ITEM\( *(?P<torch_api>[^,]+) *, *(?P<diff_url>.+) *\) *\|$"
69
69
)
70
+ ALIAS_PATTERN = re .compile (
71
+ r"^\| *ALIAS-REFERENCE-ITEM\( *(?P<alias_name>[^,]+) *, *(?P<torch_api>[^,]+) *\) *\|$"
72
+ )
70
73
NOT_IMPLEMENTED_PATTERN = re .compile (
71
74
r"^\| *NOT-IMPLEMENTED-ITEM\( *(?P<torch_api>[^,]+) *, *(?P<torch_api_url>.+) *\) *\|$"
72
75
)
@@ -87,21 +90,24 @@ def docs_url_to_relative_page(url):
87
90
88
91
def apply_reference_to_row (line , metadata_dict , table_row_idx , line_idx ):
89
92
reference_match = REFERENCE_PATTERN .match (line )
93
+ alias_match = ALIAS_PATTERN .match (line )
90
94
not_implemented_match = NOT_IMPLEMENTED_PATTERN .match (line )
91
95
96
+ row_idx_s = str (table_row_idx )
97
+
92
98
if reference_match :
93
99
torch_api = reference_match ["torch_api" ].strip ("`" ).replace (r"\_" , "_" )
94
100
diff_url = reference_match ["diff_url" ]
95
101
96
102
diff_page_url = docs_url_to_relative_page (diff_url )
97
103
98
- row_idx_s = str (table_row_idx )
99
-
100
104
if torch_api not in metadata_dict :
101
105
raise Exception (
102
106
f"Cannot find torch_api: { torch_api } in line { line_idx } "
103
107
)
104
108
109
+ meta_dict [torch_api ]["diff_url" ] = diff_page_url
110
+
105
111
reference_item = metadata_dict .get (torch_api , None )
106
112
torch_api_url = reference_item ["torch_api_url" ]
107
113
torch_api_column = f"[`{ torch_api } `]({ torch_api_url } )"
@@ -137,14 +143,61 @@ def apply_reference_to_row(line, metadata_dict, table_row_idx, line_idx):
137
143
138
144
output = "| " + " | " .join (content ) + " |\n "
139
145
return output
146
+ elif alias_match :
147
+ alias_name = alias_match ["alias_name" ].strip ("`" ).replace (r"\_" , "_" )
148
+ torch_api = alias_match ["torch_api" ].strip ("`" ).replace (r"\_" , "_" )
149
+
150
+ if torch_api not in metadata_dict :
151
+ raise Exception (
152
+ f"Cannot find torch_api: { torch_api } in line { line_idx } "
153
+ )
154
+
155
+ diff_page_url = metadata_dict [torch_api ].get ("diff_url" , "" )
156
+
157
+ reference_item = metadata_dict .get (torch_api , None )
158
+ torch_api_url = reference_item ["torch_api_url" ]
159
+ alisa_name_column = f"[`{ alias_name } `]({ torch_api_url } )"
160
+
161
+ mapping_type = reference_item ["mapping_type" ]
162
+ mapping_type_column = mapping_type
163
+
164
+ _mapping_type_desc , show_diff_url = mapping_type_to_description (
165
+ mapping_type
166
+ )
167
+
168
+ desc_column = f"`{ torch_api } ` 别名"
169
+
170
+ if show_diff_url :
171
+ desc_column += f",[详细对比]({ diff_page_url } )"
172
+
173
+ if "paddle_api" not in reference_item :
174
+ if mapping_type not in ["组合替代实现" , "可删除" , "功能缺失" ]:
175
+ print (
176
+ f"Cannot find paddle_api for torch_api: { torch_api } in line { line_idx } "
177
+ )
178
+ paddle_api_column = ""
179
+ else :
180
+ paddle_api = reference_item ["paddle_api" ]
181
+ paddle_api_url = reference_item ["paddle_api_url" ]
182
+ paddle_api_column = f"[`{ paddle_api } `]({ paddle_api_url } )"
183
+
184
+ content = [
185
+ row_idx_s ,
186
+ alisa_name_column ,
187
+ paddle_api_column ,
188
+ mapping_type_column ,
189
+ desc_column ,
190
+ ]
191
+
192
+ output = "| " + " | " .join (content ) + " |\n "
193
+ return output
194
+
140
195
elif not_implemented_match :
141
196
torch_api = (
142
197
not_implemented_match ["torch_api" ].strip ("`" ).replace (r"\_" , "_" )
143
198
)
144
199
torch_api_url = not_implemented_match ["torch_api_url" ].strip ()
145
200
146
- row_idx_s = str (table_row_idx )
147
-
148
201
torch_api_column = f"[`{ torch_api } `]({ torch_api_url } )"
149
202
150
203
paddle_api_column = ""
@@ -165,7 +218,7 @@ def apply_reference_to_row(line, metadata_dict, table_row_idx, line_idx):
165
218
raise ValueError (
166
219
f"found manual-maintaining row at line [{ line_idx } ]: { line } "
167
220
)
168
- # return line
221
+ return line
169
222
170
223
171
224
def reference_mapping_item_processer (line , line_idx , state , output , context ):
0 commit comments