Closed
Description
As @tudor-berariu reports:
import torch
source = torch.rand(1, 3, 3)
# print(source)
idxs = torch.LongTensor(1, 3, 3).random_(0, 2)
# print(idxs)
a = torch.zeros(1, 4, 5)
a[0,:3,2:] = torch.gather(source, 2, idxs)
b = torch.zeros(1, 4, 5)
torch.gather(source, 2, idxs, out=b[0,:3,2:])
print(a)
print(b)
(0 ,.,.) =
0.0000 0.0000 0.3503 0.3527 0.3503
0.0000 0.0000 0.6724 0.6724 0.1911
0.0000 0.0000 0.2204 0.2204 0.2204
0.0000 0.0000 0.0000 0.0000 0.0000
[torch.FloatTensor of size 1x4x5]
(0 ,.,.) =
0.0000 0.0000 0.3503 0.3527 0.3503
0.6724 0.6724 0.1911 0.2204 0.2204
0.2204 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000
[torch.FloatTensor of size 1x4x5]
We need to add the freeCopyTo
pattern to the two functions in TH and THC