Semantics of None in aten.index

What is the meaning of None indices as arguments to core ATen’s aten.index, which has type signature:

index.Tensor(Tensor self, Tensor?[] indices) -> Tensor

One guess is that a None index stands for the entire corresponding dimension: e.g. if v is a tensor with shape [2, 3], then index(v, [None, tensor([0, 1])]) is equivalent to index(v, [tensor([0, 1]), tensor([0, 1])]). However, this is not the case as shown by the example below:

>>> v
tensor([[0.1824, 0.1772, 0.6883],
        [0.5761, 0.7300, 0.0843]])
>>> torch.ops.aten.index(v, [torch.tensor([0, 1]), torch.tensor([0, 1])])
tensor([0.1824, 0.7300])
>>> torch.ops.aten.index(v, [None, torch.tensor([0, 1])])
tensor([[0.1824, 0.1772],
        [0.5761, 0.7300]])

I think None stands for the ellipsis sign in the Python equivalent,
so its equivalent to x[ : , [0, 1]]

1 Like