Ok, thanks for the info.
I don’t know an elegant way to achieve your results.
If your results would look like this:
l = tensor([10, 3, 1, 0, 0, 0, 0, 0, 0, 0]),
m_l = tensor([0, 0, 0, 20, 4, 0, 0, 0, 0, 0,])
, i.e. there the zeros in front of the right part, you could use .scatter_()
.
In case this helps, here is the code to achieve this, but unfortunately this isn’t exactly, what you wanted:
# Init data tensor and splits
x = torch.randn(20, 10)
splits = torch.empty(20, dtype=torch.long).random_(1, 10)
# Calculate size for result tensor
new_rows = x.size(0) * 2
offset = x.size(0)
z = torch.zeros(new_rows, 10)
# Calculate scatter indices
# The "left" part goes into z[:offset], the "right" part goes into z[offset:]
split_scatter = [torch.cat((torch.ones(1, split, dtype=torch.long) * idx,
torch.ones(1, max_len-split, dtype=torch.long) * (idx + offset)),
dim=1) for idx, split in zip(range(0, new_rows), splits)]
split_scatter = torch.cat(split_scatter)
# Apply scatter
z.scatter_(0, split_scatter, x)
# Cut tensors
x1 = z[:offset]
x2 = z[offset:]