xnn.common.models.ops.scatter_sum#
- xnn.common.models.ops.scatter_sum(src, index, dim_size)[source]#
Sum rows of
srcintodim_sizebuckets given byindex(dim 0).This is the canonical edge -> node aggregation for message passing. For each row
eit accumulatesout[index[e]] += src[e], withtorch.Tensor.scatter_add()on CUDA (the faster kernel there) andtorch.Tensor.index_add()elsewhere. The values are the same.- Parameters:
src (torch.Tensor) – Source tensor whose leading dimension is scattered. Shape
(E, *feature_dims)(e.g. per-edge messages).index (torch.Tensor) – 1-D integer tensor of length
Egiving, for each row ofsrc, the bucket (destination node) it is added into along dimension 0.dim_size (int) – Number of output buckets, i.e. the size of the leading dimension of the result (e.g. the number of nodes).
- Returns:
Tensor of shape
(dim_size, *feature_dims)with the same dtype and device assrc, holding the per-bucket sums.- Return type:
Notes
Written to stay compatible with
torch.jit.script()so scriptable model cores (e.g. SchNet’snode_energy) can call it.