Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add group_batch functionality #9798

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

tzuhanchang
Copy link
Contributor

Tensor src is batched into groups according to index tensor in the given dimension dim.
Padding is applied to enforce consistent size of batched groups.

Examples:

>>> src = tensor([[0.1349, 0.8266],
...               [0.3651, 0.1737],
...               [0.0211, 0.7000],
...               [0.1971, 0.2903],
...               [0.4086, 0.7221]])
>>> index = torch.LongTensor([0,0,1,2,2])
>>> group_batch(src, index, dim=0, pad_size=3, return_mask=True)
(tensor([[[0.1349, 0.8266],
          [0.3651, 0.1737],
          [  -inf,   -inf]],
         [[0.0211, 0.7000],
          [  -inf,   -inf],
          [  -inf,   -inf]],
         [[0.1971, 0.2903],
          [0.4086, 0.7221],
          [  -inf,   -inf]]])
tensor([[[ True,  True],
         [ True,  True],
         [False, False]],
        [[ True,  True],
         [False, False],
         [False, False]],
        [[ True,  True],
         [ True,  True],
         [False, False]]]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant