!35779 fix doc string
Merge pull request !35779 from hezhenhao1/code_docs
This commit is contained in:
commit
8c9b466693
|
@ -222,6 +222,7 @@ Reduction算子
|
|||
mindspore.ops.ge
|
||||
mindspore.ops.gt
|
||||
mindspore.ops.intopk
|
||||
mindspore.ops.isclose
|
||||
mindspore.ops.isfinite
|
||||
mindspore.ops.isnan
|
||||
mindspore.ops.le
|
||||
|
|
|
@ -703,6 +703,35 @@ mindspore.Tensor
|
|||
- **TypeError** - `x` 不是Tensor。
|
||||
- **TypeError** - 该Tensor的数据类型非float16或float32。
|
||||
|
||||
.. py:method:: isclose(x2, rtol=1e-05, atol=1e-08, equal_nan=False)
|
||||
|
||||
返回一个布尔型Tensor,表示当前Tensor与 `x2` 的对应元素是否在给定容忍度内相等。
|
||||
|
||||
.. note::
|
||||
目前,Ascend后端不支持包含 inf 或 NaN 的输入数组。因此,当输入包含NaN或inf时,结果是不确定的。在Ascend后端上, `equal_nan` 必须为真。
|
||||
|
||||
**参数:**
|
||||
|
||||
- **x2** (Tensor) - 对比的第二个输入,支持的类型有float32,float16,int32。
|
||||
- **rtol** (Tensor) - 相对容忍度。默认值:1e-05。
|
||||
- **atol** (Tensor) - 绝对容忍度。默认值:1e-08。
|
||||
- **equal_nan** (bool, optional) - IsNan的输入,任意维度的Tensor。
|
||||
|
||||
**返回:**
|
||||
|
||||
Tensor,shape与广播后的shape相同,数据类型是布尔型。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - 如果当前Tensor和 `x2` 中的任何一个不是Tensor。
|
||||
- **TypeError** - 如果当前Tensor和 `x2` 的数据类型不是float16、float32或int32之一。
|
||||
- **TypeError** - 如果 `atol` 和 `rtol` 中的任何一个不是float。
|
||||
- **TypeError** - 如果 `equal_nan` 不是bool。
|
||||
- **TypeError** - 如果当前Tensor和 `x2` 的数据类型不同。
|
||||
- **ValueError** - 如果当前Tensor和 `x2` 无法广播。
|
||||
- **ValueError** - 如果 `atol` 和 `rtol` 中的任何一个小于零。
|
||||
- **ValueError** - 如果Ascend平台上的 `equal_nan` 为False。
|
||||
|
||||
.. py:method:: item(index=None)
|
||||
|
||||
获取Tensor中指定索引的元素。
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
mindspore.ops.isclose
|
||||
=====================
|
||||
|
||||
.. py:function:: mindspore.ops.isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False)
|
||||
|
||||
返回一个布尔型Tensor,表示 `x1` 的每个元素与 `x2` 的对应元素在给定容忍度内是否“接近”,其中“接近”的数学公式为:
|
||||
|
||||
.. math::
|
||||
|
||||
∣x1−x2∣ ≤ atol + rtol × ∣x2∣
|
||||
|
||||
.. note::
|
||||
目前,Ascend后端不支持包含 inf 或 NaN 的输入数组。因此,当输入包含NaN或inf时,结果是不确定的。在Ascend后端上, `equal_nan` 必须为真。
|
||||
|
||||
**参数:**
|
||||
|
||||
- **x1** (Tensor) - 对比的第一个输入,支持的类型有float32,float16,int32。
|
||||
- **x2** (Tensor) - 对比的第二个输入,支持的类型有float32,float16,int32。
|
||||
- **rtol** (Tensor) - 相对容忍度。默认值:1e-05。
|
||||
- **atol** (Tensor) - 绝对容忍度。默认值:1e-08。
|
||||
- **equal_nan** (bool, optional) - IsNan的输入,任意维度的Tensor。
|
||||
|
||||
**返回:**
|
||||
|
||||
Tensor,shape与广播后的shape相同,数据类型是布尔型。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - 如果 `x1` 和 `x2` 中的任何一个不是Tensor。
|
||||
- **TypeError** - 如果 `x1` 和 `x2` 的数据类型不是float16、float32或int32之一。
|
||||
- **TypeError** - 如果 `atol` 和 `rtol` 中的任何一个不是float。
|
||||
- **TypeError** - 如果 `equal_nan` 不是bool。
|
||||
- **TypeError** - 如果 `x1` 和 `x2` 的数据类型不同。
|
||||
- **ValueError** - 如果 `x1` 和 `x2` 无法广播。
|
||||
- **ValueError** - 如果 `atol` 和 `rtol` 中的任何一个小于零。
|
||||
- **ValueError** - 如果Ascend平台上的 `equal_nan` 为False。
|
|
@ -220,6 +220,7 @@ Comparison operators
|
|||
mindspore.ops.ge
|
||||
mindspore.ops.gt
|
||||
mindspore.ops.intopk
|
||||
mindspore.ops.isclose
|
||||
mindspore.ops.isfinite
|
||||
mindspore.ops.isnan
|
||||
mindspore.ops.le
|
||||
|
|
|
@ -1253,7 +1253,40 @@ class Tensor(Tensor_):
|
|||
|
||||
def isclose(self, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
|
||||
"""
|
||||
Returns a boolean tensor where two tensors are element-wise equal within a tolerance.
|
||||
Returns a boolean Tensor where two Tensors are element-wise equal within a tolerance.
|
||||
|
||||
Note:
|
||||
On Ascend, input arrays containing inf or NaN are not supported. Therefore, when the input is NaN or inf,
|
||||
the result is uncertain. And `equal_nan` must be True on Ascend.
|
||||
|
||||
Args:
|
||||
x2 (Tensor): Second Tensor to compare, with data type belongs to float32, float16, int32.
|
||||
rtol (float, optional): Relative tolerance. Default: 1e-05.
|
||||
atol (float, optional): Absolute tolerance. Default: 1e-08.
|
||||
equal_nan (bool, optional): If True, then two NaNs will be considered equal. Default: False.
|
||||
|
||||
Returns:
|
||||
A bool Tensor, with the shape as broadcasted result of the input Tensor and `x2`.
|
||||
|
||||
Raises:
|
||||
TypeError: If either of self Tensor and `x2` is not Tensor.
|
||||
TypeError: If either of self Tensor and `x2` is not float16, float32 or int32.
|
||||
TypeError: If either of `atol` and `rtol` is not float.
|
||||
TypeError: If `equal_nan` is not bool.
|
||||
TypeError: If the dtype of self Tensor is not same as the `x2`.
|
||||
ValueError: If self Tensor and `x2` can not be broadcast.
|
||||
ValueError: If either of `atol` and `rtol` is less than zero.
|
||||
ValueError: If `equal_nan` is False on Ascend platform.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> input = Tensor(np.array([1.3, 2.1, 3.2, 4.1, 5.1]), mindspore.float16)
|
||||
>>> other = Tensor(np.array([1.3, 3.3, 2.3, 3.1, 5.1]), mindspore.float16)
|
||||
>>> output = ops.isclose(input, other)
|
||||
>>> print(output)
|
||||
[true false false false true]
|
||||
"""
|
||||
self._init_check()
|
||||
return tensor_operator_registry.get('isclose')(self, x2, rtol, atol, equal_nan)
|
||||
|
|
|
@ -2471,7 +2471,46 @@ def isnan(x):
|
|||
|
||||
def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
|
||||
"""
|
||||
Returns a boolean tensor where two tensors are element-wise equal within a tolerance.
|
||||
Returns a new Tensor with boolean elements representing if each element of `x1`
|
||||
is “close” to the corresponding element of `x2`. Closeness is defined as:
|
||||
|
||||
.. math::
|
||||
|
||||
∣x1−x2∣ ≤ atol + rtol × ∣x2∣
|
||||
|
||||
Note:
|
||||
On Ascend, input arrays containing inf or NaN are not supported. Therefore, when the input is NaN or inf,
|
||||
the result is uncertain. And `equal_nan` must be True on Ascend.
|
||||
|
||||
Args:
|
||||
x1 (Tensor): First Tensor to compare, with data type belongs to float32, float16, int32.
|
||||
x2 (Tensor): Second Tensor to compare, with data type belongs to float32, float16, int32.
|
||||
rtol (float, optional): Relative tolerance. Default: 1e-05.
|
||||
atol (float, optional): Absolute tolerance. Default: 1e-08.
|
||||
equal_nan (bool, optional): If True, then two NaNs will be considered equal. Default: False.
|
||||
|
||||
Returns:
|
||||
A bool Tensor, with the shape as broadcasted result of the input `x1` and `x2`.
|
||||
|
||||
Raises:
|
||||
TypeError: If either of `x1` and `x2` is not Tensor.
|
||||
TypeError: If either of `x1` and `x2` is not float16, float32 or int32.
|
||||
TypeError: If either of `atol` and `rtol` is not float.
|
||||
TypeError: If `equal_nan` is not bool.
|
||||
TypeError: If the dtype of `x1` is not same as the `x2`.
|
||||
ValueError: If `x1` and `x2` can not be broadcast.
|
||||
ValueError: If either of `atol` and `rtol` is less than zero.
|
||||
ValueError: If `equal_nan` is False on Ascend platform.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> input = Tensor(np.array([1.3, 2.1, 3.2, 4.1, 5.1]), mindspore.float16)
|
||||
>>> other = Tensor(np.array([1.3, 3.3, 2.3, 3.1, 5.1]), mindspore.float16)
|
||||
>>> output = ops.isclose(input, other)
|
||||
>>> print(output)
|
||||
[true false false false true]
|
||||
"""
|
||||
return P.IsClose(rtol=rtol, atol=atol, equal_nan=equal_nan)(x1, x2)
|
||||
|
||||
|
|
|
@ -5529,39 +5529,9 @@ class Igammac(Primitive):
|
|||
|
||||
class IsClose(Primitive):
|
||||
r"""
|
||||
Returns a boolean tensor where two tensors are element-wise equal within a tolerance.
|
||||
Returns a boolean Tensor where two tensors are element-wise equal within a tolerance.
|
||||
|
||||
Note:
|
||||
Returns a new tensor with boolean elements representing if each element of input
|
||||
is “close” to the corresponding element of other. Closeness is defined as:
|
||||
∣input−other∣ ≤ atol + rtol × ∣other∣
|
||||
|
||||
.. warning::
|
||||
When the input is nan or inf, the result is uncertain.
|
||||
|
||||
Args:
|
||||
rtol(float): Relative tolerance. Default: 1e-05.
|
||||
atol(float): Absolute tolerance. Default: 1e-08.
|
||||
equal_nan(bool): If True, then two NaNs will be considered equal. At present, `equal_nan` must be True in Ascend
|
||||
platform currently, we will support False in future version. Default: True.
|
||||
|
||||
Inputs:
|
||||
-**input**(Tensor) – First tensor to compare, with data type belongs to float32, float16, int32.
|
||||
-**other**(Tensor) – Second tensor to compare, with data type belongs to float32, float16, int32.
|
||||
|
||||
Outputs:
|
||||
Tensor, with same shape as input and other. When the input is close to the other, it is true,
|
||||
otherwise it is false.
|
||||
|
||||
Raises:
|
||||
TypeError: If either of `input` and `other` is not tensor.
|
||||
TypeError: If either of `input` and `other` is not float16, float32 or int32.
|
||||
TypeError: If either of `atol` and `rtol` is not float.
|
||||
TypeError: If `equal_nan` is not bool.
|
||||
TypeError: If the dtype of `input` is not same as the `other`.
|
||||
ValueError: If shape of `input` is not same as the `other`.
|
||||
ValueError: If either of `atol` and `rtol` is less than zero.
|
||||
ValueError: If `equal_nan` is False.
|
||||
Refer to :func:`mindspore.ops.isclose` for more detail.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
|
@ -5581,7 +5551,7 @@ class IsClose(Primitive):
|
|||
validator.check_value_type('atol', atol, [float], self.name)
|
||||
validator.check_value_type('equal_nan', equal_nan, [bool], self.name)
|
||||
if context.get_context("device_target") == "Ascend" and not equal_nan:
|
||||
raise ValueError("For IsClose, the `equal_nan` must be True, but got False.")
|
||||
raise ValueError("For IsClose, the `equal_nan` must be True on Ascend, but got False.")
|
||||
validator.check_non_negative_float(rtol, 'rtol', self.name)
|
||||
validator.check_non_negative_float(atol, 'atol', self.name)
|
||||
|
||||
|
|
Loading…
Reference in New Issue