eq

Documentation

treetensor.torch.eq(input, other, *args, **kwargs)[source]

In treetensor, you can get the equality of the two tree tensors with eq().

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.eq(
...     torch.tensor([[1, 2], [3, 4]]),
...     torch.tensor([[1, 1], [4, 4]]),
... )
tensor([[ True, False],
        [False,  True]])

>>> ttorch.eq(
...     ttorch.tensor({
...         'a': [[1, 2], [3, 4]],
...         'b': [1.0, 1.5, 2.0],
...     }),
...     ttorch.tensor({
...         'a': [[1, 1], [4, 4]],
...         'b': [1.3, 1.2, 2.0],
...     }),
... )
<Tensor 0x7ff363bbce10>
├── a --> tensor([[ True, False],
│                 [False,  True]])
└── b --> tensor([False, False,  True])

Torch Version Related

This documentation is based on torch.eq 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.eq(input, other, *, out=None)Tensor

Computes element-wise equality

The second argument can be a number or a tensor whose shape is broadcastable with the first argument.

Args:

input (Tensor): the tensor to compare other (Tensor or float): the tensor or value to compare

Keyword args:

out (Tensor, optional): the output tensor.

Returns:

A boolean tensor that is True where input is equal to other and False elsewhere

Example:

>>> torch.eq(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[1, 1], [4, 4]]))
tensor([[ True, False],
        [False, True]])