all¶
Documentation¶
-
treetensor.torch.
all
(input, *args, reduce=None, **kwargs)[source]¶ In
treetensor
, you can get theall
result of a whole tree with this function.Example:
>>> import torch >>> import treetensor.torch as ttorch >>> ttorch.all(torch.tensor([True, True])) # the same as torch.all tensor(True) >>> ttorch.all(ttorch.tensor({'a': [True, True], 'b': {'x': [True, True]}})) tensor(True) >>> ttorch.all(ttorch.tensor({'a': [True, True], 'b': {'x': [True, False]}})) tensor(False) >>> ttorch.all(ttorch.tensor({'a': [True, True], 'b': {'x': [True, False]}}), reduce=False) <Tensor 0x7fcda55652b0> ├── a --> tensor(True) └── b --> <Tensor 0x7fcda5565208> └── x --> tensor(False) >>> ttorch.all(ttorch.tensor({'a': [True, True], 'b': {'x': [True, False]}}), dim=0) <Tensor 0x7fcda5565780> ├── a --> tensor(True) └── b --> <Tensor 0x7fcda55656d8> └── x --> tensor(False)
Torch Version Related
This documentation is based on torch.all in torch v2.4.1+cu121. 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.4.1+cu121 is listed below.
Description From Torch v2.4.1+cu121¶
-
torch.
all
(input) → Tensor¶ Tests if all elements in
input
evaluate to True.Note
This function matches the behaviour of NumPy in returning output of dtype bool for all supported dtypes except uint8. For uint8 the dtype of output is uint8 itself.
Example:
>>> a = torch.rand(1, 2).bool() >>> a tensor([[False, True]], dtype=torch.bool) >>> torch.all(a) tensor(False, dtype=torch.bool) >>> a = torch.arange(0, 3) >>> a tensor([0, 1, 2]) >>> torch.all(a) tensor(False)
-
torch.
all
(input, dim, keepdim=False, *, out=None) → Tensor
For each row of
input
in the given dimensiondim
, returns True if all elements in the row evaluate to True and False otherwise.If
keepdim
isTrue
, the output tensor is of the same size asinput
except in the dimensiondim
where it is of size 1. Otherwise,dim
is squeezed (seetorch.squeeze()
), resulting in the output tensor having 1 fewer dimension thaninput
.- Args:
input (Tensor): the input tensor. dim (int): the dimension to reduce. keepdim (bool): whether the output tensor has
dim
retained or not.- Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.rand(4, 2).bool() >>> a tensor([[True, True], [True, False], [True, True], [True, True]], dtype=torch.bool) >>> torch.all(a, dim=1) tensor([ True, False, True, True], dtype=torch.bool) >>> torch.all(a, dim=0) tensor([ True, False], dtype=torch.bool)
-