TensorDictBase.entry_class#
- abstract TensorDictBase.entry_class(key: NestedKey) type#
Returns the class of an entry, possibly without reading the entry.
It returns
type(tensordict.get(key)). Prefer it to that expression whenget()is expensive, for example on a lazy stack or a tensordict stored on disk.Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.zeros(3), b=TensorDict(c=torch.zeros(3))) >>> td.entry_class("a") <class 'torch.Tensor'> >>> td.entry_class("b") <class 'tensordict._td.TensorDict'>
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.