sqrt

Documentation

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

Returns a new tensor with the square-root of the elements of input.

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.sqrt(ttorch.tensor([-4.0, -1.0, 0, 2.0, 4.8, 8.0]))
tensor([   nan,    nan, 0.0000, 1.4142, 2.1909, 2.8284])

>>> ttorch.sqrt(ttorch.tensor({
...     'a': [-4.0, -1.0, 0, 2.0, 4.8, 8.0],
...     'b': {'x': [[-2.0, 1.2, 0.25],
...                 [16.0, 3.75, -2.34]]},
... }))
<Tensor 0x7ff90a4cb760>
├── a --> tensor([   nan,    nan, 0.0000, 1.4142, 2.1909, 2.8284])
└── b --> <Tensor 0x7ff90a4cb5b0>
    └── x --> tensor([[   nan, 1.0954, 0.5000],
                      [4.0000, 1.9365,    nan]])

Torch Version Related

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

Returns a new tensor with the square-root of the elements of input.

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

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([-2.0755,  1.0226,  0.0831,  0.4806])
>>> torch.sqrt(a)
tensor([    nan,  1.0112,  0.2883,  0.6933])