cat#
- tensordict.cat(input: Sequence['T'], dim: int = 0, *, out=None) T#
Concatenates tensordicts along an existing batch dimension
dim.Same as
torch.cat(input, dim). Every input must have the same keys, and the same batch size and entry shapes except alongdim. If the keys differ, this function raises aKeyError. If the shapes do not match, it raises aRuntimeError. To join tensordicts along a new dimension, usestack()orlazy_stack()(see Stacking and variable-size data).- Parameters:
input (sequence of TensorDictBase or tensorclass instances) – the tensordicts to concatenate.
dim (int, optional) – the batch dimension to concatenate along. Defaults to
0. Adimbelow-batch_dimswarns, and is used on the dims of the leaves. Starting with TensorDict 0.17, the default will change to raising anIndexError, as for a tensor.
- Keyword Arguments:
out (TensorDictBase, optional) – a tensordict to write the result into. Defaults to
None.- Returns:
A
TensorDict. Tensorclass inputs give an instance of their class. If every input is aLazyStackedTensorDict, the result is aLazyStackedTensorDict.
Examples
>>> import torch >>> import tensordict >>> from tensordict import TensorDict >>> td = tensordict.cat( ... [TensorDict(a=torch.zeros(3), batch_size=[3]), ... TensorDict(a=torch.ones(4), batch_size=[4])] ... ) >>> td.batch_size torch.Size([7])