Pytorch parameter matrix from loss function of transformation
I have a pytorch tensor k x (n+k-1) tensor w with requires_grad=True. I want to transform it into a kxn tensor p also with as such: p[i] = w[i][i:i+n]. How do I do this, such that by calling backward() on a loss function of p in the end, I will learn w?

Any sort of indexing operation would do, with the backward function being &lt;CopySlices&gt;
A naive way of doing this would be using simple python indexing:

w_unrolled = torch.zeros(p.size())
for i in range(w.shape[0]):
    w_unrolled[i] = w[i][i:i+n]
loss = criterion(w_unrolled, p)


You can then reduce your loss via mean/sum on whichever axis. Note that while this will work, it is inefficient; the optimal way would be to use a native indexing function to speed things up.
