From d8703a29041a4a065dde6b04fa98a339efd08cbe Mon Sep 17 00:00:00 2001 From: fufu <2871640030@qq.com> Date: Sat, 14 Sep 2024 13:59:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E5=88=86=E5=8B=98=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci_scripts/check_api_parameters.py | 58 +++++++++++++++--------------- docs/api/paddle/einsum_cn.rst | 3 -- docs/api/paddle/unstack_cn.rst | 6 +--- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/ci_scripts/check_api_parameters.py b/ci_scripts/check_api_parameters.py index 5255abc5cf8..28e13b46ede 100644 --- a/ci_scripts/check_api_parameters.py +++ b/ci_scripts/check_api_parameters.py @@ -57,42 +57,40 @@ def parse_args(): def _check_params_in_description(rstfilename, paramstr): flag = True info = "" - params_intitle = [] + params_in_title = [] if paramstr: fake_func = ast.parse(f"def fake_func({paramstr}): pass") - # Iterate over all intitle parameters + # Iterate over all in_title parameters num_defaults = len(fake_func.body[0].args.defaults) num_args = len(fake_func.body[0].args.args) # args & defaults for i, arg in enumerate(fake_func.body[0].args.args): if i >= num_args - num_defaults: - default_value = ast.dump( - fake_func.body[0].args.defaults[ - i - (num_args - num_defaults) - ] - ) - params_intitle.append(f"{arg.arg}={default_value}") + default_value = fake_func.body[0].args.defaults[ + i - (num_args - num_defaults) + ] + params_in_title.append(f"{arg.arg}={default_value}") else: - params_intitle.append(arg.arg) + params_in_title.append(arg.arg) # posonlyargs for arg in fake_func.body[0].args.posonlyargs: - params_intitle.append(arg.arg) - # vararh(*args) + params_in_title.append(arg.arg) + # vararg(*args) if fake_func.body[0].args.vararg: - params_intitle.append(fake_func.body[0].args.vararg.arg) + params_in_title.append(fake_func.body[0].args.vararg.arg) # kwonlyargs & kw_defaults for i, arg in enumerate(fake_func.body[0].args.kwonlyargs): if ( i < len(fake_func.body[0].args.kw_defaults) and fake_func.body[0].args.kw_defaults[i] is not None ): - default_value = ast.dump(fake_func.body[0].args.kw_defaults[i]) - params_intitle.append(f"{arg.arg}={default_value}") + default_value = fake_func.body[0].args.kw_defaults[i] + params_in_title.append(f"{arg.arg}={default_value}") else: - params_intitle.append(arg.arg) + params_in_title.append(arg.arg) # **kwargs if fake_func.body[0].args.kwarg: - params_intitle.append(fake_func.body[0].args.kwarg.arg) + params_in_title.append(fake_func.body[0].args.kwarg.arg) funcdescnode = extract_params_desc_from_rst_file(rstfilename) if funcdescnode: @@ -101,40 +99,40 @@ def _check_params_in_description(rstfilename, paramstr): if not re.match(list_pat, str(items[0])): flag = False info = "Something wrong with the format of params list in description, check it please." - elif len(items) != len(params_intitle): + elif len(items) != len(params_in_title): flag = False if not items: info = ( "Params section in description is empty, check it please." ) else: - info = f"The number of params in title does not match the params in description: {len(params_intitle)} != {len(items)}." + info = f"The number of params in title does not match the params in description: {len(params_in_title)} != {len(items)}." print(f"check failed (parammeters description): {rstfilename}") else: for i in range(len(items)): - pname_intitle = params_intitle[i].split("=")[0].strip() + pname_in_title = params_in_title[i].split("=")[0].strip() mo = re.match( r"\*{0,2}(\w+)\b.*", items[i].children[0].astext() ) if mo: pname_indesc = mo.group(1) - if pname_indesc != pname_intitle: + if pname_indesc != pname_in_title: flag = False - info = f"the following param in title does not match the param in description: {pname_intitle} != {pname_indesc}." + info = f"the following param in title does not match the param in description: {pname_in_title} != {pname_indesc}." print( - f"check failed (parammeters description): {rstfilename}, {pname_intitle} != {pname_indesc}" + f"check failed (parammeters description): {rstfilename}, {pname_in_title} != {pname_indesc}" ) else: flag = False - info = f"param name '{pname_intitle}' not matched in description line{i+1}, check it please." + info = f"param name '{pname_in_title}' not matched in description line{i+1}, check it please." print( f"check failed (parammeters description): {rstfilename}, param name not found in {i} paragraph." ) else: - if params_intitle: + if params_in_title: info = "params section not found in description, check it please." print( - f"check failed (parameters description not found): {rstfilename}, {params_intitle}." + f"check failed (parameters description not found): {rstfilename}, {params_in_title}." ) flag = False return flag, info @@ -154,21 +152,21 @@ def _check_params_in_description_with_fullargspec(rstfilename, funcname): print(f"check failed (parammeters description): {rstfilename}") else: for i in range(len(items)): - pname_intitle = params_inspec[i] + pname_in_title = params_inspec[i] mo = re.match( r"\*{0,2}(\w+)\b.*", items[i].children[0].astext() ) if mo: pname_indesc = mo.group(1) - if pname_indesc != pname_intitle: + if pname_indesc != pname_in_title: flag = False - info = f"the following param in title does not match the param in description: {pname_intitle} != {pname_indesc}." + info = f"the following param in title does not match the param in description: {pname_in_title} != {pname_indesc}." print( - f"check failed (parammeters description): {rstfilename}, {pname_intitle} != {pname_indesc}" + f"check failed (parammeters description): {rstfilename}, {pname_in_title} != {pname_indesc}" ) else: flag = False - info = f"param name '{pname_intitle}' not matched in description line{i+1}, check it please." + info = f"param name '{pname_in_title}' not matched in description line{i+1}, check it please." print( f"check failed (parammeters description): {rstfilename}, param name not found in {i} paragraph." ) diff --git a/docs/api/paddle/einsum_cn.rst b/docs/api/paddle/einsum_cn.rst index 52545775c28..a74a06ea1d9 100644 --- a/docs/api/paddle/einsum_cn.rst +++ b/docs/api/paddle/einsum_cn.rst @@ -67,15 +67,12 @@ Einsum 求和过程理论上等价于如下四步,但实现中实际执行的 参数 ::::: - - **equation** (str):求和标记 - - **operands** (Tensor, [Tensor, ...]):输入 Tensor 返回 ::::: - Tensor:输出 Tensor 代码示例 diff --git a/docs/api/paddle/unstack_cn.rst b/docs/api/paddle/unstack_cn.rst index 87553cd16fd..b3ce6a2ddb1 100644 --- a/docs/api/paddle/unstack_cn.rst +++ b/docs/api/paddle/unstack_cn.rst @@ -5,22 +5,18 @@ unstack .. py:function:: paddle.unstack(x, axis=0, num=None) - - - 将单个 dim 为 ``D`` 的 Tensor 沿 ``axis`` 轴 unpack 为 ``num`` 个 dim 为 ``(D-1)`` 的 Tensor。 参数 :::::::::::: - **x** (Tensor) – 输入 x 为 ``dim > 0`` 的 Tensor,支持的数据类型:float32,float64,int32,int64, complex64,complex128。 - - **axis** (int | 可选) – 输入 Tensor 进行 unpack 运算所在的轴,axis 的范围为:``[-D, D)`` ,如果 ``axis < 0``,则 :math:`axis = axis + dim(x)`,axis 的默认值为 0。 - - **num** (int | 可选) - axis 轴的长度,一般无需设置,默认值为 ``None`` 。 返回 :::::::::::: + 长度为 num 的 Tensor 列表,数据类型与输入 Tensor 相同,dim 为 ``(D-1)``。 也可以参考下方的图示来理解 ``unstack`` 是如何对张量进行变换的。图中分别展示了一个形状为 ``(3, 4)`` 的 Tensor 在 ``axis=1`` 和一个形状为 ``(2, 3, 3)`` 的 Tensor 在 ``axis=1`` 的 unstack 操作。