TensorDictBase.repeat#
- TensorDictBase.repeat(*repeats: int, inplace: bool = False) Self#
Repeats the batch along each batch dimension, as
torch.Tensor.repeat()does.The whole batch is repeated, as with
numpy.tile(). To repeat each element next to itself instead, as withnumpy.repeat(), userepeat_interleave(). Unlikeexpand(), it copies the data. The feature dimensions are not repeated, and the names are kept.- Parameters:
*repeats (int) – the number of repetitions along each batch dimension, one per batch dimension, as integers or as one
torch.Size, list, tuple or tensor.- Keyword Arguments:
inplace (bool, optional) – if
True, the tensordict keeps its identity and keys, its leaves are replaced one by one, and the call returnsself. A lazy stack, or a tensordict that holds one, raises aNotImplementedError: callto_tensordict()first. See In-place operations. Defaults toFalse.- Raises:
ValueError – if the number of repeats differs from the number of batch dimensions.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.tensor([[0, 1]]), b=torch.zeros(1, 2, 3), batch_size=[1, 2]) >>> out = td.repeat(2, 2) >>> out["a"] tensor([[0, 1, 0, 1], [0, 1, 0, 1]]) >>> out["b"].shape torch.Size([2, 4, 3])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.