mindspore.ops.approximate_equal
- mindspore.ops.approximate_equal(x, y, tolerance=1e-5)[source]
Return a boolean tensor where two tensors are element-wise equal within a tolerance.
Support implicit type conversion and type promotion.
Math function is defined as:
Two infinite values and two NaN values are not considered equal.
- Parameters
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> mindspore.ops.approximate_equal(mindspore.tensor([1e6, 2e6, float("inf"), float("-inf"), float("nan")]), ... mindspore.tensor([1e6, 2e7, float("inf"), float("-inf"), float("nan")])) Tensor(shape=[6], dtype=Bool, value= [ True, False, False, False, False]) >>> >>> mindspore.ops.approximate_equal(mindspore.tensor([1e6, 2e6, 3e6]), ... mindspore.tensor([1.00001e6, 2.00002e6, 3.00009e6]), tolerance=1e3) Tensor(shape=[3], dtype=Bool, value= [ True, True, True]) >>> >>> # If `x` and `y` have different datatypes, the lower precision data type will be converted to the relatively highest precision data type. >>> mindspore.ops.approximate_equal(mindspore.tensor([1, 2], mindspore.int32), ... mindspore.tensor([1., 2], mindspore.float32)) Tensor(shape=[2], dtype=Bool, value= [ True, True])