Index list of ranges

Suppose I have a T x W matrix.

Now also suppose I have two 1D int tensors, W1 and W2, representing the start and stop indices of the range along each row.

I want to index the T x [W1:W2] section out of the original matrix.

How do I do this efficiently?

This is very related: Range-based indexing based on another tensor - #3 by KFrank