TensorDictBase.is_non_tensor#
- TensorDictBase.is_non_tensor(key: NestedKey) bool#
Checks if the value associated with a key is a non-tensor (
NonTensorData).Unlike the standalone
is_non_tensor()function which checks a value directly, this method checks the internal representation of the stored value, making it reliable for bothTensorDictandTensorClassinstances.This is useful because
TensorClassget()unwrapsNonTensorDatato plain values, so callingis_non_tensor(tc.get(key))on the result would returnFalse. This method always checks the wrapped storage.- Parameters:
key (NestedKey) – the key to check.
- Returns:
Trueif the value stored atkeyis aNonTensorDataorNonTensorStack,Falseotherwise.
Examples
>>> from tensordict import TensorDict >>> import torch >>> td = TensorDict({"obs": torch.randn(4)}, []) >>> td = td.set_non_tensor("label", "cat") >>> td.is_non_tensor("label") True >>> td.is_non_tensor("obs") False
See also
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.