TensorDictBase.set_non_tensor#
- TensorDictBase.set_non_tensor(key: NestedKey, value: Any)#
Stores
valueas non-tensor data atkey, and returnsself.The value is wrapped in a
NonTensorDatawith the batch size, device and names of the tensordict that holds it. A tuple key creates the missing nested tensordicts. Unlikeset(), a number is stored as non-tensor data too.td[key]andget_non_tensor()returnvalue, andget()returns theNonTensorData. See Non-tensor data and unbatched entries.- Parameters:
key (NestedKey) – the key of the entry.
value (Any) – the value to store.
- Raises:
RuntimeError – if the tensordict is locked.
Examples
>>> from tensordict import TensorDict >>> data = TensorDict({}, batch_size=[]) >>> data = data.set_non_tensor(("nested", "the string"), "a string!") >>> data["nested", "the string"] 'a string!' >>> data.get(("nested", "the string")) NonTensorData(data=a string!, batch_size=torch.Size([]), device=None)
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.