TensorDictBase.__eq__#
- TensorDictBase.__eq__(other: Any) Self | bool#
Compares the tensordict with
otherleaf by leaf with==.othercan be a tensordict or adictwith the same keys, paired with the tensordict key by key (aKeyErroris raised if the keys differ); a tensor, which is aligned with the batch dimensions of each leaf; or a number. A batch size that differs from the tensordict’s is broadcast with it. Anotherof another type, such asNone, givesFalse. The other comparisons (!=,<,<=,>,>=) work the same way, except for such another:!=givesTrue, and<,<=,>and>=giveFalseand aFutureWarning. Starting with TensorDict 0.17, the default will change to returningNotImplemented, so that Python raises aTypeError, as it does for tensors and for&.The result is a new tensordict that is not locked and, except with a tensor
otherof one or more dims, has no dim names.&,~and the arithmetic operators keep the dim names and the lock.- Parameters:
other (TensorDictBase, dict, Tensor or Number) – the value to compare with.
- Returns:
A new tensordict of boolean leaves, or
False.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.tensor([1.0, 2.0]), b=torch.zeros(2), batch_size=[2]) >>> (td == 1)["a"] tensor([ True, False]) >>> (td == td.clone()).all() True >>> (td >= torch.tensor([2.0, 0.0]))["b"] tensor([False, True]) >>> td == None False
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.