Invalid index in gather

see the picture blow:

where x, inds are re created by x=torch.rand(4, 2, 3), inds=torch.arange(4).view(4, 1, 1).expand(4, 2, 1) respectively.
however when I use x.gather(2, inds), error occurred:
RuntimeError: Invalid index in gather at /Users/soumith/b101_2/2019_02_08/wheel_build_dirs/wheel_3.7/pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:454

my environment is on macOS high sierra 10.13.6, with python3.7, torch 1.0.1.post2.

Besides, I have tried the 2 order tensor:

Is the tensor gathered must be a square?

And last, why the randint_like’s return still is torch.float type?


I have known the errors:
x_shape = (x1, x2, x3, …)
index_shape = (i1, i2, i3, …)
index[:,:,:,…] should < x_shape[dim]

here in my code max(index) = 3 = x_shape[dim=2], which is not satisfying the above rule.
so Invalid index happened.