In place padding and reindexing

Hi.

I would like to know if there is a inplace version of the following series of operations on the tensor input: Basically, I have a tensor called input, and I would like to reshape and reindex along a specific dimension

The series of operations could be the following:

s=input.shape
s[1] = new_len
output = torch.zeros(s)
output[:,index_tensor,…]=input

but the last one takes lots of time, almost as much as a convolution. Any idea how to get something similar but way faster?

Thanks

How large are the tensors and how did you define index_tensor?

I’m not sure, if your inplace assignment would work as you wish, since you could reassign some values, which would be needed in other steps:

# unrolled
input[2] = input[1]
input[3] = input[2] # this values was reassigned in the previous step