Rate this Page
★ ★ ★ ★ ★

is_tensorclass#

tensordict.is_tensorclass(obj: type | Any) → bool#

Returns True if obj is a tensorclass type or an instance of one.

Parameters:

obj (type or object) – the class or the object to check.

Examples

>>> import torch
>>> from tensordict import TensorDict, is_tensorclass, tensorclass
>>> @tensorclass
... class Data:
...     x: torch.Tensor
>>> is_tensorclass(Data), is_tensorclass(Data(x=torch.zeros(2)))
(True, True)
>>> is_tensorclass(TensorDict())
False