最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Can PyTorch `scatter` or `gather` be used to reproduce `torch_geometric` aggregation functions? - Stack Overflow

programmeradmin1浏览0评论

I can't understand if torch.scatter or torch.gather could be used to reduce values of a tensor according to a reduction function over specified indices.

I've frequently used the torch_geometric.nn.aggr` module's functions in order to perform aggregations over indices, and I want to reproduce these very useful functions using pure PyTorch operations.

I can't understand if torch.scatter or torch.gather could be used to reduce values of a tensor according to a reduction function over specified indices.

I've frequently used the torch_geometric.nn.aggr` module's functions in order to perform aggregations over indices, and I want to reproduce these very useful functions using pure PyTorch operations.

Share Improve this question asked Mar 19 at 10:33 daqhdaqh 1461 silver badge12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

you could use the function scatter_reduce_ (is in beta): https://pytorch./docs/stable/generated/torch.Tensor.scatter_reduce_.html

however you have to specify an out tensor (which should have desired shape and initial values):

e.g. for sum aggregation:

out = torch.zeros((index.max() + 1.), dtype=torch.float)
out.scatter_reduce_(dim=0, index=index, src=x, reduce="sum")

or min aggregation:

out = torch.full((index.max() + 1,), torch.inf)
out.scatter_reduce_(dim=0, index=index, src=x, reduce="amin")

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论