(x, batch)
| 44 | # 如何进行全局池化对每个图中节点的特征进行求和 |
| 45 | # -------------------------------------------------------------------------------------------------------- |
| 46 | def batch_sum_pooling(x, batch): |
| 47 | batch_size = int(torch.max(batch.cpu())) + 1 |
| 48 | res = torch.zeros(batch_size, x.size(1)).to(x.device) |
| 49 | out = res.scatter_add_( |
| 50 | dim=0, |
| 51 | index=batch.unsqueeze(-1).expand_as(x), |
| 52 | src=x |
| 53 | ) |
| 54 | return out |
| 55 | |
| 56 | return out |
| 57 | |
| 58 | # %% |
| 59 | # 如何编辑一个graph? |