mindspore.ops.isclose

View Source On Gitee
mindspore.ops.isclose(input, other, rtol=1e-05, atol=1e-08, equal_nan=False)[source]

Return a boolean tensor where two tensors are element-wise equal within a tolerance. Math function is defined as:

|inputother|atol+rtol×|other|

Two Infinite values are considered equal if they have the same sign, Two NaN values are considered equal if equal_nan is True .

Parameters
  • input (Tensor) – The first input tensor.

  • other (Tensor) – The second input tensor.

  • rtol (Union[float, int, bool], optional) – Relative tolerance. Default 1e-05 .

  • atol (Union[float, int, bool], optional) – Absolute tolerance. Default 1e-08 .

  • equal_nan (bool, optional) – Whether two NaNs are considered equal. Default False .

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> mindspore.ops.isclose(mindspore.tensor([2e6, float("inf"), float("-inf"), float("inf"), float("nan")]),
...                       mindspore.tensor([2e7, float("inf"), float("-inf"), float("-inf"), float("nan")]))
Tensor(shape=[6], dtype=Bool, value= [ True, False,  True,  True, False, False])
>>>
>>> mindspore.ops.isclose(mindspore.tensor([1e6, 2e6, 3e6]),
...                       mindspore.tensor([1.00008e6, 2.00008e7, 3.00008e8]), rtol=1e3)
Tensor(shape=[3], dtype=Bool, value= [ True,  True,  True])
>>>
>>> mindspore.ops.isclose(mindspore.tensor([1e6, 2e6, 3e6]),
...                       mindspore.tensor([1.00001e6, 2.00002e6, 3.00009e6]), atol=1e3)
Tensor(shape=[3], dtype=Bool, value= [ True,  True,  True])
>>> mindspore.ops.isclose(mindspore.tensor([float("nan"), 1, 2]),
...                       mindspore.tensor([float("nan"), 1, 2]), equal_nan=True)
Tensor(shape=[3], dtype=Bool, value= [ True,  True,  True])