-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add framework utils for Chinese Version API Docs (#6308)
* start up of framework * refine * refine * add test on reset_docstr Co-authored-by: oneflow-ci-bot <[email protected]>
- Loading branch information
1 parent
481ad4d
commit 2fe6db3
Showing
6 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .math_ops import * | ||
from .activation import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import oneflow | ||
from oneflow.framework.docstr.utils import reset_docstr | ||
|
||
reset_docstr( | ||
oneflow.nn.ReLU, | ||
r"""ReLU(inplace=False) | ||
ReLU 激活函数,对张量中的每一个元素做 element-wise 运算,公式如下: | ||
:math:`\text{ReLU}(x) = (x)^+ = \max(0, x)` | ||
参数: | ||
inplace: 是否做 in-place 操作。 默认为 ``False`` | ||
形状: | ||
- Input: :math:`(N, *)` 其中 `*` 的意思是,可以指定任意维度 | ||
- Output: :math:`(N, *)` 输入形状与输出形状一致 | ||
示例: | ||
.. code-block:: python | ||
>>> import oneflow as flow | ||
>>> import numpy as np | ||
>>> relu = flow.nn.ReLU() | ||
>>> ndarr = np.asarray([1, -2, 3]) | ||
>>> x = flow.Tensor(ndarr) | ||
>>> relu(x) | ||
tensor([1., 0., 3.], dtype=oneflow.float32) | ||
""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import oneflow | ||
from oneflow.framework.docstr.utils import reset_docstr | ||
|
||
reset_docstr( | ||
oneflow.add, | ||
r"""add(input, other) | ||
计算 `input` 和 `other` 的和。支持 element-wise、标量和广播形式的加法。 | ||
公式为: | ||
.. math:: | ||
out = input + other | ||
示例: | ||
.. code-block:: python | ||
>>> import numpy as np | ||
>>> import oneflow as flow | ||
# element-wise 加法 | ||
>>> x = flow.tensor(np.random.randn(2,3), dtype=flow.float32) | ||
>>> y = flow.tensor(np.random.randn(2,3), dtype=flow.float32) | ||
>>> out = flow.add(x, y).numpy() | ||
>>> out.shape | ||
(2, 3) | ||
# 标量加法 | ||
>>> x = 5 | ||
>>> y = flow.tensor(np.random.randn(2,3), dtype=flow.float32) | ||
>>> out = flow.add(x, y).numpy() | ||
>>> out.shape | ||
(2, 3) | ||
# 广播加法 | ||
>>> x = flow.tensor(np.random.randn(1,1), dtype=flow.float32) | ||
>>> y = flow.tensor(np.random.randn(2,3), dtype=flow.float32) | ||
>>> out = flow.add(x, y).numpy() | ||
>>> out.shape | ||
(2, 3) | ||
""", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters