Skip to content

Commit 2dc563f

Browse files
fmassaapaszke
authored andcommitted
Fix indexing when passing only an Ellipsis
1 parent 15ba71a commit 2dc563f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

test/test_torch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,11 +1880,13 @@ def test_index(self):
18801880
self.assertEqual(reference[2, ..., 2, 2], 27, 0)
18811881
self.assertEqual(reference[2, 2, ..., 2], 27, 0)
18821882
self.assertEqual(reference[2, 2, 2, ...], 27, 0)
1883+
self.assertEqual(reference[...], reference, 0)
18831884

18841885
reference_5d = self._consecutive((3, 3, 3, 3, 3))
18851886
self.assertEqual(reference_5d[..., 1, 0], reference_5d[:, :, :, 1, 0], 0)
18861887
self.assertEqual(reference_5d[2, ..., 1, 0], reference_5d[2, :, :, 1, 0], 0)
18871888
self.assertEqual(reference_5d[2, 1, 0, ..., 1], reference_5d[2, 1, 0, :, 1], 0)
1889+
self.assertEqual(reference_5d[...], reference_5d, 0)
18881890

18891891
# LongTensor indexing
18901892
reference = self._consecutive((5, 5, 5))

torch/csrc/generic/Tensor.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ static bool THPTensor_(_index)(THPTensor *self, PyObject *index,
540540
}
541541
}
542542
if (valid) return true;
543-
} else {
543+
} else if (index == Py_Ellipsis) return true;
544+
else {
544545
if (THPTensor_(_indexOnce)<allow_index>(index, indexed_dim, tresult, sresult, storage_offset))
545546
return true;
546547
}
@@ -551,9 +552,9 @@ static bool THPTensor_(_index)(THPTensor *self, PyObject *index,
551552
", numpy scalars"
552553
#endif
553554
#ifndef THC_GENERIC_FILE
554-
"torch.LongTensor and torch.ByteTensor.",
555+
", torch.LongTensor and torch.ByteTensor.",
555556
#else
556-
"torch.cuda.LongTensor and torch.cuda.ByteTensor.",
557+
", torch.cuda.LongTensor and torch.cuda.ByteTensor.",
557558
#endif
558559
THPUtils_typename(index));
559560
return false;

0 commit comments

Comments
 (0)