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

Fix segment_reduce() ignoring tailing 0 segments #2228

Merged
merged 2 commits into from
Sep 24, 2020
Merged

Fix segment_reduce() ignoring tailing 0 segments #2228

merged 2 commits into from
Sep 24, 2020

Conversation

mjwen
Copy link
Contributor

@mjwen mjwen commented Sep 23, 2020

Description

segment_reduce() supports zeor-length segments. But it fails if the zero-length segments is at the end of seglen.

For example,

import dgl
import torch

val = torch.ones(10, 3)
seg = torch.tensor([1, 0, 5, 4, 0])
x = dgl.ops.segment.segment_reduce(seg, val, "sum")

yields a value for x as

tensor([[1., 1., 1.],
        [0., 0., 0.],
        [5., 5., 5.],
        [4., 4., 4.]])

but it should be

tensor([[1., 1., 1.],
        [0., 0., 0.],
        [5., 5., 5.],
        [4., 4., 4.],
        [0., 0., 0.]])

This PR fixes this.

@mjwen mjwen changed the title Bugfix segment_reduce() ignoring tailing 0 segments Fix segment_reduce() ignoring tailing 0 segments Sep 23, 2020
@BarclayII BarclayII merged commit 25a8e3f into dmlc:master Sep 24, 2020
@BarclayII
Copy link
Collaborator

Thanks for your fix!

BarclayII added a commit to BarclayII/dgl that referenced this pull request Nov 27, 2020
Co-authored-by: Quan (Andy) Gan <coin2028@hotmail.com>
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.

2 participants