log2

Documentation

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

Returns a new tensor with the logarithm to the base 2 of the elements of input.

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.log2(ttorch.tensor([-4.0, -1.0, 0, 2.0, 4.8, 8.0]))
tensor([   nan,    nan,   -inf, 1.0000, 2.2630, 3.0000])

>>> ttorch.log2(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 0x7ff90a4cff70>
├── a --> tensor([   nan,    nan,   -inf, 1.0000, 2.2630, 3.0000])
└── b --> <Tensor 0x7ff90a4bc070>
    └── x --> tensor([[    nan,  0.2630, -2.0000],
                      [ 4.0000,  1.9069,     nan]])

Torch Version Related

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

Returns a new tensor with the logarithm to the base 2 of the elements of input.

\[y_{i} = \log_{2} (x_{i})\]
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.rand(5)
>>> a
tensor([ 0.8419,  0.8003,  0.9971,  0.5287,  0.0490])


>>> torch.log2(a)
tensor([-0.2483, -0.3213, -0.0042, -0.9196, -4.3504])