I’m not sure if there’s a fast way to do this, but you could iterate through all of the rows. Here’s an example:
M = torch.Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
I = torch.LongTensor([0, 1, 0])
out = torch.cat([((x <= x[i]).type_as(x) * x).unsqueeze(0) for x, i in zip(M.t(), I)]).t()

gives: