abs

Documentation

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

Computes the absolute value of each element in input.

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.abs(ttorch.tensor([12, 0, -3]))
tensor([12,  0,  3])

>>> ttorch.abs(ttorch.tensor({
...     'a': [12, 0, -3],
...     'b': {'x': [[-3, 1], [0, -2]]},
... }))
<Tensor 0x7f1c81d78ee0>
├── a --> tensor([12,  0,  3])
└── b --> <Tensor 0x7f1c81d78d90>
    └── x --> tensor([[3, 1],
                      [0, 2]])

Torch Version Related

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

Computes the absolute value of each element in input.

\[\text{out}_{i} = |\text{input}_{i}|\]
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> torch.abs(torch.tensor([-1, -2, 3]))
tensor([ 1,  2,  3])