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.

Warning

This API is deprecated since version 2.8.0 and will be removed after version 2.9.0. Please use mindspore.Tensor.isclose() instead.

Support implicit type conversion and type promotion.

Math function is defined as:

\[\begin{split}out_i = \begin{cases} & \text{ if } \left | x_{i} - y_{i} \right | < \text{tolerance},\ \ True \\ & \text{ if } \left | x_{i} - y_{i} \right | \ge \text{tolerance},\ \ False \end{cases}\end{split}\]

Two infinite values and two NaN values are not considered equal.

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

  • y (Tensor) – The second input tensor.

  • tolerance (float) – The maximum deviation within which two elements can be considered equal. Default 1e-5 .

Returns

Tensor

Supported Platforms:

Deprecated

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=[5], 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])