Hi,
I’m trying to use properties of one tensor to select out values from another tensor and I think I want to use index_select. I’m getting an error, however, that I don’t know how to get around.
Here’s a minimal working example:
import torch
from torch.autograd import Variable

blah = Variable( torch.Tensor( [[ 1.1,2.2,3.3],[4.4,5.5,6.6]] ), requires_grad=True )
all_above10 = Variable( torch.Tensor( [ 11, 12, 13, 14, 15, 16]), requires_grad=False)
inds_above10 = torch.nonzero( all_above10 > 10 )
print( "inds_above10", inds_above10 )
#foo = Variable( torch.LongTensor([0,0,0,1,1,1]), requires_grad=False)
foo = inds_above10 / 3
print( "foo", foo )
bar = torch.index_select( blah, 0, foo ) 
print(bar)

And I get this error:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-fa2b5f6dcfe9> in <module>()
      9 foo = inds_above10 / 3
     10 print( "foo", foo )
---> 11 bar = torch.index_select( blah, 0, foo )
     12 print(bar)

RuntimeError: invalid argument 3: Index is supposed to be an empty tensor or a vector at /Users/andrew/rosetta/GIT/tmol/src/pytorch/aten/src/TH/generic/THTensorMath.c:261

If I just create my LongTensor foo manually (by uncommenting the other definition of foo and commenting out the current one), then there’s no problem.
How can I use logic (e.g. “all_above10 > 10” ) to get exactly the entries from one tensor into another tensor?
Edit: Im using version 0ef10385b2 of pytorch from 2018/2/13