default_is_leaf#
- tensordict.default_is_leaf(cls: Type) bool#
Returns
Trueif a type is a leaf: anything but a tensordict or a tensorclass.This is the default
is_leafofkeys()and the methods that walk the nested entries. AUnbatchedTensoris a leaf too. ANonTensorDatais not, soleaves_only=Trueskips the non-tensor entries. See Keys, nested keys, and locking.- Parameters:
cls (type) – the type of an entry, as returned by
entry_class().
Examples
>>> import torch >>> from tensordict import TensorDict, NonTensorData, default_is_leaf >>> default_is_leaf(torch.Tensor), default_is_leaf(NonTensorData), default_is_leaf(TensorDict) (True, False, False) >>> td = TensorDict(a={}, b="a string!", c=torch.zeros(())) >>> list(td.keys(leaves_only=True, is_leaf=default_is_leaf)) ['c']
See also