neg_

Documentation

treetensor.torch.neg_(input)[source]

In-place version of treetensor.torch.neg().

Examples:

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

>>> t = 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]]],
...     },
... })
>>> ttorch.neg_(t)
>>> t
<Tensor 0x7f11b13b6fd0>
├── a --> tensor([-4, -3, -2, -6, -2])
└── b --> <Tensor 0x7f11b13b60f0>
    ├── 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 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__)'