TensorDictBase.copy#
- TensorDictBase.copy_(tensordict: T, non_blocking: bool = False) Self#
Copies the entries of
tensordictinto the existing entries, and returnsself.The same as
update_(), under the name oftorch.Tensor.copy_(): the existing tensors keep their storage, and every key oftensordictmust exist in the tensordict.- Parameters:
tensordict (TensorDictBase or dict) – the entries to copy.
non_blocking (bool, optional) – if
True, copies between devices can run asynchronously with respect to the host. Defaults toFalse.
- Raises:
KeyError – if a key of
tensordictis missing from the tensordict.RuntimeError – if a value does not fit the shape of its entry.
Examples
>>> import torch >>> from tensordict import TensorDict >>> x = torch.zeros(3) >>> td = TensorDict(x=x, batch_size=[3]) >>> _ = td.copy_(TensorDict(x=torch.ones(3), batch_size=[3])) >>> x tensor([1., 1., 1.])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.