Skip to content
Discussion options

You must be logged in to vote

Hi @rajajisai! I recently tried the same thing in my PR #7459. I hope this helps :)

import torch
from torch_geometric.utils import index_sort, to_dense_batch
src_feat = torch.tensor(
    [
        [1, 1, 1],
        [2, 2, 2],
        [3, 3, 3],
        [4, 4, 4],
        [5, 5, 5],
        [6, 6, 6],
    ]
)
dst_indices = torch.tensor([1, 2, 5, 5, 5, 1], dtype=torch.long)

# to_dense_batch assumes that the indices are sorted
_, indices = index_sort(dst_indices)
result, _ = to_dense_batch(src_feat[indices], dst_indices[indices])
print(result)
tensor([[[0, 0, 0],
         [0, 0, 0],
         [0, 0, 0]],

        [[1, 1, 1],
         [6, 6, 6],
         [0, 0, 0]],

        [[2, 2, 2],
    …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rajajisai
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants