Skip to content

allclose

allclose

allclose(A: Tensor, B: Tensor, rtol: float = 1e-05, atol: float = 1e-08) -> bool

Return True if two tensors are numerically equal within the given tolerances.

For Abelian tensors, compares each dense block with torch.allclose. For generic tensors, compares the physical tensors R @ W block-by-block, which is gauge-invariant with respect to the reduced representation.

Parameters:

Name Type Description Default
A Tensor

First tensor.

required
B Tensor

Second tensor.

required
rtol float

Relative tolerance passed to torch.allclose. Default: 1e-5.

1e-05
atol float

Absolute tolerance passed to torch.allclose. Default: 1e-8.

1e-08

Returns:

Type Description
bool

True if all blocks are numerically equal within the given tolerances and the two tensors share the same index structure and block keys. False otherwise.

Raises:

Type Description
TypeError

If either argument is not a Tensor.

ValueError

If the tensors have incompatible index structures.

Notes

  • For Abelian tensors, each dense block is compared directly with torch.allclose.
  • For non-Abelian (SU(2)) tensors, the physical tensor R @ W is compared block-by-block, making the check invariant to the gauge freedom in the reduced representation. Two tensors that represent the same physical content but differ in their internal (R, W) factorization will still compare as equal.
  • Structural mismatches (different tensor order, incompatible groups or directions) raise ValueError. Differing block keys return False without raising.

See Also