@ptrblck Sorry I have a follow up question: the solution seems to assume that the start and end ranges won’t overlap with each other. Is there a way to modify it to work for overlapping cases? For example, when indices = torch.tensor([[1,3], [2,3]]) or indices = torch.tensor([[1,3], [1,2]]).