oneflow.isclose(input, other, atol=1e-08, rtol=1e-05, equal_nan=False)Tensor

The documentation is referenced from:

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:

\[\lvert \text{input} - \text{other} \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other} \rvert\]
  • input (oneflow.Tensor) – first tensor to compare

  • other (oneflow.Tensor) – second tensor to compare

  • atol (float, optional) – absolute tolerance. Default: 1e-08

  • rtol (float, optional) – relative tolerance. Default: 1e-05

  • equal_nan (bool, optional) – if True, then two NaN s will be considered equal. Default: False


A Tensor with bool type.

Return type


For example:

>>> import oneflow as flow

>>> flow.isclose(flow.tensor((1., 2, 3)), flow.tensor((1 + 1e-10, 3, 4)))
tensor([ True, False, False], dtype=oneflow.bool)

>>> flow.isclose(flow.tensor((float('inf'), 4)), flow.tensor((float('inf'), 6)), rtol=.5)
tensor([True, True], dtype=oneflow.bool)