AttributeError: 'torch.cuda.LongTensor' object has no attribute 'dot'

For tensor types of Long, Byte, and Integer, torch.dot function does not work when they are in GPU.
On CPU, there is no problem at all.
As I couldn’t find any written restriction of running torch.dot function in GPU, I am asking here.

  • I found that for Float tensors, torch.dot works in GPU.
>>> a = b =torch.LongTensor([1,2,3])
>>> a.dot(b)
14
>>> a=a.cuda();b=b.cuda()
>>> a.dot(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'torch.cuda.LongTensor' object has no attribute 'dot'

torch.dot hasn’t been implemented for CUDA Integer tensor types. this and kthvalue are the only missing functions on the GPU at the moment.

1 Like

I am getting a similar missing feature as well, seems that pow is also not in torch.LongTensor yet:

*** AttributeError: 'torch.cuda.LongTensor' object has no attribute 'pow'

Which version are you using? This works for me:

>>> torch.cuda.FloatTensor(3).pow(2)

1.00000e-02 *
  0.0003
  0.1568
  1.0655
[torch.cuda.FloatTensor of size 3 (GPU 0)]

>>> torch.FloatTensor(3).pow(2)

 8.7180
 0.0000
 8.7180
[torch.FloatTensor of size 3]

I am using the 0.2.0_1 version:

$ python -c "import torch; print torch.__version__"
0.2.0_1

torch.cuda.FloatTensor works for me as well; but torch.cuda.LongTensor doesn’t.

$ python -c "import torch; torch.cuda.LongTensor(3).pow(2)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'torch.cuda.LongTensor' object has no attribute 'pow'

Sorry I missed the type :). This is because pow() might give results not representable as long. You can do t * t manually.

Thanks for the reply!

Yah that was what I did instead. By the way, reciprocal seems not working for Long as well…

This is expected, for same reason. You can cast to Double/Float.