Skip to content

gather / scatter dont respect non-contigous out Tensor #1193

Closed
@soumith

Description

@soumith

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions