Sorry, I was just trying to do that as an example of indexing outside the allowable array size. Here’s a better example:
X = torch.randn(5,5,5)
y = torch.LongTensor([5])
X.index_select(2,y)
returns RuntimeError: out of range at /data/users/soumith/miniconda2/conda-bld/pytorch-0.1.7_1485444530918/work/torch/lib/TH/generic/THTensor.c:379
but if I run
X = torch.randn(5,5,5).cuda()
y = torch.LongTensor([5]).cuda()
X.index_select(2,y) # Works, but should not
X.index_select(2,y+5) # Also works, but really should not
On the version I installed off conda this allows me to grab random junk (presumably it’s grabbing things from nearby memory locations) but it doesn’t throw any errors. On the version I compiled yesterday this may or may not throw a device-side assert error (the GPUs are all tied up on that machine so I can’t properly test it atm) but in the case I was previously encountering it was not throwing that assert error until after I had done the bad indexing.
Is it not possible to insert a value check in the index_select function to ensure that the elements of the second argument are all less than the size of the indexed tensor along that axis?