equal

Documentation

treetensor.torch.equal(input, other)[source]

In treetensor, you can get the equality of the two tree tensors.

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.equal(
...     torch.tensor([1, 2, 3]),
...     torch.tensor([1, 2, 3]),
... )  # the same as torch.equal
True

>>> ttorch.equal(
...     ttorch.tensor({
...         'a': torch.tensor([1, 2, 3]),
...         'b': torch.tensor([[4, 5], [6, 7]]),
...     }),
...     ttorch.tensor({
...         'a': torch.tensor([1, 2, 3]),
...         'b': torch.tensor([[4, 5], [6, 7]]),
...     }),
... )
True

Torch Version Related

This documentation is based on torch.equal in torch v2.0.1+cu117. Its arguments’ arrangements depend on the version of pytorch you installed.

If some arguments listed here are not working properly, please check your pytorch’s version with the following command and find its documentation.

1
python -c 'import torch;print(torch.__version__)'

The arguments and keyword arguments supported in torch v2.0.1+cu117 is listed below.

Description From Torch v2.0.1+cu117

torch.equal(input, other) → bool

True if two tensors have the same size and elements, False otherwise.

Example:

>>> torch.equal(torch.tensor([1, 2]), torch.tensor([1, 2]))
True