fn

isclose

Tensor
isclose(input: Tensor, other: Tensor, rtol: float = ..., atol: float = ..., equal_nan: bool = ...)
source

Element-wise approximate equality with absolute and relative tolerance.

Returns a boolean tensor that is True where the two operands are equal up to a combined absolute / relative tolerance. Useful for comparing floating-point results where bit-exact equality is too strict.

Parameters

inputTensor
Left operand.
otherTensor
Right operand. Broadcasts against input.
rtolfloat= ...
Relative tolerance.
atolfloat= ...
Absolute tolerance.
equal_nanbool= ...
If True, two NaN entries compare equal.

Returns

Tensor

Boolean tensor (dtype bool) with shape broadcast(input.shape, other.shape).

Notes

Mathematical definition:

outi=(xiyiatol+rtolyi)\text{out}_i = \bigl( |x_i - y_i| \le \text{atol} + \text{rtol} \cdot |y_i| \bigr)

When equal_nan is True positions where both operands are NaN are additionally marked True. Not differentiable.

Examples

>>> import lucid
>>> a = lucid.tensor([1.0, 2.0])
>>> b = lucid.tensor([1.0 + 1e-9, 2.5])
>>> lucid.isclose(a, b, rtol=1e-5, atol=1e-8)
Tensor([True, False])