isinf

Documentation

treetensor.torch.isinf(input)[source]

In treetensor, you can test if each element of input is infinite (positive or negative infinity) or not.

Examples:

>>> import torch
>>> import treetensor.torch as ttorch
>>> ttorch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([False,  True, False,  True, False])

>>> ttorch.isinf(ttorch.tensor({
...     'a': [1, float('inf'), 2, float('-inf'), float('nan')],
...     'b': {'x': [[1, float('inf'), -2], [float('-inf'), 3, float('nan')]]}
... }))
<Tensor 0x7fb782a29b80>
├── a --> tensor([False,  True, False,  True, False])
└── b --> <Tensor 0x7fb782a2d1f0>
    └── x --> tensor([[False,  True, False],
                      [ True, False, False]])

Torch Version Related

This documentation is based on torch.isinf in torch v2.0.1+cu117. 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.0.1+cu117 is listed below.

Description From Torch v2.0.1+cu117

torch.isinf(input)Tensor

Tests if each element of input is infinite (positive or negative infinity) or not.

Note

Complex values are infinite when their real or imaginary part is infinite.

Args:

{input}

Returns:

A boolean tensor that is True where input is infinite and False elsewhere

Example:

>>> torch.isinf(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([False,  True,  False,  True,  False])