neg

Documentation

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

Returns a new tensor with the negative of the elements of input.

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.neg(ttorch.tensor([4, 3, 2, 6, 2]))
tensor([-4, -3, -2, -6, -2])

>>> ttorch.neg(ttorch.tensor({
...     'a': [4, 3, 2, 6, 2],
...     'b': {
...         'x': [[3, 4, 6],
...               [6, 3, 5]],
...         'y': [[[3, 5, 5],
...                [5, 7, 6]],
...               [[4, 6, 5],
...                [7, 2, 7]]],
...     },
... }))
<Tensor 0x7f11b13b5860>
├── a --> tensor([-4, -3, -2, -6, -2])
└── b --> <Tensor 0x7f11b13b5828>
    ├── x --> tensor([[-3, -4, -6],
    │                 [-6, -3, -5]])
    └── y --> tensor([[[-3, -5, -5],
                       [-5, -7, -6]],

                      [[-4, -6, -5],
                       [-7, -2, -7]]])

Torch Version Related

This documentation is based on torch.neg in torch v1.9.0+cu102. 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 v1.9.0+cu102 is listed below.

Description From Torch v1.9.0+cu102

torch.neg(input, *, out=None)Tensor

Returns a new tensor with the negative of the elements of input.

\[\text{out} = -1 \times \text{input}\]
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(5)
>>> a
tensor([ 0.0090, -0.2262, -0.0682, -0.2866,  0.3940])
>>> torch.neg(a)
tensor([-0.0090,  0.2262,  0.0682,  0.2866, -0.3940])