Closed abcnet closed 8 years ago
y:add(a)
syntax is for in-place add of a
to y
. if you want to add a
to b
, and put the result into y
, you can do either of:
y = a + b
or:
y = torch.add(a, b)
I know y:add(a) is a completely different statement than y:add(a,b). I am saying the documentation is wrong in describing y:add(a,b). It is not y=a+b as described in the doc. Instead, it is accumulatively adding the product of a times b into y, like y=y+a*b in matlab.
Hmmm... right :-)
@abcnet can't reproduce.
y = torch.ones(3)
a = torch.ones(3)*5
b = torch.ones(3)*2
y:add(a,b)
print(y)
this gives as output
7
7
7
[torch.DoubleTensor of size 3]
as expected.
I think the problem you are mentioning is because your a
is a number, and not a tensor. and thus you are using the following overloaded version of add
https://github.com/torch/torch7/blob/master/doc/maths.md#res-torchaddres-tensor1-value-tensor2
@abcnet any news on that ? Can this issue be closed ?
Correct, that is the overloaded version of add. y=torch.ones(3) y:add(10,torch.ones(3)) 11 11 11 Thanks
y:add(a,b) is not putting a+b into y. Instead, it is y+=a*b.