clamp_

Documentation

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

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

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> t = ttorch.tensor([-1.7120,  0.1734, -0.0478, 2.0922])
>>> ttorch.clamp_(t, min=-0.5, max=0.5)
>>> t
tensor([-0.5000,  0.1734, -0.0478,  0.5000])

>>> t = ttorch.tensor({
...     'a': [-1.7120,  0.1734, -0.0478, 2.0922],
...     'b': {'x': [[-0.9049, 1.7029, -0.3697], [0.0489, -1.3127, -1.0221]]},
... })
>>> ttorch.clamp_(t, min=-0.5, max=0.5)
>>> t
<Tensor 0x7fbf53327730>
├── a --> tensor([-0.5000,  0.1734, -0.0478,  0.5000])
└── b --> <Tensor 0x7fbf533277f0>
    └── x --> tensor([[-0.5000,  0.5000, -0.3697],
                      [ 0.0489, -0.5000, -0.5000]])

Torch Version Related

This documentation is based on torch.clamp_ 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__)'