I have a similar question. My data is a 3x3 matrix with values (src), and the index contains column ids (index), indicating to which column each element of src belongs.
import torch

src = torch.tensor([[1.0, 2.0, 3.0], [2.0, 0.0, 1.0], [1.0, 3.0, 4.0]], dtype=torch.int64)

index = torch.tensor([[0, 0, 1], [0, 0, 1], [0, 0, 1]])

The result of the unsorted segment sum should be [9, 8, 0] (since there are 3 columns or segments). The sum over the first column (with id 0) is 9, the sum over the second column (with id 1) is 8, and the sum over the third column is 0 (since index does not contain any id 2). How can I achieve this with scatter_add?