albanD:

lin_idx = idx.select(1, -1)*inp.stride(-1) + 
idx.select(1, -2)*inp.stride(-2) + 
idx.select(1, -3)*inp.stride(-3)


lin_idx = idx.select(1, 2)*inp.stride(-1) + idx.select(1, 1)*inp.stride(-2) + idx.select(1, 0)*inp.stride(-3)
I replaced your lines with this one, I think it is working properly now, thanks a lot!