oneflow.repeat_interleave¶
-
oneflow.
repeat_interleave
(input, repeats, dim=None, *, output_size=None) → Tensor¶ Repeat elements of a tensor.
Warning
This is different from
oneflow.Tensor.repeat()
but similar tonumpy.repeat
.The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.repeat_interleave.html
- Parameters
input (oneflow.Tensor) – the input Tensor.
repeats (Tensor or int) – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
dim (int, optional) – The dimension along which to repeat values. By default, use the flattened input array, and return a flat output array.
- Keyword Arguments
output_size (int, optional) – Total output size for the given axis ( e.g. sum of repeats). If given, it will avoid stream syncronization needed to calculate output shape of the tensor.
- Returns
Repeated tensor which has the same shape as input, except along the given axis.
- Return type
For example:
>>> import oneflow as flow >>> x = flow.tensor([1, 2, 3]) >>> y = flow.tensor([[1, 2], [3, 4]]) >>> flow.repeat_interleave(y, 2) tensor([1, 1, 2, 2, 3, 3, 4, 4], dtype=oneflow.int64) >>> flow.repeat_interleave(y, 3, dim=1) tensor([[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]], dtype=oneflow.int64) >>> flow.repeat_interleave(y, flow.tensor([1, 2]), dim=0) tensor([[1, 2], [3, 4], [3, 4]], dtype=oneflow.int64) >>> flow.repeat_interleave(y, flow.tensor([1, 2]), dim=0, output_size=3) tensor([[1, 2], [3, 4], [3, 4]], dtype=oneflow.int64)