!44218 add CN docs for some APIs
Merge pull request !44218 from 李林杰/code_docs_1019_add_CN_docs_for_6_ops_master
This commit is contained in:
commit
46db6ccd22
|
@ -0,0 +1,27 @@
|
|||
mindspore.ops.DivNoNan
|
||||
=============================
|
||||
|
||||
.. py:class:: mindspore.ops.DivNoNan
|
||||
|
||||
对 `x1` 和 `x2` 逐元素执行安全除法,如果 `x2` 的元素为0,则返回0。
|
||||
|
||||
`x1` 和 `x2` 的输入遵循隐式类型转换规则,使数据类型一致。
|
||||
输入必须是两个Tensor或一个Tensor和一个Scalar。
|
||||
当输入是两个Tensor时,它们的dtype不能同时是布尔型的,它们的shape可以广播。
|
||||
当输入是一个Tensor和一个Scalar时,Scalar只能是一个常数。
|
||||
|
||||
.. math::
|
||||
output_{i} = \begin{cases}
|
||||
0, & \text{ if } x2_{i} = 0\\
|
||||
x1_{i} / x2_{i}, & \text{ if } x2_{i} \ne 0
|
||||
\end{cases}
|
||||
|
||||
输入:
|
||||
- **x1** (Union[Tensor, number.Number, bool]) - 第一个输入是number.Number、bool或者Tensor,数据类型为 `number <https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.html#mindspore.dtype>`_ 或 `bool_ <https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore.html#mindspore.dtype>`_ 。
|
||||
- **x2** (Union[Tensor, number.Number, bool]) - 当第一个输入是bool或数据类型为number或bool\_的Tensor时,第二个输入是number.Number或bool。当第一个输入是Scalar时,第二个输入必须是数据类型为number或bool\_的Tensor。
|
||||
|
||||
输出:
|
||||
Tensor,shape与广播后的shape相同,数据类型为两个输入中精度较高或数位较高的类型。
|
||||
|
||||
异常:
|
||||
- **TypeError** - 如果 `x1` 和 `x2` 不是number.Number、bool或Tensor。
|
|
@ -0,0 +1,8 @@
|
|||
mindspore.ops.Expm1
|
||||
====================
|
||||
|
||||
.. py:class:: mindspore.ops.Expm1
|
||||
|
||||
返回Tensor元素的指数,然后减去1。
|
||||
|
||||
更多参考详见 :func:`mindspore.ops.expm1` 。
|
|
@ -0,0 +1,27 @@
|
|||
mindspore.ops.Multinomial
|
||||
==========================
|
||||
|
||||
.. py:class:: mindspore.ops.Multinomial(seed=0, seed2=0, dtype=mstype.int32)
|
||||
|
||||
返回从输入Tensor对应行进行多项式概率分布采样出的Tensor。
|
||||
|
||||
.. note::
|
||||
输入的行不需要求和为1(在这种情况下,我们使用值作为权重),但必须是非负的、有限的,并且具有非零和。
|
||||
|
||||
参数:
|
||||
- **seed** (int) - 随机数种子,必须是非负数。默认值:0。
|
||||
- **seed2** (int) - 二号随机数种子,必须是非负数。默认值:0。
|
||||
- **dtype** (dtype) - 输出数据类型,必须是int32或者int63,默认类型:int32。
|
||||
|
||||
输入:
|
||||
- **x** (Tensor) - 包含累加概率和的输入Tensor,必须是1维或2维。具有float16、float32或float64数据类型。CPU和GPU后端支持1维或者2维,Ascend后端仅支持2维。
|
||||
- **num_samples** (int) - 要抽取的样本数。
|
||||
|
||||
输出:
|
||||
Tensor,具有与输入相同的行。每行的采样索引数为 `num_samples` 。
|
||||
|
||||
异常:
|
||||
- **TypeError** - 如果 `seed` 或者 `seed2` 不是int类型。
|
||||
- **TypeError** - 如果 `x` 不是dtype为float16、float32或者float64的Tensor。
|
||||
- **TypeError** - 如果 `num_sample` 不是int类型。
|
||||
- **TypeError** - 如果 `dtype` 不是int32或者int64类型。
|
|
@ -0,0 +1,24 @@
|
|||
mindspore.ops.RNNTLoss
|
||||
=======================
|
||||
|
||||
.. py:class:: mindspore.ops.RNNTLoss(blank_label=0)
|
||||
|
||||
计算相对于softmax输出的RNNTLoss及其梯度。
|
||||
|
||||
参数:
|
||||
- **blank_label** (int) - 空白标签。默认值:0。
|
||||
|
||||
输入:
|
||||
- **acts** (Tensor) - Tensor,shape为 :math:`(B,T,U,V)` 。数据类型必须为float16或float32。
|
||||
- **labels** (Tensor) - Tensor,shape为 :math:`(B, U-1)` 。数据类型为int32。
|
||||
- **input_lengths** (Tensor) - Tensor,shape为 :math:`(B,)` 。数据类型为int32。
|
||||
- **label_lengths** (Tensor) - Tensor,shape为 :math:`(B,)` 。数据类型为int32。
|
||||
|
||||
输出:
|
||||
- **costs** (Tensor) - Tensor,shape为 :math:`(B,)` 。数据类型为int32。
|
||||
- **grads** (Tensor) - 具有与 `acts` 相同的shape和dtype。
|
||||
|
||||
异常:
|
||||
- **TypeError** - 如果 `acts` 、 `labels` 、 `input_lengths` 或 `label_lengths` 不是Tensor。
|
||||
- **TypeError** - 如果 `acts` 的dtype既不是float16也不是float32。
|
||||
- **TypeError** - 如果 `labels`、 `input_lengths` 或 `label_lengths` 的dtype不是int32。
|
|
@ -11,7 +11,7 @@ mindspore.ops.broadcast_to
|
|||
|
||||
- 如果不相等,分以下三种情况:
|
||||
|
||||
- 情况一:如果目标shape该维的值为-1, 则输出shape该维的值为对应输入shape该维的值。比如说输入shape为 :math:`(3, 3)` ,目标shape为 :math:`(-1, 3)` ,则输出shape为 :math:`(3, 3)` ;
|
||||
- 情况一:如果目标shape该维的值为-1,则输出shape该维的值为对应输入shape该维的值。比如说输入shape为 :math:`(3, 3)` ,目标shape为 :math:`(-1, 3)` ,则输出shape为 :math:`(3, 3)` ;
|
||||
|
||||
- 情况二:如果目标shape该维的值不为-1,但是输入shape该维的值为1,则输出shape该维的值为目标shape该维的值。比如说输入shape为 :math:`(1, 3)` ,目标shape为 :math:`(8, 3)` ,则输出shape为 :math:`(8, 3)` ;
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
mindspore.ops.scalar_cast
|
||||
==========================
|
||||
|
||||
.. py:function:: mindspore.ops.mindspore.ops.scalar_cast(input_x, input_y)
|
||||
|
||||
将输入Scalar转换为其他类型。
|
||||
|
||||
参数:
|
||||
- **input_x** (scalar) - 输入Scalar。只允许常量值。
|
||||
- **input_y** (mindspore.dtype) - 要强制转换的类型。只允许常量值。
|
||||
|
||||
返回:
|
||||
Scalar,类型与 `input_y` 对应的python类型相同。
|
||||
|
||||
异常:
|
||||
- **TypeError** - 如果 `input_x` 或 `input_y` 不是常量值。
|
|
@ -0,0 +1,15 @@
|
|||
mindspore.ops.zeros_like
|
||||
=========================
|
||||
|
||||
.. py:function:: mindspore.ops.zeros_like(input_x)
|
||||
|
||||
返回填充值为0的Tensor,其shape和数据类型与 `input_x` 相同。
|
||||
|
||||
参数:
|
||||
- **input_x** (Tensor) - 任何维度的输入Tensor。数据类型为int32、int64、float16或float32。
|
||||
|
||||
返回:
|
||||
Tensor,具有与 `input_x` 相同的shape和数据类型,但填充了零。
|
||||
|
||||
异常:
|
||||
- **TypeError** - 如果 `input_x` 不是Tensor。
|
|
@ -3439,25 +3439,28 @@ def affine_grid(theta, output_size, align_corners=False):
|
|||
def broadcast_to(x, shape):
|
||||
"""
|
||||
Broadcasts input tensor to a given shape. The dim of input shape must be smaller
|
||||
than or equal to that of target shape, suppose input shape :math:`(x1, x2, ..., xm)`,
|
||||
target shape :math:`(*, y_1, y_2, ..., y_m)`. The broadcast rules are as follows:
|
||||
than or equal to that of target shape. Suppose input shape is :math:`(x1, x2, ..., xm)`,
|
||||
target shape is :math:`(*, y_1, y_2, ..., y_m)`, where :math:`*` means any additional dimension.
|
||||
The broadcast rules are as follows:
|
||||
|
||||
Compare the value of `x_m` and `y_m`, `x_{m-1}` and `y_{m-1}`, ..., `x_1` and `y_1` consecutively and
|
||||
decide whether these shapes are broadcastable and what the broadcast result is.
|
||||
|
||||
If the value pairs at a specific dim are equal, then that value goes right into that dim of output shape.
|
||||
With an input shape :math:`(2, 3)`, target shape :math:`(2, 3)` , the inferred outpyt shape is :math:`(2, 3)`.
|
||||
With an input shape :math:`(2, 3)`, target shape :math:`(2, 3)` , the inferred output shape is :math:`(2, 3)`.
|
||||
|
||||
If the value pairs are unequal, there are three cases:
|
||||
|
||||
Case 1: Value of target shape is -1, then the value of the output shape is that of the input shape's.
|
||||
With an input shape :math:`(3, 3)`, target shape :math:`(-1, 3)`, the output shape is :math:`(3, 3)`.
|
||||
Case 1: If the value of the target shape in the dimension is -1, the value of the
|
||||
output shape in the dimension is the value of the corresponding input shape in the dimension.
|
||||
|
||||
Case 2: Value of target shape is not -1 but the value ot the input shape is 1, then the value of the output shape
|
||||
is that of the target shape's. With an input shape :math:`(1, 3)`, target
|
||||
Case 2: If the value of target shape in the dimension is not -1, but the corresponding
|
||||
value in the input shape is 1, then the corresponding value of the output shape
|
||||
is that of the target shape. With an input shape :math:`(1, 3)`, target
|
||||
shape :math:`(8, 3)`, the output shape is :math:`(8, 3)`.
|
||||
|
||||
Case 3: All other cases mean that the two shapes are not broadcastable.
|
||||
Case 3: If the corresponding values of the two shapes do not satisfy the above cases,
|
||||
it means that broadcasting from the input shape to the target shape is not supported.
|
||||
|
||||
So far we got the last m dims of the outshape, now focus on the first :math:`*` dims, there are
|
||||
two cases:
|
||||
|
|
|
@ -2959,7 +2959,7 @@ class Div(_MathBinaryOp):
|
|||
|
||||
class DivNoNan(Primitive):
|
||||
r"""
|
||||
Computes a safe divide and returns 0 if the x2 is zero.
|
||||
Operates a safe division between `x1` and `x2` element-wise. Returns 0 if element of `x2` is zero.
|
||||
|
||||
Inputs of `x1` and `x2` comply with the implicit type conversion rules to make the data types consistent.
|
||||
The inputs must be two tensors or one tensor and one scalar.
|
||||
|
@ -2980,7 +2980,7 @@ class DivNoNan(Primitive):
|
|||
`number <https://www.mindspore.cn/docs/en/master/api_python/mindspore.html#mindspore.dtype>`_ or
|
||||
`bool_ <https://www.mindspore.cn/docs/en/master/api_python/mindspore.html#mindspore.dtype>`_.
|
||||
- **x2** (Union[Tensor, number.Number, bool]) - The second input is a number.Number or
|
||||
a bool when the first input is a tensor or a tensor whose data type is number or bool\_.
|
||||
a bool when the first input is a bool or a tensor whose data type is number or bool\_.
|
||||
When the first input is Scalar, the second input must be a Tensor whose data type is number or bool\_.
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue