-
Notifications
You must be signed in to change notification settings - Fork 750
中文API文档复制英文API文档示例代码
Ligoml edited this page Dec 20, 2022
·
5 revisions
为了保证中英文API文档示例代码的一致性,飞桨提供了中文API文档复制英文API文档示例代码的方式。通过在英文文档的示例代码处添加placeholder 标识符,同时,在对应中文文档的示例代码处按照规则放置对应的placeholder即可,具体如下:
在英文文档的示例代码的code block中添加 :name: code_id
标识符,在中文文档的对应位置,添加 COPY-FROM: api_name:code_id
即可。
api_name 为该API的公开路径。如
paddle.add
、paddle.any
、paddle.nn.Conv2D
.
注:如果只有一段示例代码,也可以不添加
name
标识符,在中文文档的对应位置,添加COPY-FROM: api_name
即可。
sphinx语法中,针对示例代码块,有 name
标识可以作为标识,具体如:
# paddle repo
def any(x, axis=None, keepdim=False, name=None):
"""
Computes the the ``logical or`` of tensor elements over the given dimension.
Args:
xxx
Returns:
xxx
Examples:
.. code-block:: python
:name: code-example1
import paddle
import numpy as np
# x is a bool Tensor with following elements:
# [[True, False]
# [False, False]]
x = paddle.assign(np.array([[1, 0], [1, 1]], dtype='int32'))
print(x)
x = paddle.cast(x, 'bool')
# out1 should be [True]
out1 = paddle.any(x) # [True]
print(out1)
"""
# docs repo any_cn.rst
any
.. py:function:: paddle.any(x, axis=None, keepdim=False, name=None)
参数
xxx
返回
xxx
代码示例
COPY-FROM: paddle.any:code-example1 # api_name 为 paddle.add,code_id 为 code-example1
COPY-FROM: paddle.any # 若该API仅有一个示例代码,可以直接写 api_name
# paddle repo
class Optimizer():
"""
Optimizer Base class.
Args:
xxx
Returns:
xxx
Examples:
.. code-block:: python
:name: code-example1
"""
def state_dict(self):
'''
Get state dict information from optimizer.
Args:
xxx
Returns:
xxx
Examples:
.. code-block:: python
:name: code-example1
import paddle
emb = paddle.nn.Embedding(10, 10)
adam = paddle.optimizer.Adam(0.001, parameters=emb.parameters())
state_dict = adam.state_dict()
'''
class Adadelta(Optimizer):
"""
Computes the the ``logical or`` of tensor elements over the given dimension.
Args:
xxx
Returns:
xxx
Examples:
.. code-block:: python
:name: code-example1
"""
# docs repo Adadelta_cn.rst
Adadelta
.. py:class:: paddle.optimizer.Adadelta()
参数
xxx
返回
xxx
代码示例
COPY-FROM: paddle.optimizer.Adadelta:code-example1
.. py:method: state_dict()
参数
xxx
返回
xxx
代码示例
COPY-FROM: paddle.optimizer.Optimizer.state_dict:code-example1