Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing with an empty vector of indices throws a RuntimeError #3416

Closed
bermanmaxim opened this issue Nov 1, 2017 · 1 comment · Fixed by #3429
Closed

Indexing with an empty vector of indices throws a RuntimeError #3416

bermanmaxim opened this issue Nov 1, 2017 · 1 comment · Fixed by #3429

Comments

@bermanmaxim
Copy link
Contributor

Arguably, indexing a Tensor by a LongTensor with no dimension should return a LongTensor with no dimension. Consider the following case:

>>> a = torch.ones(5)
>>> a[a<0]
[torch.FloatTensor with no dimension]
>>> a[(a<0).nonzero().squeeze()]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: invalid argument 3: Index is supposed to be a vector at /opt/conda/conda-bld/pytorch_1503966894950/work/torch/lib/TH/generic/THTensorMath.c:248

This breaks indexing by indices when the list of indices is empty, which can be hard to detect. In my use-case, I use such a masking to select rows of a tensor corresponding to "valid" entries in a vector; I had not considered that it would not work when there are no valid entries.

@soumith soumith added this to Crashes / Segfaults / Errors in Issue Categories Nov 1, 2017
@ssnl
Copy link
Collaborator

ssnl commented Nov 1, 2017

Thanks! I'll take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants