TensorDictBase.all#
- TensorDictBase.all(dim: int | None = None) bool | TensorCollection#
Returns whether every element of every leaf is
True(nonzero).- Parameters:
dim (int, optional) – a batch dimension to reduce. If given, returns a new tensordict of boolean leaves without that dimension. A negative
dimcounts from the end of the batch dimensions. Defaults toNone, which checks every element and returns abool.- Returns:
A
bool, or a new tensordict ifdimis given.- Raises:
RuntimeError – if
dimis not a batch dimension.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.tensor([[True, False], [True, True]]), batch_size=[2, 2]) >>> td.all() False >>> td.all(dim=1)["a"] tensor([False, True])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.