Hi,
I found the sum of the Variable not equals to its data, is this normal ?
Example Code:
import torch
t = torch.rand(10000).gt(0.05)
t.sum()
from torch.autograd import Variable
vt = Variable(t)
vt.sum()
vt.data.sum()
n = 0
for item in t:
if item > 0:
n = n + 1
n
python shell output:
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import torch
>>> t = torch.rand(10000).gt(0.05)
>>> t.sum()
9506
>>> from torch.autograd import Variable
>>> vt = Variable(t)
>>> vt.sum()
Variable containing:
34
[torch.ByteTensor of size 1]
>>> vt.data.sum()
9506
>>>
>>> n = 0
>>> for item in t:
... if item > 0:
... n = n + 1
...
>>> n
9506
We can see that, t.sum() = 9506
and vt.sum() = 34
Is this a bug or I missed something?
Thanks