Modified the docs to add example for torch.is_floating_point and torc… (#161951)

…h.is_complex.

The PR proposes adding a simple, self-explanatory example to the documentation page. The example demonstrates the function's output for tensors with various data types, showing both True and False return values.

Fixes #161859

Pull Request resolved: https://github.com/pytorch/pytorch/pull/161951
Approved by: https://github.com/zou3519
This commit is contained in:
mansiag05 2025-09-04 18:50:16 +00:00 committed by PyTorch MergeBot
parent 6f7608d603
commit 9480cdc0b6

View File

@ -5555,26 +5555,48 @@ Example::
add_docstr(
torch.is_floating_point,
r"""
is_floating_point(input) -> (bool)
is_floating_point(input: Tensor) -> bool
Returns True if the data type of :attr:`input` is a floating point data type i.e.,
one of ``torch.float64``, ``torch.float32``, ``torch.float16``, and ``torch.bfloat16``.
Args:
{input}
Example::
>>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0]))
True
>>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.int32))
False
>>> torch.is_floating_point(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
True
>>> torch.is_floating_point(torch.tensor([1, 2, 3], dtype=torch.complex64))
False
""".format(**common_args),
)
add_docstr(
torch.is_complex,
r"""
is_complex(input) -> (bool)
is_complex(input: Tensor) -> bool
Returns True if the data type of :attr:`input` is a complex data type i.e.,
one of ``torch.complex64``, and ``torch.complex128``.
Args:
{input}
Example::
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex64))
True
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.complex128))
True
>>> torch.is_complex(torch.tensor([1, 2, 3], dtype=torch.int32))
False
>>> torch.is_complex(torch.tensor([1.0, 2.0, 3.0], dtype=torch.float16))
False
""".format(**common_args),
)