TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-15

tensorplay.functional.allclose

tensorplay.functional.allclose(input: Tensor, other: Tensor, rtol: float = 1e-05, atol: float = 1e-08, equal_nan: bool = False) → bool[source]

This function checks if input and other satisfy the condition:

∣inputi−otheri∣≤atol+rtol×∣otheri∣\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{atol} + \texttt{rtol} \times \lvert \text{other}_i \rvert

elementwise, for all elements of input and other. The behaviour of this function is analogous to numpy.allclose

Parameters:
  • input (Tensor) – first tensor to compare

  • other (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

Example:

>>> tensorplay.allclose(tensorplay.tensor([10000., 1e-07]), tensorplay.tensor([10000.1, 1e-08]))
False
>>> tensorplay.allclose(tensorplay.tensor([10000., 1e-08]), tensorplay.tensor([10000.1, 1e-09]))
True
>>> tensorplay.allclose(tensorplay.tensor([1.0, float('nan')]), tensorplay.tensor([1.0, float('nan')]))
False
>>> tensorplay.allclose(tensorplay.tensor([1.0, float('nan')]), tensorplay.tensor([1.0, float('nan')]), equal_nan=True)
True

On this page

Ask DeepWiki