Skip to content

Commit

Permalink
部分勘误
Browse files Browse the repository at this point in the history
  • Loading branch information
fufu0615 committed Sep 14, 2024
1 parent 2362db1 commit d8703a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
58 changes: 28 additions & 30 deletions ci_scripts/check_api_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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."
)
Expand Down
3 changes: 0 additions & 3 deletions docs/api/paddle/einsum_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,12 @@ Einsum 求和过程理论上等价于如下四步,但实现中实际执行的
参数
:::::


- **equation** (str):求和标记

- **operands** (Tensor, [Tensor, ...]):输入 Tensor

返回
:::::


Tensor:输出 Tensor

代码示例
Expand Down
6 changes: 1 addition & 5 deletions docs/api/paddle/unstack_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 操作。
Expand Down

0 comments on commit d8703a2

Please sign in to comment.