Rate this Page
★ ★ ★ ★ ★

TensorDictBase.is_non_tensor#

TensorDictBase.is_non_tensor(key: NestedKey) → bool#

Returns True if the entry at key is non-tensor data.

Non-tensor data is a NonTensorData or a NonTensorStack. Unlike the function is_non_tensor(), which checks a value, this method checks the stored entry. This matters for a tensorclass, whose get returns the content of a non-tensor entry, not the NonTensorData.

Parameters:

key (NestedKey) – the key to check.

Raises:

KeyError – if the key is missing.

Examples

>>> import torch
>>> from tensordict import TensorDict
>>> td = TensorDict({"obs": torch.zeros(4)}, [])
>>> td = td.set_non_tensor("label", "cat")
>>> td.is_non_tensor("label")
True
>>> td.is_non_tensor("obs")
False

Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.