Repository navigation
[Docathon][Add API Legend No.26-30]添加tensor_split系列API图例 - #6809
Conversation
|
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-6809.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html |
|
@fufu0615 你是用啥画的图啊 |
eaef617 to
967a1e6
Compare
sunzhongkai588
left a comment
There was a problem hiding this comment.
@megemini 可以看一下社区开发者提供的图例和修改的内容是否正确~
| .. py:function:: paddle.dsplit(x, num_or_indices, name=None) | ||
|
|
||
|
|
||
| ``dsplit`` 全称 Depth Split ,即深度分割,将输入 Tensor 沿着深度轴分割成多个子 Tensor,等价于将 :ref:`cn_api_paddle_tensor_split` API 的参数 axis 固定为 2。注意:使用 ``paddle.dsplit`` 进行变换的 Tensor 维度数量必须不少于 3。 |
There was a problem hiding this comment.
| ::::::::: | ||
| - **x** (Tensor) - 输入变量,数据类型为 bool、bfloat16、float16、float32、float64、uint8、int8、int32、int64 的多维 Tensor,其维度必须大于 0。 | ||
| - **num_or_indices** (int|list|tuple) - 如果 ``num_or_indices`` 是一个整数 ``n`` ,则 ``x`` 沿 ``axis`` 拆分为 ``n`` 部分。如果 ``x`` 可被 ``n`` 整除,则每个部分都是 ``x.shape[axis]/n`` 。如果 ``x`` 不能被 ``n`` 整除,则第一个 ``int(x.shape[axis]%n)`` 分割大小将为 ``int(x.shape[axis]/n)+1`` ,其余部分的大小将是 ``int(x.shape[axis]/n)`` 。如果 ``num_or_indices`` 是整数索引的列表或元组,则在每个索引处沿 ``axis`` 分割 ``x`` 。例如, ``num_or_indices=[2, 4]`` 在 ``axis=0`` 时将沿轴 0 将 ``x`` 拆分为 ``x[:2]`` 、 ``x[2:4]`` 和 ``x[4:]`` 。 | ||
| - **num_or_indices** (int|list|tuple) - 如果 ``num_or_indices`` 是一个整数 ``n`` ,则 ``x`` 沿 ``axis`` 拆分为 ``n`` 部分。如果 ``x`` 可被 ``n`` 整除,则每个部分都是 ``x.shape[axis]/n`` 。如果 ``x`` 不能被 ``n`` 整除,则第 ``int(x.shape[axis]/n)+1`` 个部分的大小将是 ``int(x.shape[axis]%n)`` ,其余部分的大小将是 ``int(x.shape[axis]/n)`` 。如果 ``num_or_indices`` 是整数索引的列表或元组,则在每个索引处沿 ``axis`` 分割 ``x`` 。例如, ``num_or_indices=[2, 4]`` 在 ``axis=0`` 时将沿轴 0 将 ``x`` 拆分为 ``x[:2]`` 、 ``x[2:4]`` 和 ``x[4:]`` 。 |
There was a problem hiding this comment.
这里有点问题,我这里翻译的可能不太好,原文是
the first
int(x.shape[axis] % n)sections will have sizeint(x.shape[axis] / n) + 1
翻译为 则第一个 .... ,应该翻译为 则前 ... 个 。
参考代码:
In [5]: x = paddle.rand([13])
In [6]: out = paddle.tensor_split(x, 3)
In [7]: out
Out[7]:
[Tensor(shape=[5], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[0.40005636, 0.65518010, 0.31436527, 0.23026623, 0.36780968]),
Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[0.55613798, 0.12409472, 0.20364396, 0.83700526]),
Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[0.03752962, 0.71997887, 0.79592997, 0.49080023])]
In [8]: x = paddle.rand([8])
In [9]: out = paddle.tensor_split(x, 3)
In [10]: out
Out[10]:
[Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[0.75365561, 0.43469149, 0.56143743]),
Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[0.89418393, 0.64861047, 0.43100974]),
Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[0.99590099, 0.27822134])]
In [11]: 13%3
Out[11]: 1
In [12]: 8%3
Out[12]: 2
In [13]: 13//3
Out[13]: 4
In [14]: 8//3
Out[14]: 2- 当长度为
13,分割3份,则前13%3=1个的大小为13//3+1=5,余下2份,大小为13//3=4,即:[5, 4, 4] - 当长度为
8,分割3份,则前8%3=2个的大小为8//3+1=3,余下1份,大小为8//3=2,即:[3, 3, 2]
因此,如需修改,可以修改一下原文中的翻译,但是,这里修改后的描述有问题,因为
则第
int(x.shape[axis]/n)+1个部分的大小将是int(x.shape[axis]%n)
表示只有一个部分,即 int(x.shape[axis]/n)+1 是 int(x.shape[axis]%n) 这样大小,与实际不符。
另外,图例也需要修改。
There was a problem hiding this comment.
了解了,感谢师傅讲解,改完的图例和文档已推送🫡
|
|
||
|
|
||
| 代码示例 | ||
| 代码示例 1 |
There was a problem hiding this comment.
这里分割开了示例代码,paddle 那边也需要同步修改 ~
| ``vsplit`` 全称 Vertical Split 即垂直分割,将输入 Tensor 沿着垂直轴分割成多个子 Tensor ,等价于将 :ref:`cn_api_paddle_tensor_split` API 的参数 axis 固定为 0。 | ||
|
|
||
| 当 Tensor 维度数量等于 1 时: | ||
|
|
||
| .. image:: ../../images/api_legend/vsplit/vsplit-1.png | ||
| :alt: vsplit 图例-1 | ||
|
|
||
| 当 Tensor 维度数量大于 1 时: | ||
|
|
||
| .. image:: ../../images/api_legend/vsplit/vsplit-2.png | ||
| :alt: vsplit 图例-2 |
megemini
left a comment
There was a problem hiding this comment.
两个问题
- 如果图例中有中文,那么英文文档怎么办?可以考虑去掉中文文字说明,或者中英文各一份
vsplit的问题没修改吧?
…e#6809) * 修改tensor_split文档描述并增加图例 * 修改hsplit文档描述并增加图例 * 修改dsplit文档描述并增加图例 * 修改vsplit文档描述并增加图例 * 修改代码块引用和图例参数注释


PADDLEPADDLE_PR=66991
PR types
Add api legends
PR changes
Docs
Description
为tensor_split,hsplit,dsplit,vsplit API文档增加图例
(tensor_split文档的示例代码部分有修改,需要等待英文文档pr合并后更新)
对应的英文文档修复为:PaddlePaddle/Paddle#66991